From 77664e132f845e69e2f01012201380072756d178 Mon Sep 17 00:00:00 2001 From: Tina Date: Mon, 28 Oct 2024 12:48:07 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=EB=82=A0=EC=94=A8=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=9A=94=EC=95=BD,=20=EC=B5=9C=EB=8B=A8=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=A1=B0=ED=9A=8C,=20=EC=B6=94=EC=B2=9C?= =?UTF-8?q?=20=EC=9D=B4=EB=A0=A5=20=EC=A1=B0=ED=9A=8C=20=20API,=20Github?= =?UTF-8?q?=20Actions=20=EB=B0=B0=ED=8F=AC=20=ED=94=84=EB=A1=9C=EC=84=B8?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80=20-=20[AJ-14]=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=ED=8C=8C=EC=9D=BC=20=EA=B2=BD=EB=A1=9C=20classpath?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 71 +++++++++++++++++++ .../lyf/jarvis/common/audit/BaseEntity.java | 7 +- .../history/controller/HistoryController.java | 43 +++++++++++ .../lyf/jarvis/history/domain/History.java | 47 ++++++++++++ .../history/domain/HistoryCreateRequest.java | 11 +++ .../history/domain/HistoryResponse.java | 10 +++ .../persistence/HistoryRepository.java | 14 ++++ .../history/service/HistoryService.java | 14 ++++ .../history/service/HistoryServiceImpl.java | 60 ++++++++++++++++ .../domain/GroupRecommendation.java | 41 +++++++++++ .../recommendation/domain/Recommendation.java | 52 ++++++++++++++ .../route/controller/RouteController.java | 37 ++++++++++ .../jarvis/route/service/RouteService.java | 2 +- .../route/service/RouteServiceImpl.java | 2 +- .../travel/service/TravelServiceImpl.java | 2 +- .../lyf/jarvis/user/service/UserService.java | 6 ++ .../jarvis/user/service/UserServiceImpl.java | 10 ++- .../weather/controller/WeatherController.java | 12 +++- .../weather/service/WeatherReportService.java | 25 +++++++ .../weather/service/WeatherService.java | 2 +- .../weather/service/WeatherServiceImpl.java | 2 +- .../main/resources}/application-dev.yml | 0 .../main/resources}/application-local.yml | 0 .../main/resources/application-prod.yml | 8 +-- .../main/resources}/application.yml | 16 ++--- .../main/resources}/business-config.yml | 0 {data => src/main/resources/data}/data.sql | 0 {data => src/main/resources/data}/schema.sql | 0 {config => src/main/resources}/encryption.yml | 0 .../main/resources}/external-url.yml | 0 {config => src/main/resources}/log4j2.xml | 0 .../main/resources}/logback-spring.xml | 0 {config => src/main/resources}/queries.yml | 0 33 files changed, 472 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 src/main/java/com/moneygement/lyf/jarvis/history/controller/HistoryController.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/history/domain/History.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryCreateRequest.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryResponse.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/history/persistence/HistoryRepository.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryService.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryServiceImpl.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/GroupRecommendation.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/Recommendation.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/route/controller/RouteController.java create mode 100644 src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherReportService.java rename {config => src/main/resources}/application-dev.yml (100%) rename {config => src/main/resources}/application-local.yml (100%) rename config/application-prd.yml => src/main/resources/application-prod.yml (62%) rename {config => src/main/resources}/application.yml (83%) rename {config => src/main/resources}/business-config.yml (100%) rename {data => src/main/resources/data}/data.sql (100%) rename {data => src/main/resources/data}/schema.sql (100%) rename {config => src/main/resources}/encryption.yml (100%) rename {config => src/main/resources}/external-url.yml (100%) rename {config => src/main/resources}/log4j2.xml (100%) rename {config => src/main/resources}/logback-spring.xml (100%) rename {config => src/main/resources}/queries.yml (100%) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..00079e5 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 \ No newline at end of file diff --git a/src/main/java/com/moneygement/lyf/jarvis/common/audit/BaseEntity.java b/src/main/java/com/moneygement/lyf/jarvis/common/audit/BaseEntity.java index 107148e..4fd17ec 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/common/audit/BaseEntity.java +++ b/src/main/java/com/moneygement/lyf/jarvis/common/audit/BaseEntity.java @@ -3,21 +3,24 @@ import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; +import lombok.Getter; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; +@Getter @MappedSuperclass @EntityListeners(AuditingEntityListener.class) public abstract class BaseEntity { @CreatedDate @Column(name = "CREATED_DATE", updatable = false, nullable = false) - private LocalDateTime createdDate; + protected LocalDateTime createdDate; @LastModifiedDate @Column(name = "UPDATED_DATE") - private LocalDateTime updatedDate; + protected LocalDateTime updatedDate; } diff --git a/src/main/java/com/moneygement/lyf/jarvis/history/controller/HistoryController.java b/src/main/java/com/moneygement/lyf/jarvis/history/controller/HistoryController.java new file mode 100644 index 0000000..9bef297 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/history/controller/HistoryController.java @@ -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 getHistoryByUserId(@PathVariable String userId) { + return historyService.findByUserId(userId); + } + + @PostMapping + @Operation(summary = "History 등록", description = "History를 저장하는 기능을 제공합니다.") + public ResponseEntity createHistory(@RequestBody HistoryCreateRequest request) { + History savedHistory = historyService.save(request); + return new ResponseEntity<>(savedHistory, HttpStatus.CREATED); + } +} diff --git a/src/main/java/com/moneygement/lyf/jarvis/history/domain/History.java b/src/main/java/com/moneygement/lyf/jarvis/history/domain/History.java new file mode 100644 index 0000000..e09cdf0 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/history/domain/History.java @@ -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; + } + +} diff --git a/src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryCreateRequest.java b/src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryCreateRequest.java new file mode 100644 index 0000000..b0e7e5f --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryCreateRequest.java @@ -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 +) { +} diff --git a/src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryResponse.java b/src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryResponse.java new file mode 100644 index 0000000..f49f023 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/history/domain/HistoryResponse.java @@ -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) { +} diff --git a/src/main/java/com/moneygement/lyf/jarvis/history/persistence/HistoryRepository.java b/src/main/java/com/moneygement/lyf/jarvis/history/persistence/HistoryRepository.java new file mode 100644 index 0000000..dade526 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/history/persistence/HistoryRepository.java @@ -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 { + + // userId로 History 목록 조회 + List findByUserId(String userId); +} \ No newline at end of file diff --git a/src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryService.java b/src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryService.java new file mode 100644 index 0000000..56fa719 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryService.java @@ -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 findByUserId(String userId); +} diff --git a/src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryServiceImpl.java b/src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryServiceImpl.java new file mode 100644 index 0000000..e466454 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/history/service/HistoryServiceImpl.java @@ -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 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 = userService.findById(userId); + + if(user.isEmpty()) { + throw new EntityNotFoundException("user not found!"); + } + } +} diff --git a/src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/GroupRecommendation.java b/src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/GroupRecommendation.java new file mode 100644 index 0000000..eca5952 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/GroupRecommendation.java @@ -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; + } +} + diff --git a/src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/Recommendation.java b/src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/Recommendation.java new file mode 100644 index 0000000..e76d47a --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/recommendation/domain/Recommendation.java @@ -0,0 +1,52 @@ +package com.moneygement.lyf.jarvis.recommendation.domain; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Setter +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "recommendation") +public class Recommendation { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @Column(name = "group_id", nullable = false) + private Long groupId; + + @Column(name = "name", nullable = false, length = 255) + private String name; + + @Column(name = "description") + private String description; + + @Column(name = "category", length = 50) + private String category; + + @Column(name = "latitude", nullable = false) + private Double latitude; + + @Column(name = "longitude", nullable = false) + private Double longitude; + + @Column(name = "rating") + private Double rating = 0.0; + + public Recommendation(Long groupId, String name, + String category, + Double latitude, Double longitude, Double rating) { + this.groupId = groupId; + this.name = name; + this.category = category; + this.latitude = latitude; + this.longitude = longitude; + this.rating = rating; + } + +} diff --git a/src/main/java/com/moneygement/lyf/jarvis/route/controller/RouteController.java b/src/main/java/com/moneygement/lyf/jarvis/route/controller/RouteController.java new file mode 100644 index 0000000..44294f3 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/route/controller/RouteController.java @@ -0,0 +1,37 @@ +package com.moneygement.lyf.jarvis.route.controller; + +import java.io.IOException; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +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.route.domain.OptimalRouteRequest; +import com.moneygement.lyf.jarvis.route.domain.OptimalRouteResponse; +import com.moneygement.lyf.jarvis.route.service.RouteService; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/api/route") +@RequiredArgsConstructor +@Tag(name = "Route", description = "최단 경로 정보 제공 API") +public class RouteController { + + private final RouteService routeService; + + @PostMapping("") + @Operation(summary = "최단 경로 정보 제공", description = "좌표와 교통수단 기준의 최단 경로 정보를 제공합니다.") + public ResponseEntity getOptimalRouteRequest(@RequestBody OptimalRouteRequest optimalRouteRequest) + throws IOException { + OptimalRouteResponse optimalRoute = routeService.getOptimalRoute(optimalRouteRequest); + return ResponseEntity.ok(optimalRoute); + } +} diff --git a/src/main/java/com/moneygement/lyf/jarvis/route/service/RouteService.java b/src/main/java/com/moneygement/lyf/jarvis/route/service/RouteService.java index 7fa7583..bc86fa1 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/route/service/RouteService.java +++ b/src/main/java/com/moneygement/lyf/jarvis/route/service/RouteService.java @@ -5,5 +5,5 @@ import java.io.IOException; public interface RouteService { - OptimalRouteResponse callGraphHopperForOptimalRoute(OptimalRouteRequest request) throws IOException; + OptimalRouteResponse getOptimalRoute(OptimalRouteRequest request) throws IOException; } diff --git a/src/main/java/com/moneygement/lyf/jarvis/route/service/RouteServiceImpl.java b/src/main/java/com/moneygement/lyf/jarvis/route/service/RouteServiceImpl.java index b324633..237c2be 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/route/service/RouteServiceImpl.java +++ b/src/main/java/com/moneygement/lyf/jarvis/route/service/RouteServiceImpl.java @@ -20,7 +20,7 @@ public class RouteServiceImpl implements RouteService { private final GraphHopperConfig graphHopperConfig; private final ObjectMapper objectMapper = new ObjectMapper(); - public OptimalRouteResponse callGraphHopperForOptimalRoute(OptimalRouteRequest request) throws IOException { + public OptimalRouteResponse getOptimalRoute(OptimalRouteRequest request) throws IOException { ResponseEntity response = HttpClientUtil.post(null, graphHopperConfig.getGraphHopperUrl() + "?key=" + graphHopperConfig.getGraphHopperApiKey(), request); if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) { diff --git a/src/main/java/com/moneygement/lyf/jarvis/travel/service/TravelServiceImpl.java b/src/main/java/com/moneygement/lyf/jarvis/travel/service/TravelServiceImpl.java index bdf8b66..b4eb682 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/travel/service/TravelServiceImpl.java +++ b/src/main/java/com/moneygement/lyf/jarvis/travel/service/TravelServiceImpl.java @@ -37,7 +37,7 @@ public TravelPlanResponse createTravelPlan(TravelPlanRequest request) throws IOE .map(location -> List.of(location.getLongitude(), location.getLatitude())) .toList(); OptimalRouteRequest optimalRouteRequest = new OptimalRouteRequest(points); - OptimalRouteResponse optimalRouteResponse = routeService.callGraphHopperForOptimalRoute(optimalRouteRequest); + OptimalRouteResponse optimalRouteResponse = routeService.getOptimalRoute(optimalRouteRequest); // 4. 여행 계획 DTO 생성 return createTravelPlanResponse(request.getStartPoint(), diff --git a/src/main/java/com/moneygement/lyf/jarvis/user/service/UserService.java b/src/main/java/com/moneygement/lyf/jarvis/user/service/UserService.java index 116b14a..19a776f 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/user/service/UserService.java +++ b/src/main/java/com/moneygement/lyf/jarvis/user/service/UserService.java @@ -1,4 +1,10 @@ package com.moneygement.lyf.jarvis.user.service; +import java.util.Optional; + +import com.moneygement.lyf.jarvis.user.domain.User; + public interface UserService { + + Optional findById(String userId); } diff --git a/src/main/java/com/moneygement/lyf/jarvis/user/service/UserServiceImpl.java b/src/main/java/com/moneygement/lyf/jarvis/user/service/UserServiceImpl.java index 1c6d915..aae6d3f 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/user/service/UserServiceImpl.java +++ b/src/main/java/com/moneygement/lyf/jarvis/user/service/UserServiceImpl.java @@ -1,15 +1,23 @@ package com.moneygement.lyf.jarvis.user.service; +import java.util.Optional; + import org.springframework.stereotype.Service; +import com.moneygement.lyf.jarvis.user.domain.User; import com.moneygement.lyf.jarvis.user.persistence.UserRepository; import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor -public class UserServiceImpl { +public class UserServiceImpl implements UserService { private final UserRepository userRepository; + + @Override + public Optional findById(String userId) { + return userRepository.findUserByUserId(userId); + } } diff --git a/src/main/java/com/moneygement/lyf/jarvis/weather/controller/WeatherController.java b/src/main/java/com/moneygement/lyf/jarvis/weather/controller/WeatherController.java index 1c175cd..42e8183 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/weather/controller/WeatherController.java +++ b/src/main/java/com/moneygement/lyf/jarvis/weather/controller/WeatherController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RestController; import com.moneygement.lyf.jarvis.weather.domain.WeatherInformationResponse; +import com.moneygement.lyf.jarvis.weather.service.WeatherReportService; import com.moneygement.lyf.jarvis.weather.service.WeatherService; import io.swagger.v3.oas.annotations.Operation; @@ -19,13 +20,20 @@ @Tag(name = "Weather", description = "날씨 정보 조회 AP") public class WeatherController { private final WeatherService weatherService; + private final WeatherReportService weatherReportService; @GetMapping("") - @Operation(summary = "날씨 정보 조회", description = "좌표 기준(위,경도)의 날씨 정보를 제공합니다.") + @Operation(summary = "날씨 정보 조회", description = "좌표 기준(위,경도)의 날씨 정보를 제공 합니다.") public ResponseEntity recommendTravelPlan(@RequestParam double latitude, @RequestParam double longitude) { - WeatherInformationResponse weatherInformationResponse = weatherService.callWeatherApi(latitude, + WeatherInformationResponse weatherInformationResponse = weatherService.getWeather(latitude, longitude); return ResponseEntity.ok(weatherInformationResponse); } + + @GetMapping("/summary") + @Operation(summary = "날씨 정보 요약 조회", description = "좌표 기준(위,경도)의 날씨 요약을 제공 합니다.") + public String getWeatherSummary(@RequestParam double latitude, @RequestParam double longitude) { + return weatherReportService.getWeatherSummary(latitude, longitude);} + } diff --git a/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherReportService.java b/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherReportService.java new file mode 100644 index 0000000..a5dfc40 --- /dev/null +++ b/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherReportService.java @@ -0,0 +1,25 @@ +package com.moneygement.lyf.jarvis.weather.service; + +import org.springframework.stereotype.Service; + +import com.moneygement.lyf.jarvis.weather.domain.WeatherInformationResponse; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class WeatherReportService { + private final WeatherService weatherService; + + public String getWeatherSummary(double latitude, double longitude) { + WeatherInformationResponse response = weatherService.getWeather(latitude, longitude); + + return String.format( + "In %s: %s, %.1f°C (feels like %.1f°C)", + response.getName(), + response.getWeather().getFirst().getMain(), + response.getMain().getTemp(), + response.getMain().getFeelsLike() + ); + } +} \ No newline at end of file diff --git a/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherService.java b/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherService.java index ff00be6..ec1388d 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherService.java +++ b/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherService.java @@ -3,5 +3,5 @@ import com.moneygement.lyf.jarvis.weather.domain.WeatherInformationResponse; public interface WeatherService { - WeatherInformationResponse callWeatherApi(double latitude, double longitude); + WeatherInformationResponse getWeather(double latitude, double longitude); } diff --git a/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherServiceImpl.java b/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherServiceImpl.java index 0a19064..40e87e9 100644 --- a/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherServiceImpl.java +++ b/src/main/java/com/moneygement/lyf/jarvis/weather/service/WeatherServiceImpl.java @@ -19,7 +19,7 @@ public class WeatherServiceImpl implements WeatherService { private final OpenWeatherConfig openWeatherConfig; - public WeatherInformationResponse callWeatherApi(double latitude, double longitude) { + public WeatherInformationResponse getWeather(double latitude, double longitude) { ResponseEntity response = HttpClientUtil.get(null, openWeatherConfig.getOpenWeatherUrl() + "?lat=" + latitude + "&lon=" + longitude diff --git a/config/application-dev.yml b/src/main/resources/application-dev.yml similarity index 100% rename from config/application-dev.yml rename to src/main/resources/application-dev.yml diff --git a/config/application-local.yml b/src/main/resources/application-local.yml similarity index 100% rename from config/application-local.yml rename to src/main/resources/application-local.yml diff --git a/config/application-prd.yml b/src/main/resources/application-prod.yml similarity index 62% rename from config/application-prd.yml rename to src/main/resources/application-prod.yml index c0d0e89..419afc9 100644 --- a/config/application-prd.yml +++ b/src/main/resources/application-prod.yml @@ -1,11 +1,11 @@ spring: config: activate: - on-profile: prd + on-profile: prod datasource: - url: jdbc:mysql://database-1.cv4wygc02ww1.us-east-1.rds.amazonaws.com:3306/moneygement + url: ${DB_HOST} username: admin - password: ekskfakstp1! + password: ${DB_PASSWORD} driver-class-name: com.mysql.cj.jdbc.Driver sql: init: @@ -13,7 +13,7 @@ spring: continue-on-error: true jpa: hibernate: - ddl-auto: none + ddl-auto: create # p6spy datasource: diff --git a/config/application.yml b/src/main/resources/application.yml similarity index 83% rename from config/application.yml rename to src/main/resources/application.yml index 6202848..299a6ce 100644 --- a/config/application.yml +++ b/src/main/resources/application.yml @@ -9,13 +9,13 @@ server: spring: profiles: # change profile - active: local + active: prod config: import: - - file:./config/queries.yml - - file:./config/external-url.yml - - file:./config/business-config.yml - - file:./config/encryption.yml + - classpath:queries.yml + - classpath:external-url.yml + - classpath:business-config.yml + - classpath:encryption.yml jpa: show-sql: true format_sql: true @@ -26,8 +26,8 @@ spring: sql: init: encoding: UTF-8 - schema-locations: file:./data/schema.sql - data-locations: file:./data/data.sql + schema-locations: classpath:data/schema.sql + data-locations: classpath:data/data.sql ai: openai: # api-key: testKey @@ -80,4 +80,4 @@ management: # log4j logging: - config: file:./config/log4j2.xml + config: classpath:log4j2.xml diff --git a/config/business-config.yml b/src/main/resources/business-config.yml similarity index 100% rename from config/business-config.yml rename to src/main/resources/business-config.yml diff --git a/data/data.sql b/src/main/resources/data/data.sql similarity index 100% rename from data/data.sql rename to src/main/resources/data/data.sql diff --git a/data/schema.sql b/src/main/resources/data/schema.sql similarity index 100% rename from data/schema.sql rename to src/main/resources/data/schema.sql diff --git a/config/encryption.yml b/src/main/resources/encryption.yml similarity index 100% rename from config/encryption.yml rename to src/main/resources/encryption.yml diff --git a/config/external-url.yml b/src/main/resources/external-url.yml similarity index 100% rename from config/external-url.yml rename to src/main/resources/external-url.yml diff --git a/config/log4j2.xml b/src/main/resources/log4j2.xml similarity index 100% rename from config/log4j2.xml rename to src/main/resources/log4j2.xml diff --git a/config/logback-spring.xml b/src/main/resources/logback-spring.xml similarity index 100% rename from config/logback-spring.xml rename to src/main/resources/logback-spring.xml diff --git a/config/queries.yml b/src/main/resources/queries.yml similarity index 100% rename from config/queries.yml rename to src/main/resources/queries.yml