-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 날씨 정보 요약, 최단 경로 조회, 추천 이력 조회 API, Github Actions 배포 프로세스 추가
- [AJ-14] 설정파일 경로 classpath로 변경
- Loading branch information
Showing
33 changed files
with
472 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Deploy | ||
|
||
on: [] | ||
|
||
env: | ||
REPO: lyf-jarvis-back | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'corretto' | ||
|
||
|
||
- name: Set Yaml | ||
uses: microsoft/variable-substitution@v1 | ||
with: | ||
files: ./src/main/resources/application-prod.yml | ||
env: | ||
spring.datasource.url: ${{ secrets.DB_HOST }} | ||
spring.datasource.username: admin | ||
spring.datasource.password: ${{ secrets.DB_PASSWORD }} | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context : . | ||
file: Dockerfile | ||
push: true | ||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO }}:latest | ||
|
||
deploy-to-ec2: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Deploy to EC2 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_SSH_USER }} | ||
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | ||
script: | | ||
CONTAINER_ID=$(sudo docker ps -q --filter "publish=8080-8081") | ||
if [ ! -z "$CONTAINER_ID" ]; then | ||
sudo docker stop $CONTAINER_ID || true | ||
sudo docker rm $CONTAINER_ID || true | ||
fi | ||
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/lyf-jarvis-back:latest | ||
sudo docker run -d --name lyf-jarvis-back-${{ github.sha }} -p 8081:8080 ${{ secrets.DOCKERHUB_USERNAME }}/lyf-jarvis-back:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/moneygement/lyf/jarvis/history/controller/HistoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.moneygement.lyf.jarvis.history.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.moneygement.lyf.jarvis.history.domain.History; | ||
import com.moneygement.lyf.jarvis.history.domain.HistoryCreateRequest; | ||
import com.moneygement.lyf.jarvis.history.domain.HistoryResponse; | ||
import com.moneygement.lyf.jarvis.history.service.HistoryService; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/api/history") | ||
@RequiredArgsConstructor | ||
@Tag(name = "History", description = "추천 목록 정보 조회 AP") | ||
public class HistoryController { | ||
|
||
private final HistoryService historyService; | ||
|
||
@GetMapping("/{userId}") | ||
@Operation(summary = "History 조회", description = "UserId 기준의 History 정보를 제공 합니다.") | ||
public List<HistoryResponse> getHistoryByUserId(@PathVariable String userId) { | ||
return historyService.findByUserId(userId); | ||
} | ||
|
||
@PostMapping | ||
@Operation(summary = "History 등록", description = "History를 저장하는 기능을 제공합니다.") | ||
public ResponseEntity<History> createHistory(@RequestBody HistoryCreateRequest request) { | ||
History savedHistory = historyService.save(request); | ||
return new ResponseEntity<>(savedHistory, HttpStatus.CREATED); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/moneygement/lyf/jarvis/history/domain/History.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.moneygement.lyf.jarvis.history.domain; | ||
|
||
import com.moneygement.lyf.jarvis.common.audit.BaseEntity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "history") | ||
public class History extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@Column(name = "user_id", nullable = false) | ||
private String userId; | ||
|
||
@Column(name = "group_id") | ||
private Long groupId; | ||
|
||
@Column(name = "request", length = 2500, nullable = false) | ||
private String request; | ||
|
||
@Column(name = "response", length = 2500, nullable = false) | ||
private String response; | ||
|
||
public History(String userId, Long groupId, String request, String response) { | ||
this.userId = userId; | ||
this.groupId = groupId; | ||
this.request = request; | ||
this.response = response; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.moneygement.lyf.jarvis.history.domain; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record HistoryCreateRequest( | ||
@NotNull(message = "user id should be not null") String userId, | ||
Long groupId, | ||
@NotNull(message = "request should be not null") String request, | ||
@NotNull(message = "response should be not null") String response | ||
) { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.moneygement.lyf.jarvis.history.domain; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record HistoryResponse(String userId, | ||
Long groupId, | ||
String jarvisMessage, | ||
String userMessage, | ||
LocalDateTime createdDate) { | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/moneygement/lyf/jarvis/history/persistence/HistoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.moneygement.lyf.jarvis.history.persistence; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import java.util.List; | ||
|
||
import com.moneygement.lyf.jarvis.history.domain.History; | ||
|
||
@Repository | ||
public interface HistoryRepository extends JpaRepository<History, Long> { | ||
|
||
// userId로 History 목록 조회 | ||
List<History> findByUserId(String userId); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.moneygement.lyf.jarvis.history.service; | ||
|
||
import java.util.List; | ||
|
||
import com.moneygement.lyf.jarvis.history.domain.History; | ||
import com.moneygement.lyf.jarvis.history.domain.HistoryCreateRequest; | ||
import com.moneygement.lyf.jarvis.history.domain.HistoryResponse; | ||
|
||
public interface HistoryService { | ||
|
||
History save(HistoryCreateRequest historyCreateRequest); | ||
|
||
List<HistoryResponse> findByUserId(String userId); | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.moneygement.lyf.jarvis.history.service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.moneygement.lyf.jarvis.history.domain.History; | ||
import com.moneygement.lyf.jarvis.history.domain.HistoryCreateRequest; | ||
import com.moneygement.lyf.jarvis.history.domain.HistoryResponse; | ||
import com.moneygement.lyf.jarvis.history.persistence.HistoryRepository; | ||
import com.moneygement.lyf.jarvis.user.domain.User; | ||
import com.moneygement.lyf.jarvis.user.service.UserService; | ||
|
||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class HistoryServiceImpl implements HistoryService { | ||
|
||
private final HistoryRepository historyRepository; | ||
private final UserService userService; | ||
|
||
@Override | ||
public History save(HistoryCreateRequest request) { | ||
validateUserId(request.userId()); | ||
|
||
return historyRepository.save( | ||
new History(request.userId(), | ||
request.groupId(), | ||
request.request(), | ||
request.response())); | ||
} | ||
|
||
@Override | ||
public List<HistoryResponse> findByUserId(String userId) { | ||
validateUserId(userId); | ||
return historyRepository.findByUserId(userId).stream().map( | ||
history -> new HistoryResponse(history.getUserId(), | ||
history.getGroupId(), | ||
history.getResponse(), | ||
history.getRequest(), | ||
history.getCreatedDate() | ||
) | ||
).toList(); | ||
} | ||
|
||
/** | ||
* UserId가 실제 존재하는지 확인 | ||
* @param userId | ||
*/ | ||
private void validateUserId(String userId) { | ||
Optional<User> user = userService.findById(userId); | ||
|
||
if(user.isEmpty()) { | ||
throw new EntityNotFoundException("user not found!"); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/GroupRecommendation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.moneygement.lyf.jarvis.recommendation.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "group_recommendation") | ||
public class GroupRecommendation { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "group_id") | ||
private Long groupId; | ||
|
||
@Column(name = "session_name", length = 100) | ||
private String sessionName; | ||
|
||
@Column(name = "introduction", length = 500) | ||
private String introduction; | ||
|
||
@Column(name = "owner_user_id", nullable = false, length = 40) | ||
private String ownerUserId; | ||
|
||
public GroupRecommendation(String sessionName, String introduction, String ownerUserId) { | ||
this.sessionName = sessionName; | ||
this.introduction = introduction; | ||
this.ownerUserId = ownerUserId; | ||
} | ||
} | ||
|
Oops, something went wrong.