Skip to content

Commit

Permalink
fix: trip-place에서 city와 country미존재시 리턴 안되는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mummhy0811 committed Jun 5, 2024
1 parent 6011eff commit 450babe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public Trip findByTripIdx(Long tripIdx) {

public List<TripResDto> getTripsByTeam(Long teamIdx) {
teamService.findTeamByTeamIdx(teamIdx); // 팀 확인
System.out.println("팀 존재~~");
List<Trip> trips = tripRepository.findAllByTeam_TeamIdx(teamIdx);
System.out.println("여행 사이즈~~"+trips.size());
List<TripResDto> dtos = new ArrayList<>();
for (Trip trip : trips) {
dtos.add(toTripResDto(trip));
Expand Down Expand Up @@ -133,6 +135,18 @@ public void deleteTrip(Long tripIdx) throws NoSuchElementException{

private TripResDto toTripResDto(Trip trip) {
List<TripCity> tripCities = tripCityService.getTripCountry(trip.getTripIdx());
if(tripCities.isEmpty() || tripCities.get(0).getCity()==null || tripCities.get(0).getCity().getCountry()==null) {
return TripResDto.builder()
.teamIdx(trip.getTeam().getTeamIdx())
.teamName(trip.getTeam().getTeamName())
.tripIdx(trip.getTripIdx())
.tripDay(trip.getTripDay())
.tripContent(trip.getTripContent())
.tripGoalAmount(trip.getTripGoalAmount())
.tripName(trip.getTripName())
.tripStartDay(trip.getTripStartDay())
.build();
}
List<City> cities = tripCities.stream().map(tripCity -> tripCity.getCity().toCity()).toList();
CountryEntity country = tripCities.get(0).getCity().getCountry();
return TripResDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class TripCity {
private Trip trip;

@ManyToOne
@JoinColumn(name = "city_idx", nullable = false)
@JoinColumn(name = "city_idx")
private CityEntity city;

@ManyToOne
Expand Down

0 comments on commit 450babe

Please sign in to comment.