From 18591523679680c4b4c0e453adf35a655d94cb67 Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Sun, 26 May 2024 23:55:14 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[feat]=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EB=B3=84=20=EC=B6=94=EC=B2=9C=ED=95=98=EB=8A=94=20API?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0(=EB=AF=B8=EC=99=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/jwt/JwtTokenProvider.java | 2 +- .../Ness/Backend/domain/main/MainService.java | 17 +++-- ...rtService.java => AsyncReportService.java} | 8 ++- .../domain/report/ReportController.java | 6 +- .../domain/schedule/ScheduleRepository.java | 11 ++++ .../domain/schedule/entity/Schedule.java | 6 ++ .../Backend/domain/todo/AsyncTodoService.java | 66 +++++++++++++++++++ .../request/PostFastApiTodoCategoryDto.java | 22 +++++++ .../todo/dto/request/PostFastApiTodoDto.java | 32 +++++++++ .../dto/request/PostFastApiTodoListDto.java | 18 +++++ .../PostFastApiRecommendCategoryDto.java | 22 +++++++ .../dto/response/PostFastApiRecommendDto.java | 19 ++++++ .../response/PostFastApiRecommendListDto.java | 18 +++++ .../response/PostFastApiRecommendTodoDto.java | 32 +++++++++ .../global/fastApi/FastApiTodoApi.java | 13 ++++ .../java/Ness/Backend/global/time/Time.java | 13 ++++ 16 files changed, 294 insertions(+), 11 deletions(-) rename src/main/java/Ness/Backend/domain/report/{ReportService.java => AsyncReportService.java} (97%) create mode 100644 src/main/java/Ness/Backend/domain/todo/AsyncTodoService.java create mode 100644 src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoCategoryDto.java create mode 100644 src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoDto.java create mode 100644 src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoListDto.java create mode 100644 src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendCategoryDto.java create mode 100644 src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendDto.java create mode 100644 src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendListDto.java create mode 100644 src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendTodoDto.java create mode 100644 src/main/java/Ness/Backend/global/fastApi/FastApiTodoApi.java create mode 100644 src/main/java/Ness/Backend/global/time/Time.java diff --git a/src/main/java/Ness/Backend/domain/auth/jwt/JwtTokenProvider.java b/src/main/java/Ness/Backend/domain/auth/jwt/JwtTokenProvider.java index 9faef0b..62a9223 100644 --- a/src/main/java/Ness/Backend/domain/auth/jwt/JwtTokenProvider.java +++ b/src/main/java/Ness/Backend/domain/auth/jwt/JwtTokenProvider.java @@ -105,7 +105,7 @@ private String getAuthKeyClaim(String jwtToken) { .asString(); //가져온 클레임을 문자열로 변환하여 반환 } - /* 토큰에서 expire time 정보 가져오는 메서드 */ + /* 토큰에서 expire Time 정보 가져오는 메서드 */ private Date getExpireTimeClaim(String jwtToken) { return JWT.require(this.getSign()) .acceptExpiresAt(JWT_EXPIRATION_TIME) diff --git a/src/main/java/Ness/Backend/domain/main/MainService.java b/src/main/java/Ness/Backend/domain/main/MainService.java index 0663b81..e74a2a6 100644 --- a/src/main/java/Ness/Backend/domain/main/MainService.java +++ b/src/main/java/Ness/Backend/domain/main/MainService.java @@ -1,7 +1,9 @@ package Ness.Backend.domain.main; import Ness.Backend.domain.main.dto.response.GetMainDto; -import Ness.Backend.domain.report.ReportService; +import Ness.Backend.domain.todo.AsyncTodoService; +import Ness.Backend.domain.todo.dto.response.PostFastApiRecommendListDto; +import Ness.Backend.domain.report.AsyncReportService; import Ness.Backend.domain.report.dto.response.PostFastApiAiRecommendActivityDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -11,13 +13,16 @@ @RequiredArgsConstructor @Transactional public class MainService { - private final ReportService reportService; + private final AsyncReportService asyncReportService; + private final AsyncTodoService asyncTodoService; + + public GetMainDto getMain(Long memberId){ + PostFastApiAiRecommendActivityDto activityDto = asyncReportService.getRecommendActivity(memberId); + PostFastApiRecommendListDto todoDto = asyncTodoService.getTodo(memberId); - public GetMainDto getMain(Long id){ - PostFastApiAiRecommendActivityDto dto = reportService.getRecommendActivity(id); return GetMainDto.builder() - .recommendText(dto.getAnswer()) - .activityList(dto.getActivityList()) + .recommendText(activityDto.getAnswer()) + .activityList(activityDto.getActivityList()) .build(); } } diff --git a/src/main/java/Ness/Backend/domain/report/ReportService.java b/src/main/java/Ness/Backend/domain/report/AsyncReportService.java similarity index 97% rename from src/main/java/Ness/Backend/domain/report/ReportService.java rename to src/main/java/Ness/Backend/domain/report/AsyncReportService.java index 8d62399..1d38b16 100644 --- a/src/main/java/Ness/Backend/domain/report/ReportService.java +++ b/src/main/java/Ness/Backend/domain/report/AsyncReportService.java @@ -17,7 +17,10 @@ import Ness.Backend.global.fastApi.FastApiTagApi; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -26,7 +29,9 @@ @Service @RequiredArgsConstructor @Slf4j -public class ReportService { +@EnableAsync +@Transactional +public class AsyncReportService { private final ReportMemoryRepository reportMemoryRepository; private final ReportTagRepository reportTagRepository; private final ReportRecommendRepository reportRecommendRepository; @@ -147,6 +152,7 @@ public PostFastApiAiTagListDto postNewAiTag(Long id, ZonedDateTime today){ } /* 한 줄 추천 및 엑티비티 가져오는 로직 */ + @Async public PostFastApiAiRecommendActivityDto getRecommendActivity(Long memberId){ // 오늘 날짜 가져오기 ZonedDateTime now = getToday(); diff --git a/src/main/java/Ness/Backend/domain/report/ReportController.java b/src/main/java/Ness/Backend/domain/report/ReportController.java index 4b92d9a..e38647d 100644 --- a/src/main/java/Ness/Backend/domain/report/ReportController.java +++ b/src/main/java/Ness/Backend/domain/report/ReportController.java @@ -14,16 +14,16 @@ @RequiredArgsConstructor @RequestMapping("/report") public class ReportController { - private final ReportService reportService; + private final AsyncReportService asyncReportService; @GetMapping("/memory") @Operation(summary = "리포트 메모리 조회 API", description = "사용자의 ID로 리포트 메모리를 조회하는 API입니다.") public GetReportMemoryListDto getMemory(@AuthUser Member member) { - return reportService.getMemory(member.getId()); + return asyncReportService.getMemory(member.getId()); } @GetMapping("/tag") @Operation(summary = "리포트 테그 조회 API", description = "사용자의 ID로 리포트 테그를 조회하는 API입니다.") public GetReportTagListDto getTag(@AuthUser Member member) { - return reportService.getTag(member.getId()); + return asyncReportService.getTag(member.getId()); } } \ No newline at end of file diff --git a/src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java b/src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java index e3139e8..1faa873 100644 --- a/src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java +++ b/src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java @@ -34,6 +34,17 @@ List findOneDaySchedulesByMember_Id( @Param("memberId") Long memberId, @Param("date") ZonedDateTime date); + // 메인페이지에서 각 일정의 한줄 추천 가져오기 위한 스케쥴 쿼리 + @Query(value = "SELECT * FROM schedule " + + "WHERE member_id = :memberId " + + "AND (CONVERT_TZ(start_time, '+00:00', '+09:00')) > CONVERT_TZ(:now, '+00:00', '+09:00') " + + "ORDER BY start_time ASC " + + "LIMIT 5", + nativeQuery = true) + List findUpcomingSchedulesByStart_Time( + @Param("memberId") Long memberId, + @Param("now") ZonedDateTime now); + //스케쥴 ID로 특정 스케쥴 찾아주기 Schedule findScheduleById(Long scheduleId); diff --git a/src/main/java/Ness/Backend/domain/schedule/entity/Schedule.java b/src/main/java/Ness/Backend/domain/schedule/entity/Schedule.java index f4dafae..b4a6d1b 100644 --- a/src/main/java/Ness/Backend/domain/schedule/entity/Schedule.java +++ b/src/main/java/Ness/Backend/domain/schedule/entity/Schedule.java @@ -29,6 +29,8 @@ public class Schedule { private ZonedDateTime endTime; + private String todo; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; @@ -67,4 +69,8 @@ public void changeSchedule(String info, String location, String person, ZonedDat public void changeCategory(Category category){ this.category = category; } + + public void updateTodo(String todo){ + this.todo = todo; + } } diff --git a/src/main/java/Ness/Backend/domain/todo/AsyncTodoService.java b/src/main/java/Ness/Backend/domain/todo/AsyncTodoService.java new file mode 100644 index 0000000..7e62bbb --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/AsyncTodoService.java @@ -0,0 +1,66 @@ +package Ness.Backend.domain.todo; + +import Ness.Backend.domain.schedule.ScheduleRepository; +import Ness.Backend.domain.schedule.entity.Schedule; +import Ness.Backend.domain.todo.dto.request.PostFastApiTodoCategoryDto; +import Ness.Backend.domain.todo.dto.request.PostFastApiTodoDto; +import Ness.Backend.domain.todo.dto.request.PostFastApiTodoListDto; +import Ness.Backend.domain.todo.dto.response.PostFastApiRecommendListDto; +import Ness.Backend.global.fastApi.FastApiTodoApi; +import Ness.Backend.global.time.Time; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; + +@Service +@RequiredArgsConstructor +@Slf4j +@EnableAsync +@Transactional +public class AsyncTodoService { + private final FastApiTodoApi fastApiTodoApi; + private final ScheduleRepository scheduleRepository; + private final Time time; + + /* 일정 관련 한 줄 추천 가져오는 로직 */ + @Async + public PostFastApiRecommendListDto getTodo(Long memberId){ + // 오늘 날짜 가져오기 + ZonedDateTime now = time.getToday(); + List upcomingSchedules = scheduleRepository.findUpcomingSchedulesByStart_Time(memberId, now); + + List filteredSchedules = upcomingSchedules.stream() + .filter(schedule -> schedule.getTodo() == null) + .toList(); + + List todoDtos = filteredSchedules.stream() + .map(schedule -> PostFastApiTodoDto.builder() + .startTime(schedule.getStartTime()) + .category(PostFastApiTodoCategoryDto.builder() + .id(schedule.getCategory().getId()) + .name(schedule.getCategory().getName()) + .color(schedule.getCategory().getColor()) + .build()) + .person(schedule.getPerson()) + .location(schedule.getLocation()) + .info(schedule.getInfo()) + .build()) + .toList(); + + PostFastApiTodoListDto userTodoList = new PostFastApiTodoListDto(todoDtos); + + PostFastApiRecommendListDto aiTodoList = fastApiTodoApi.creatFastApiTodo(userTodoList); + + aiTodoList.getRecommendationList() + .forEach(todo -> todo.getTodo()); + + return aiTodoList; + } +} diff --git a/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoCategoryDto.java b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoCategoryDto.java new file mode 100644 index 0000000..2883fb6 --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoCategoryDto.java @@ -0,0 +1,22 @@ +package Ness.Backend.domain.todo.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostFastApiTodoCategoryDto { + @JsonProperty("categoryId") + private Long id; + + @JsonProperty("categoryName") + private String name; + + @JsonProperty("categoryColor") + private String color; +} diff --git a/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoDto.java b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoDto.java new file mode 100644 index 0000000..d72f2b1 --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoDto.java @@ -0,0 +1,32 @@ +package Ness.Backend.domain.todo.dto.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.ZonedDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostFastApiTodoDto { + @JsonProperty("startTime") + @JsonFormat(shape = JsonFormat.Shape.STRING) + private ZonedDateTime startTime; + + @JsonProperty("category") + private PostFastApiTodoCategoryDto category; + + @JsonProperty("person") + private String person; + + @JsonProperty("location") + private String location; + + @JsonProperty("info") + private String info; +} diff --git a/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoListDto.java b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoListDto.java new file mode 100644 index 0000000..8a8b529 --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoListDto.java @@ -0,0 +1,18 @@ +package Ness.Backend.domain.todo.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostFastApiTodoListDto { + @JsonProperty("todoList") + List todoList; +} diff --git a/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendCategoryDto.java b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendCategoryDto.java new file mode 100644 index 0000000..1790f3a --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendCategoryDto.java @@ -0,0 +1,22 @@ +package Ness.Backend.domain.todo.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostFastApiRecommendCategoryDto { + @JsonProperty("categoryId") + private Long id; + + @JsonProperty("categoryName") + private String name; + + @JsonProperty("categoryColor") + private String color; +} diff --git a/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendDto.java b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendDto.java new file mode 100644 index 0000000..f91ad0c --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendDto.java @@ -0,0 +1,19 @@ +package Ness.Backend.domain.todo.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostFastApiRecommendDto { + @JsonProperty("todo") + private PostFastApiRecommendTodoDto todo; + + @JsonProperty("nessComment") + private String nessComment; +} diff --git a/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendListDto.java b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendListDto.java new file mode 100644 index 0000000..5d9b91a --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendListDto.java @@ -0,0 +1,18 @@ +package Ness.Backend.domain.todo.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostFastApiRecommendListDto { + @JsonProperty("recommendationList") + List recommendationList; +} diff --git a/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendTodoDto.java b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendTodoDto.java new file mode 100644 index 0000000..3b85a44 --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendTodoDto.java @@ -0,0 +1,32 @@ +package Ness.Backend.domain.todo.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.ZonedDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostFastApiRecommendTodoDto { + @JsonProperty("startTime") + @JsonFormat(shape = JsonFormat.Shape.STRING) + private ZonedDateTime startTime; + + @JsonProperty("category") + private PostFastApiRecommendTodoDto category; + + @JsonProperty("person") + private String person; + + @JsonProperty("location") + private String location; + + @JsonProperty("info") + private String info; +} diff --git a/src/main/java/Ness/Backend/global/fastApi/FastApiTodoApi.java b/src/main/java/Ness/Backend/global/fastApi/FastApiTodoApi.java new file mode 100644 index 0000000..6d03b56 --- /dev/null +++ b/src/main/java/Ness/Backend/global/fastApi/FastApiTodoApi.java @@ -0,0 +1,13 @@ +package Ness.Backend.global.fastApi; + +import Ness.Backend.domain.todo.dto.request.PostFastApiTodoListDto; +import Ness.Backend.domain.todo.dto.response.PostFastApiRecommendListDto; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +@FeignClient( + name = "FastApiTodo", + url = "${spring.cloud.openfeign.client.config.fastapi.url}") +public interface FastApiTodoApi { + @PostMapping(value = "/recommendation/list") + PostFastApiRecommendListDto creatFastApiTodo(PostFastApiTodoListDto postFastApiTodoListDto); +} \ No newline at end of file diff --git a/src/main/java/Ness/Backend/global/time/Time.java b/src/main/java/Ness/Backend/global/time/Time.java new file mode 100644 index 0000000..228f4ac --- /dev/null +++ b/src/main/java/Ness/Backend/global/time/Time.java @@ -0,0 +1,13 @@ +package Ness.Backend.global.time; + +import org.springframework.stereotype.Component; + +import java.time.ZoneId; +import java.time.ZonedDateTime; + +@Component +public class Time { + public ZonedDateTime getToday(){ + return ZonedDateTime.now(ZoneId.of("Asia/Seoul")); + } +} \ No newline at end of file From 899c954b393b9d9c093797ad8370402af2026b3a Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Sun, 26 May 2024 23:56:33 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[refact]=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=82=A0=EC=94=A8=20API=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/weather/WeatherController.java | 30 ------------ .../domain/weather/WeatherService.java | 47 ------------------- .../weather/dto/response/GetWeatherDto.java | 9 ---- .../weather/dto/response/PublicDataBody.java | 28 ----------- .../dto/response/PublicDataHeader.java | 19 -------- .../weather/dto/response/PublicDataItem.java | 37 --------------- .../dto/response/PublicDataItemList.java | 18 ------- .../dto/response/PublicDataResponse.java | 19 -------- .../dto/response/PublicDataWeather.java | 19 -------- .../publicData/PublicDataWeatherApi.java | 37 --------------- 10 files changed, 263 deletions(-) delete mode 100644 src/main/java/Ness/Backend/domain/weather/WeatherController.java delete mode 100644 src/main/java/Ness/Backend/domain/weather/WeatherService.java delete mode 100644 src/main/java/Ness/Backend/domain/weather/dto/response/GetWeatherDto.java delete mode 100644 src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataBody.java delete mode 100644 src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataHeader.java delete mode 100644 src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataItem.java delete mode 100644 src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataItemList.java delete mode 100644 src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataResponse.java delete mode 100644 src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataWeather.java delete mode 100644 src/main/java/Ness/Backend/global/publicData/PublicDataWeatherApi.java diff --git a/src/main/java/Ness/Backend/domain/weather/WeatherController.java b/src/main/java/Ness/Backend/domain/weather/WeatherController.java deleted file mode 100644 index 8be8d51..0000000 --- a/src/main/java/Ness/Backend/domain/weather/WeatherController.java +++ /dev/null @@ -1,30 +0,0 @@ -package Ness.Backend.domain.weather; - -import Ness.Backend.domain.member.entity.Member; -import Ness.Backend.global.auth.AuthUser; -import io.swagger.v3.oas.annotations.Operation; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatusCode; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/weather") -public class WeatherController { - private final WeatherService weatherService; - - @GetMapping("/dev") - @Operation(summary = "날씨 정보 요청", description = "기상청에서 초단기예보 날씨 정보를 가져오는 API입니다.") - public ResponseEntity getWeather() { - return new ResponseEntity<>(weatherService.getWeather(), HttpStatusCode.valueOf(200)); - } - - @GetMapping("") - @Operation(summary = "날씨 정보 요청", description = "기상청에서 초단기예보 날씨 정보를 가져오는 API입니다.") - public ResponseEntity getWeather(@AuthUser Member member) { - return new ResponseEntity<>(weatherService.getWeather(), HttpStatusCode.valueOf(200)); - } -} diff --git a/src/main/java/Ness/Backend/domain/weather/WeatherService.java b/src/main/java/Ness/Backend/domain/weather/WeatherService.java deleted file mode 100644 index 4ba7562..0000000 --- a/src/main/java/Ness/Backend/domain/weather/WeatherService.java +++ /dev/null @@ -1,47 +0,0 @@ -package Ness.Backend.domain.weather; - -import Ness.Backend.domain.weather.dto.response.PublicDataWeather; -import Ness.Backend.global.publicData.PublicDataWeatherApi; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; - -@Service -@RequiredArgsConstructor -@Slf4j -public class WeatherService { - private final PublicDataWeatherApi publicDataWeatherApi; - - @Value("${api-key.public-weather}") - private String publicWeatherApiKey; - - public PublicDataWeather getWeather(){ - return getPublicDataWeather(); - } - - public ZonedDateTime getToday(){ - return ZonedDateTime.now(ZoneId.of("Asia/Seoul")); - } - - /* - * Map categoryAverages = items.stream() - .collect(Collectors.groupingBy( - WeatherItemDto::getCategory, - Collectors.averagingDouble(item -> Double.parseDouble(item.getFcstValue())) - )); - * */ - - public PublicDataWeather getPublicDataWeather(){ - return publicDataWeatherApi.getPublicDataWeather( - "application/json", - publicWeatherApiKey, 60, 1, "JSON", - getToday().format(DateTimeFormatter.ofPattern("yyyyMMdd")), - getToday().format(DateTimeFormatter.ofPattern("Hm")), - 59, 127); // 우선은 서울 서대문구로 하드코딩 - } -} diff --git a/src/main/java/Ness/Backend/domain/weather/dto/response/GetWeatherDto.java b/src/main/java/Ness/Backend/domain/weather/dto/response/GetWeatherDto.java deleted file mode 100644 index 8737084..0000000 --- a/src/main/java/Ness/Backend/domain/weather/dto/response/GetWeatherDto.java +++ /dev/null @@ -1,9 +0,0 @@ -package Ness.Backend.domain.weather.dto.response; - -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -public class GetWeatherDto { -} \ No newline at end of file diff --git a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataBody.java b/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataBody.java deleted file mode 100644 index 6aa3273..0000000 --- a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataBody.java +++ /dev/null @@ -1,28 +0,0 @@ -package Ness.Backend.domain.weather.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@EqualsAndHashCode -@NoArgsConstructor -@AllArgsConstructor -public class PublicDataBody { - @JsonProperty("numOfRows") - private int numOfRows; - - @JsonProperty("pageNo") - private int pageNo; - - @JsonProperty("totalCount") - private int totalCount; - - @JsonProperty("dataType") - private String dataType; - - @JsonProperty("items") - PublicDataItemList publicDataItemList; -} diff --git a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataHeader.java b/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataHeader.java deleted file mode 100644 index 667561d..0000000 --- a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataHeader.java +++ /dev/null @@ -1,19 +0,0 @@ -package Ness.Backend.domain.weather.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@EqualsAndHashCode -@NoArgsConstructor -@AllArgsConstructor -public class PublicDataHeader { - @JsonProperty("resultCode") - private int resultCode; - - @JsonProperty("resultMsg") - private String resultMsg; -} diff --git a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataItem.java b/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataItem.java deleted file mode 100644 index 81976ac..0000000 --- a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataItem.java +++ /dev/null @@ -1,37 +0,0 @@ -package Ness.Backend.domain.weather.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@EqualsAndHashCode -@NoArgsConstructor -@AllArgsConstructor -public class PublicDataItem { - @JsonProperty("baseDate") - private int baseDate; - - @JsonProperty("baseTime") - private int baseTime; - - @JsonProperty("nx") - private int nx; - - @JsonProperty("ny") - private int ny; - - @JsonProperty("category") - private String category; - - @JsonProperty("fcstDate") - private int fcstDate; - - @JsonProperty("fcstTime") - private int fcstTime; - - @JsonProperty("fcstValue") - private String fcstValue; -} diff --git a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataItemList.java b/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataItemList.java deleted file mode 100644 index c6dc992..0000000 --- a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataItemList.java +++ /dev/null @@ -1,18 +0,0 @@ -package Ness.Backend.domain.weather.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.util.List; - -@Getter -@EqualsAndHashCode -@NoArgsConstructor -@AllArgsConstructor -public class PublicDataItemList { - @JsonProperty("item") - List publicDataItems; -} diff --git a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataResponse.java b/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataResponse.java deleted file mode 100644 index 0613843..0000000 --- a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataResponse.java +++ /dev/null @@ -1,19 +0,0 @@ -package Ness.Backend.domain.weather.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@EqualsAndHashCode -@NoArgsConstructor -@AllArgsConstructor -public class PublicDataResponse { - @JsonProperty("header") - private PublicDataHeader header; - - @JsonProperty("body") - private PublicDataBody body; -} diff --git a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataWeather.java b/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataWeather.java deleted file mode 100644 index bd46ecb..0000000 --- a/src/main/java/Ness/Backend/domain/weather/dto/response/PublicDataWeather.java +++ /dev/null @@ -1,19 +0,0 @@ -package Ness.Backend.domain.weather.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; - -/* -* 초단기예보 -* */ -@Getter -@EqualsAndHashCode -@NoArgsConstructor -@AllArgsConstructor -public class PublicDataWeather { - @JsonProperty("response") - private PublicDataResponse response; -} diff --git a/src/main/java/Ness/Backend/global/publicData/PublicDataWeatherApi.java b/src/main/java/Ness/Backend/global/publicData/PublicDataWeatherApi.java deleted file mode 100644 index 697b695..0000000 --- a/src/main/java/Ness/Backend/global/publicData/PublicDataWeatherApi.java +++ /dev/null @@ -1,37 +0,0 @@ -package Ness.Backend.global.publicData; - -import Ness.Backend.domain.weather.dto.response.PublicDataWeather; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestHeader; - -/* -* 기상청 초단기예보조회 -* */ -@FeignClient( - name = "PublicDataWeather", - url = "${spring.cloud.openfeign.client.config.public-weather.url}") -public interface PublicDataWeatherApi { - @GetMapping(value = "/1360000/VilageFcstInfoService_2.0/getUltraSrtFcst?" + - "ServiceKey={SERVICE_KEY}" + - "&numOfRows={NUMBER_OF_ROWS}" + - "&pageNo={PAGE_NO}" + - "&dataType={DATA_TYPE}" + - "&base_date={BASE_DATE}" + - "&base_time={BASE_TIME}" + - "&nx={NX}" + - "&ny={NY}", - consumes = "application/json", - produces = "application/json") - PublicDataWeather getPublicDataWeather( - @RequestHeader("Content-type") String contentType, - @PathVariable("SERVICE_KEY") String serviceKey, - @PathVariable("NUMBER_OF_ROWS") int numOfRows, - @PathVariable("PAGE_NO") int pageNo, - @PathVariable("DATA_TYPE") String dataType, - @PathVariable("BASE_DATE") String formattedLocalDate, - @PathVariable("BASE_TIME") String formattedLocalTime, - @PathVariable("NX") int x, - @PathVariable("NY") int y); -} \ No newline at end of file From 29907d43115978ca4787869d5f6dfc54a1bcaa50 Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Mon, 27 May 2024 17:10:43 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[feat]=20=EB=A9=94=EC=9D=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=98=20=EB=84=A4=EC=8A=A4=20=EC=BD=94?= =?UTF-8?q?=EB=A9=98=ED=8A=B8=20=EA=B0=9C=EB=B0=9C=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ness/Backend/domain/main/MainService.java | 22 ++--- .../domain/main/dto/response/GetMainDto.java | 9 ++- .../domain/report/ReportController.java | 6 +- ...cReportService.java => ReportService.java} | 6 +- .../domain/schedule/ScheduleService.java | 20 +++++ .../schedule/dto/response/GetScheduleDto.java | 8 +- .../Backend/domain/todo/AsyncTodoService.java | 66 --------------- .../Ness/Backend/domain/todo/TodoService.java | 80 +++++++++++++++++++ .../todo/dto/request/PostFastApiTodoDto.java | 3 + .../dto/request/PostFastApiTodoListDto.java | 8 +- .../response/PostFastApiRecommendTodoDto.java | 3 + 11 files changed, 145 insertions(+), 86 deletions(-) rename src/main/java/Ness/Backend/domain/report/{AsyncReportService.java => ReportService.java} (98%) delete mode 100644 src/main/java/Ness/Backend/domain/todo/AsyncTodoService.java create mode 100644 src/main/java/Ness/Backend/domain/todo/TodoService.java diff --git a/src/main/java/Ness/Backend/domain/main/MainService.java b/src/main/java/Ness/Backend/domain/main/MainService.java index e74a2a6..2929023 100644 --- a/src/main/java/Ness/Backend/domain/main/MainService.java +++ b/src/main/java/Ness/Backend/domain/main/MainService.java @@ -1,28 +1,32 @@ package Ness.Backend.domain.main; import Ness.Backend.domain.main.dto.response.GetMainDto; -import Ness.Backend.domain.todo.AsyncTodoService; -import Ness.Backend.domain.todo.dto.response.PostFastApiRecommendListDto; -import Ness.Backend.domain.report.AsyncReportService; +import Ness.Backend.domain.report.ReportService; import Ness.Backend.domain.report.dto.response.PostFastApiAiRecommendActivityDto; +import Ness.Backend.domain.schedule.dto.response.GetScheduleDto; +import Ness.Backend.domain.todo.TodoService; +import Ness.Backend.domain.todo.dto.response.PostFastApiRecommendDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @RequiredArgsConstructor @Transactional public class MainService { - private final AsyncReportService asyncReportService; - private final AsyncTodoService asyncTodoService; + private final ReportService reportService; + private final TodoService todoService; public GetMainDto getMain(Long memberId){ - PostFastApiAiRecommendActivityDto activityDto = asyncReportService.getRecommendActivity(memberId); - PostFastApiRecommendListDto todoDto = asyncTodoService.getTodo(memberId); + List scheduleDtos = todoService.getTodo(memberId); + PostFastApiAiRecommendActivityDto activityDtos = reportService.getRecommendActivity(memberId); return GetMainDto.builder() - .recommendText(activityDto.getAnswer()) - .activityList(activityDto.getActivityList()) + .recommendText(activityDtos.getAnswer()) + .activityList(activityDtos.getActivityList()) + .scheduleList(scheduleDtos) .build(); } } diff --git a/src/main/java/Ness/Backend/domain/main/dto/response/GetMainDto.java b/src/main/java/Ness/Backend/domain/main/dto/response/GetMainDto.java index cbc9638..7292566 100644 --- a/src/main/java/Ness/Backend/domain/main/dto/response/GetMainDto.java +++ b/src/main/java/Ness/Backend/domain/main/dto/response/GetMainDto.java @@ -1,6 +1,7 @@ package Ness.Backend.domain.main.dto.response; import Ness.Backend.domain.report.dto.response.PostFastApiAiActivityDto; +import Ness.Backend.domain.schedule.dto.response.GetScheduleDto; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; @@ -21,10 +22,16 @@ public class GetMainDto { // 한줄 추천 활동 리스트 private List activityList; + // 일정 및 한줄 추천 리스트 + private List scheduleList; + @Builder - public GetMainDto(String recommendText, List activityList){ + public GetMainDto(String recommendText, + List activityList, + List scheduleList){ // 한줄 추천 데이터 this.recommendText = recommendText; this.activityList = activityList; + this.scheduleList = scheduleList; } } diff --git a/src/main/java/Ness/Backend/domain/report/ReportController.java b/src/main/java/Ness/Backend/domain/report/ReportController.java index e38647d..4b92d9a 100644 --- a/src/main/java/Ness/Backend/domain/report/ReportController.java +++ b/src/main/java/Ness/Backend/domain/report/ReportController.java @@ -14,16 +14,16 @@ @RequiredArgsConstructor @RequestMapping("/report") public class ReportController { - private final AsyncReportService asyncReportService; + private final ReportService reportService; @GetMapping("/memory") @Operation(summary = "리포트 메모리 조회 API", description = "사용자의 ID로 리포트 메모리를 조회하는 API입니다.") public GetReportMemoryListDto getMemory(@AuthUser Member member) { - return asyncReportService.getMemory(member.getId()); + return reportService.getMemory(member.getId()); } @GetMapping("/tag") @Operation(summary = "리포트 테그 조회 API", description = "사용자의 ID로 리포트 테그를 조회하는 API입니다.") public GetReportTagListDto getTag(@AuthUser Member member) { - return asyncReportService.getTag(member.getId()); + return reportService.getTag(member.getId()); } } \ No newline at end of file diff --git a/src/main/java/Ness/Backend/domain/report/AsyncReportService.java b/src/main/java/Ness/Backend/domain/report/ReportService.java similarity index 98% rename from src/main/java/Ness/Backend/domain/report/AsyncReportService.java rename to src/main/java/Ness/Backend/domain/report/ReportService.java index 1d38b16..07aabcf 100644 --- a/src/main/java/Ness/Backend/domain/report/AsyncReportService.java +++ b/src/main/java/Ness/Backend/domain/report/ReportService.java @@ -17,8 +17,6 @@ import Ness.Backend.global.fastApi.FastApiTagApi; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,9 +27,8 @@ @Service @RequiredArgsConstructor @Slf4j -@EnableAsync @Transactional -public class AsyncReportService { +public class ReportService { private final ReportMemoryRepository reportMemoryRepository; private final ReportTagRepository reportTagRepository; private final ReportRecommendRepository reportRecommendRepository; @@ -152,7 +149,6 @@ public PostFastApiAiTagListDto postNewAiTag(Long id, ZonedDateTime today){ } /* 한 줄 추천 및 엑티비티 가져오는 로직 */ - @Async public PostFastApiAiRecommendActivityDto getRecommendActivity(Long memberId){ // 오늘 날짜 가져오기 ZonedDateTime now = getToday(); diff --git a/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java b/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java index 252be58..209c84c 100644 --- a/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java +++ b/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java @@ -248,4 +248,24 @@ public GetScheduleListDto makeScheduleListDto(List scheduleList){ .toList(); return new GetScheduleListDto(getScheduleDtos); } + + public List makeScheduleWithCommentListDto(List scheduleList){ + // ScheduleListResponseDto에 매핑 + return scheduleList.stream() + .map(schedule -> GetScheduleDto.builder() + .id(schedule.getId()) + .category(schedule.getCategory().getName()) + .categoryNum(schedule.getCategory().getId()) + .categoryColor(schedule.getCategory().getColor()) + .info(schedule.getInfo()) + .startTime(schedule.getStartTime()) + .endTime(schedule.getEndTime()) + .nessComment(schedule.getTodo()) + .details(GetScheduleDetailDto.builder() + .person(schedule.getPerson()) + .location(schedule.getLocation()) + .build()) + .build()) + .toList(); + } } diff --git a/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDto.java b/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDto.java index 0f5a0b8..87cfa39 100644 --- a/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDto.java +++ b/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDto.java @@ -42,10 +42,15 @@ public class GetScheduleDto { @JsonProperty("details") private GetScheduleDetailDto details; + + @Schema(description = "스케줄에 대한 네스의 한줄 코멘트", example = "공대에서 공부하시는군요. 효율적인 학습을 위해 좋은 환경을 만드세요!") + @JsonProperty("nessComment") + private String nessComment; + @Builder public GetScheduleDto(Long id, String category, Long categoryNum, String categoryColor, String info, ZonedDateTime startTime, ZonedDateTime endTime, - GetScheduleDetailDto details){ + GetScheduleDetailDto details, String nessComment){ this.id = id; this.category = category; this.categoryNum = categoryNum; @@ -54,5 +59,6 @@ public GetScheduleDto(Long id, String category, Long categoryNum, String categor this.startTime = startTime; this.endTime = endTime; this.details = details; + this.nessComment = nessComment; } } diff --git a/src/main/java/Ness/Backend/domain/todo/AsyncTodoService.java b/src/main/java/Ness/Backend/domain/todo/AsyncTodoService.java deleted file mode 100644 index 7e62bbb..0000000 --- a/src/main/java/Ness/Backend/domain/todo/AsyncTodoService.java +++ /dev/null @@ -1,66 +0,0 @@ -package Ness.Backend.domain.todo; - -import Ness.Backend.domain.schedule.ScheduleRepository; -import Ness.Backend.domain.schedule.entity.Schedule; -import Ness.Backend.domain.todo.dto.request.PostFastApiTodoCategoryDto; -import Ness.Backend.domain.todo.dto.request.PostFastApiTodoDto; -import Ness.Backend.domain.todo.dto.request.PostFastApiTodoListDto; -import Ness.Backend.domain.todo.dto.response.PostFastApiRecommendListDto; -import Ness.Backend.global.fastApi.FastApiTodoApi; -import Ness.Backend.global.time.Time; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.util.List; - -@Service -@RequiredArgsConstructor -@Slf4j -@EnableAsync -@Transactional -public class AsyncTodoService { - private final FastApiTodoApi fastApiTodoApi; - private final ScheduleRepository scheduleRepository; - private final Time time; - - /* 일정 관련 한 줄 추천 가져오는 로직 */ - @Async - public PostFastApiRecommendListDto getTodo(Long memberId){ - // 오늘 날짜 가져오기 - ZonedDateTime now = time.getToday(); - List upcomingSchedules = scheduleRepository.findUpcomingSchedulesByStart_Time(memberId, now); - - List filteredSchedules = upcomingSchedules.stream() - .filter(schedule -> schedule.getTodo() == null) - .toList(); - - List todoDtos = filteredSchedules.stream() - .map(schedule -> PostFastApiTodoDto.builder() - .startTime(schedule.getStartTime()) - .category(PostFastApiTodoCategoryDto.builder() - .id(schedule.getCategory().getId()) - .name(schedule.getCategory().getName()) - .color(schedule.getCategory().getColor()) - .build()) - .person(schedule.getPerson()) - .location(schedule.getLocation()) - .info(schedule.getInfo()) - .build()) - .toList(); - - PostFastApiTodoListDto userTodoList = new PostFastApiTodoListDto(todoDtos); - - PostFastApiRecommendListDto aiTodoList = fastApiTodoApi.creatFastApiTodo(userTodoList); - - aiTodoList.getRecommendationList() - .forEach(todo -> todo.getTodo()); - - return aiTodoList; - } -} diff --git a/src/main/java/Ness/Backend/domain/todo/TodoService.java b/src/main/java/Ness/Backend/domain/todo/TodoService.java new file mode 100644 index 0000000..3198bc8 --- /dev/null +++ b/src/main/java/Ness/Backend/domain/todo/TodoService.java @@ -0,0 +1,80 @@ +package Ness.Backend.domain.todo; + +import Ness.Backend.domain.profile.ProfileRepository; +import Ness.Backend.domain.profile.entity.Profile; +import Ness.Backend.domain.schedule.ScheduleRepository; +import Ness.Backend.domain.schedule.ScheduleService; +import Ness.Backend.domain.schedule.dto.response.GetScheduleDto; +import Ness.Backend.domain.schedule.dto.response.GetScheduleListDto; +import Ness.Backend.domain.schedule.entity.Schedule; +import Ness.Backend.domain.todo.dto.request.PostFastApiTodoCategoryDto; +import Ness.Backend.domain.todo.dto.request.PostFastApiTodoDto; +import Ness.Backend.domain.todo.dto.request.PostFastApiTodoListDto; +import Ness.Backend.domain.todo.dto.response.PostFastApiRecommendListDto; +import Ness.Backend.global.fastApi.FastApiTodoApi; +import Ness.Backend.global.time.Time; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.ZonedDateTime; +import java.util.List; + +@Service +@RequiredArgsConstructor +@Slf4j +@Transactional +public class TodoService { + private final FastApiTodoApi fastApiTodoApi; + private final ScheduleRepository scheduleRepository; + private final ScheduleService scheduleService; + private final ProfileRepository profileRepository; + private final Time time; + + /* 일정 관련 한 줄 추천 가져오는 로직 */ + public List getTodo(Long memberId){ + Profile userProfile = profileRepository.findProfileByMember_Id(memberId); + // 오늘 날짜 가져오기 + ZonedDateTime now = time.getToday(); + List upcomingSchedules = scheduleRepository.findUpcomingSchedulesByStart_Time(memberId, now); + + List filteredSchedules = upcomingSchedules.stream() + .filter(schedule -> schedule.getTodo() == null) + .toList(); + + if(!filteredSchedules.isEmpty()){ + List todoDtos = filteredSchedules.stream() + .map(schedule -> PostFastApiTodoDto.builder() + .id(schedule.getId()) + .startTime(schedule.getStartTime()) + .category(PostFastApiTodoCategoryDto.builder() + .id(schedule.getCategory().getId()) + .name(schedule.getCategory().getName()) + .color(schedule.getCategory().getColor()) + .build()) + .person(schedule.getPerson()) + .location(schedule.getLocation()) + .info(schedule.getInfo()) + .build()) + .toList(); + + PostFastApiTodoListDto userTodoList = PostFastApiTodoListDto.builder() + .persona(userProfile.getPersonaType()) + .todoList(todoDtos) + .build(); + + PostFastApiRecommendListDto aiTodoList = fastApiTodoApi.creatFastApiTodo(userTodoList); + + //AI에서 받아온 TODO를 업데이트 + aiTodoList.getRecommendationList() + .forEach(todo -> scheduleRepository + .findScheduleById(todo.getTodo().getId()) + .updateTodo(todo.getNessComment())); + } + + List updatedSchedules = scheduleRepository.findUpcomingSchedulesByStart_Time(memberId, now); + + return scheduleService.makeScheduleWithCommentListDto(updatedSchedules); + } +} diff --git a/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoDto.java b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoDto.java index d72f2b1..6189ad5 100644 --- a/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoDto.java +++ b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoDto.java @@ -14,6 +14,9 @@ @AllArgsConstructor @Builder public class PostFastApiTodoDto { + @JsonProperty("id") + private Long id; + @JsonProperty("startTime") @JsonFormat(shape = JsonFormat.Shape.STRING) private ZonedDateTime startTime; diff --git a/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoListDto.java b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoListDto.java index 8a8b529..ea09c88 100644 --- a/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoListDto.java +++ b/src/main/java/Ness/Backend/domain/todo/dto/request/PostFastApiTodoListDto.java @@ -1,5 +1,7 @@ package Ness.Backend.domain.todo.dto.request; +import Ness.Backend.domain.profile.entity.PersonaType; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Builder; @@ -13,6 +15,10 @@ @AllArgsConstructor @Builder public class PostFastApiTodoListDto { + @JsonProperty("persona") + @JsonFormat(shape = JsonFormat.Shape.STRING) + private PersonaType persona; + @JsonProperty("todoList") - List todoList; + private List todoList; } diff --git a/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendTodoDto.java b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendTodoDto.java index 3b85a44..b439f9b 100644 --- a/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendTodoDto.java +++ b/src/main/java/Ness/Backend/domain/todo/dto/response/PostFastApiRecommendTodoDto.java @@ -14,6 +14,9 @@ @AllArgsConstructor @Builder public class PostFastApiRecommendTodoDto { + @JsonProperty("id") + private Long id; + @JsonProperty("startTime") @JsonFormat(shape = JsonFormat.Shape.STRING) private ZonedDateTime startTime;