Skip to content

Commit

Permalink
Merge pull request #48 from MAKAR-iOS/chore/#47
Browse files Browse the repository at this point in the history
[Chore/#47] 홈 화면 조회 API Response 수정
  • Loading branch information
daeun084 authored Jul 30, 2024
2 parents a43fb7d + 318a09a commit 722049d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
36 changes: 17 additions & 19 deletions src/main/java/makar/dev/converter/UserConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@

public class UserConverter {

public static UserResponse.HomeDto toHomeDto(boolean isRouteSet, List<Noti> 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<NotiResponse.NotiDto> 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();
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/makar/dev/dto/response/UserResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import makar.dev.domain.Noti;

import java.util.List;

Expand All @@ -19,9 +18,8 @@ public static class HomeDto {
private String sourceStationName;
private String destinationStationName;
private String makarTime;
private String getoffTime;
private List<NotiResponse.NotiDto> notiList;
private List<RouteResponse.BriefRouteDto> favoriteRouteList;
private List<RouteResponse.BriefRouteDto> recentRouteList;
private String getOffTime;
private List<NotiResponse.NotiDto> makarNotiList;
private List<NotiResponse.NotiDto> getOffNotiList;
}
}
2 changes: 1 addition & 1 deletion src/main/java/makar/dev/service/NotiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public NotiResponse.NotiListDto deleteNoti(Long notiId, TokenDto tokenDto, Notif
return separateNotiList(user.getNotiList());
}

private NotiResponse.NotiListDto separateNotiList(List<Noti> notiList){
public NotiResponse.NotiListDto separateNotiList(List<Noti> notiList){
List<Noti> makarNotiList = new ArrayList<>();
List<Noti> getoffNotiList = new ArrayList<>();

Expand Down
19 changes: 11 additions & 8 deletions src/main/java/makar/dev/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,7 @@
@RequiredArgsConstructor
public class UserService {
private final UserRepository userRepository;
private final NotiService notiService;
private final DataManager dataManager;

@Transactional
Expand Down Expand Up @@ -66,20 +68,21 @@ 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<Noti> 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){
return userRepository.findById(userId)
.orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_USER));
}

private boolean isRouteSet(User user){
List<Noti> notiList = user.getNotiList();
return !notiList.isEmpty();
}


}

0 comments on commit 722049d

Please sign in to comment.