From 318a09ad7b47a9f50cd76cdf0382c49613a5e5e9 Mon Sep 17 00:00:00 2001 From: daeun084 <030804jk@naver.com> Date: Tue, 30 Jul 2024 14:03:23 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=ED=99=88=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20Response=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makar/dev/converter/UserConverter.java | 36 +++++++++---------- .../makar/dev/dto/response/UserResponse.java | 8 ++--- .../java/makar/dev/service/NotiService.java | 2 +- .../java/makar/dev/service/UserService.java | 19 +++++----- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/main/java/makar/dev/converter/UserConverter.java b/src/main/java/makar/dev/converter/UserConverter.java index 3a821ca..cd0acae 100644 --- a/src/main/java/makar/dev/converter/UserConverter.java +++ b/src/main/java/makar/dev/converter/UserConverter.java @@ -10,29 +10,27 @@ public class UserConverter { - public static UserResponse.HomeDto toHomeDto(boolean isRouteSet, List notiList){ - - if (notiList.isEmpty()) - return UserResponse.HomeDto.builder() - .isRouteSet(isRouteSet) - .sourceStationName(null) - .destinationStationName(null) - .makarTime(null) - .getoffTime(null) - .notiList(null) - .build(); - - Route route = notiList.get(0).getRoute(); - List notiDtoList = notiList.stream() - .map(NotiConverter::toNotiDto) - .toList(); + public static UserResponse.HomeDto toRouteSetHomeDto(NotiResponse.NotiListDto notiListDto, Route route){ return UserResponse.HomeDto.builder() - .isRouteSet(isRouteSet) + .isRouteSet(true) .sourceStationName(route.getSourceStation().getStationName()) .destinationStationName(route.getDestinationStation().getStationName()) .makarTime(route.getSchedule().getSourceTime()) - .getoffTime(route.getSchedule().getDestinationTime()) - .notiList(notiDtoList) + .getOffTime(route.getSchedule().getDestinationTime()) + .makarNotiList(notiListDto.getMakarNotiDtoList()) + .getOffNotiList(notiListDto.getGetoffNotiDtoList()) + .build(); + } + + public static UserResponse.HomeDto toRouteUnSetHomeDto(){ + return UserResponse.HomeDto.builder() + .isRouteSet(false) + .sourceStationName(null) + .destinationStationName(null) + .makarTime(null) + .getOffTime(null) + .makarNotiList(null) + .getOffNotiList(null) .build(); } diff --git a/src/main/java/makar/dev/dto/response/UserResponse.java b/src/main/java/makar/dev/dto/response/UserResponse.java index 1aae188..24a1602 100644 --- a/src/main/java/makar/dev/dto/response/UserResponse.java +++ b/src/main/java/makar/dev/dto/response/UserResponse.java @@ -4,7 +4,6 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import makar.dev.domain.Noti; import java.util.List; @@ -19,9 +18,8 @@ public static class HomeDto { private String sourceStationName; private String destinationStationName; private String makarTime; - private String getoffTime; - private List notiList; - private List favoriteRouteList; - private List recentRouteList; + private String getOffTime; + private List makarNotiList; + private List getOffNotiList; } } diff --git a/src/main/java/makar/dev/service/NotiService.java b/src/main/java/makar/dev/service/NotiService.java index bd952d9..39d8ebd 100644 --- a/src/main/java/makar/dev/service/NotiService.java +++ b/src/main/java/makar/dev/service/NotiService.java @@ -88,7 +88,7 @@ public NotiResponse.NotiListDto deleteNoti(Long notiId, TokenDto tokenDto, Notif return separateNotiList(user.getNotiList()); } - private NotiResponse.NotiListDto separateNotiList(List notiList){ + public NotiResponse.NotiListDto separateNotiList(List notiList){ List makarNotiList = new ArrayList<>(); List getoffNotiList = new ArrayList<>(); diff --git a/src/main/java/makar/dev/service/UserService.java b/src/main/java/makar/dev/service/UserService.java index e344d96..eb59ad4 100644 --- a/src/main/java/makar/dev/service/UserService.java +++ b/src/main/java/makar/dev/service/UserService.java @@ -8,6 +8,7 @@ import makar.dev.domain.Noti; import makar.dev.domain.Route; import makar.dev.domain.User; +import makar.dev.dto.response.NotiResponse; import makar.dev.dto.response.UserResponse; import makar.dev.manager.DataManager; import makar.dev.repository.UserRepository; @@ -21,6 +22,7 @@ @RequiredArgsConstructor public class UserService { private final UserRepository userRepository; + private final NotiService notiService; private final DataManager dataManager; @Transactional @@ -66,9 +68,16 @@ public User createUser(String id, String password, String email, String username // 홈 화면 조회 public UserResponse.HomeDto getHome(TokenDto tokenDto) { User user = findUserById(tokenDto.getUserId()); - boolean isRouteSet = isRouteSet(user); + List notiList = user.getNotiList(); + + // 경로 미설정 ver. + if (notiList.isEmpty()) + return UserConverter.toRouteUnSetHomeDto(); - return UserConverter.toHomeDto(isRouteSet, user.getNotiList()); + // 경로 설정 ver. + NotiResponse.NotiListDto notiListDto = notiService.separateNotiList(notiList); + Route route = notiList.get(0).getRoute(); + return UserConverter.toRouteSetHomeDto(notiListDto, route); } public User findUserById(Long userId){ @@ -76,10 +85,4 @@ public User findUserById(Long userId){ .orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_USER)); } - private boolean isRouteSet(User user){ - List notiList = user.getNotiList(); - return !notiList.isEmpty(); - } - - }