Skip to content

Commit

Permalink
Merge pull request #98 from studio-recoding/fix-everything
Browse files Browse the repository at this point in the history
[🚀feat] 메인 페이지 일정 한줄 코멘트 API
  • Loading branch information
JeonHaeseung authored May 27, 2024
2 parents 26009dd + 29907d4 commit 8275c3c
Show file tree
Hide file tree
Showing 28 changed files with 349 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/Ness/Backend/domain/main/MainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@
import Ness.Backend.domain.main.dto.response.GetMainDto;
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 ReportService reportService;
private final TodoService todoService;

public GetMainDto getMain(Long memberId){
List<GetScheduleDto> scheduleDtos = todoService.getTodo(memberId);
PostFastApiAiRecommendActivityDto activityDtos = reportService.getRecommendActivity(memberId);

public GetMainDto getMain(Long id){
PostFastApiAiRecommendActivityDto dto = reportService.getRecommendActivity(id);
return GetMainDto.builder()
.recommendText(dto.getAnswer())
.activityList(dto.getActivityList())
.recommendText(activityDtos.getAnswer())
.activityList(activityDtos.getActivityList())
.scheduleList(scheduleDtos)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,10 +22,16 @@ public class GetMainDto {
// 한줄 추천 활동 리스트
private List<PostFastApiAiActivityDto> activityList;

// 일정 및 한줄 추천 리스트
private List<GetScheduleDto> scheduleList;

@Builder
public GetMainDto(String recommendText, List<PostFastApiAiActivityDto> activityList){
public GetMainDto(String recommendText,
List<PostFastApiAiActivityDto> activityList,
List<GetScheduleDto> scheduleList){
// 한줄 추천 데이터
this.recommendText = recommendText;
this.activityList = activityList;
this.scheduleList = scheduleList;
}
}
2 changes: 2 additions & 0 deletions src/main/java/Ness/Backend/domain/report/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand All @@ -26,6 +27,7 @@
@Service
@RequiredArgsConstructor
@Slf4j
@Transactional
public class ReportService {
private final ReportMemoryRepository reportMemoryRepository;
private final ReportTagRepository reportTagRepository;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ List<Schedule> 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<Schedule> findUpcomingSchedulesByStart_Time(
@Param("memberId") Long memberId,
@Param("now") ZonedDateTime now);

//스케쥴 ID로 특정 스케쥴 찾아주기
Schedule findScheduleById(Long scheduleId);

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/Ness/Backend/domain/schedule/ScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,24 @@ public GetScheduleListDto makeScheduleListDto(List<Schedule> scheduleList){
.toList();
return new GetScheduleListDto(getScheduleDtos);
}

public List<GetScheduleDto> makeScheduleWithCommentListDto(List<Schedule> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Schedule {

private ZonedDateTime endTime;

private String todo;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
Expand Down Expand Up @@ -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;
}
}
80 changes: 80 additions & 0 deletions src/main/java/Ness/Backend/domain/todo/TodoService.java
Original file line number Diff line number Diff line change
@@ -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<GetScheduleDto> getTodo(Long memberId){
Profile userProfile = profileRepository.findProfileByMember_Id(memberId);
// 오늘 날짜 가져오기
ZonedDateTime now = time.getToday();
List<Schedule> upcomingSchedules = scheduleRepository.findUpcomingSchedulesByStart_Time(memberId, now);

List<Schedule> filteredSchedules = upcomingSchedules.stream()
.filter(schedule -> schedule.getTodo() == null)
.toList();

if(!filteredSchedules.isEmpty()){
List<PostFastApiTodoDto> 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<Schedule> updatedSchedules = scheduleRepository.findUpcomingSchedulesByStart_Time(memberId, now);

return scheduleService.makeScheduleWithCommentListDto(updatedSchedules);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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("id")
private Long id;

@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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PostFastApiTodoListDto {
@JsonProperty("persona")
@JsonFormat(shape = JsonFormat.Shape.STRING)
private PersonaType persona;

@JsonProperty("todoList")
private List<PostFastApiTodoDto> todoList;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<PostFastApiRecommendDto> recommendationList;
}
Loading

0 comments on commit 8275c3c

Please sign in to comment.