diff --git a/src/main/java/com/hanaro/triptogether/trip/controller/TripController.java b/src/main/java/com/hanaro/triptogether/trip/controller/TripController.java index 12c28fc..3e2afa4 100644 --- a/src/main/java/com/hanaro/triptogether/trip/controller/TripController.java +++ b/src/main/java/com/hanaro/triptogether/trip/controller/TripController.java @@ -1,6 +1,7 @@ package com.hanaro.triptogether.trip.controller; import com.hanaro.triptogether.trip.dto.request.TripReqDto; +import com.hanaro.triptogether.trip.dto.response.TripListResDto; import com.hanaro.triptogether.trip.dto.response.TripResDto; import com.hanaro.triptogether.trip.service.TripService; import lombok.RequiredArgsConstructor; @@ -23,7 +24,7 @@ public TripResDto getTrip(@PathVariable("trip_idx") Long trip_idx) { } @GetMapping("/teams/{team_idx}") - public List getTrips(@PathVariable("team_idx") Long team_idx) { + public TripListResDto getTrips(@PathVariable("team_idx") Long team_idx) { return tripService.getTripsByTeam(team_idx); } diff --git a/src/main/java/com/hanaro/triptogether/trip/dto/response/TripListResDto.java b/src/main/java/com/hanaro/triptogether/trip/dto/response/TripListResDto.java new file mode 100644 index 0000000..3e98b53 --- /dev/null +++ b/src/main/java/com/hanaro/triptogether/trip/dto/response/TripListResDto.java @@ -0,0 +1,13 @@ +package com.hanaro.triptogether.trip.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class TripListResDto { + private Long preferTripIdx; + private List trips; +} diff --git a/src/main/java/com/hanaro/triptogether/trip/service/TripService.java b/src/main/java/com/hanaro/triptogether/trip/service/TripService.java index 50d1f8a..997cdbb 100644 --- a/src/main/java/com/hanaro/triptogether/trip/service/TripService.java +++ b/src/main/java/com/hanaro/triptogether/trip/service/TripService.java @@ -14,6 +14,7 @@ import com.hanaro.triptogether.trip.domain.Trip; import com.hanaro.triptogether.trip.domain.TripRepository; import com.hanaro.triptogether.trip.dto.request.TripReqDto; +import com.hanaro.triptogether.trip.dto.response.TripListResDto; import com.hanaro.triptogether.trip.dto.response.TripResDto; import com.hanaro.triptogether.tripCity.domain.TripCity; import com.hanaro.triptogether.tripCity.domain.TripCityRepository; @@ -50,14 +51,15 @@ public Trip findByTripIdx(Long tripIdx) { return tripRepository.findById(tripIdx).orElseThrow(() -> new ApiException(ExceptionEnum.TRIP_NOT_FOUND)); } - public List getTripsByTeam(Long teamIdx) { - teamService.findTeamByTeamIdx(teamIdx); // 팀 확인 + public TripListResDto getTripsByTeam(Long teamIdx) { + Team team = teamService.findTeamByTeamIdx(teamIdx); // 팀 확인 List trips = tripRepository.findAllByTeam_TeamIdx(teamIdx); List dtos = new ArrayList<>(); for (Trip trip : trips) { dtos.add(toTripResDto(trip)); } - return dtos; + + return TripListResDto.builder().trips(dtos).preferTripIdx(team.getPreferTrip().getTripIdx()).build(); } @Transactional diff --git a/src/test/java/com/hanaro/triptogether/trip/service/TripServiceTest.java b/src/test/java/com/hanaro/triptogether/trip/service/TripServiceTest.java index cbe4523..5c59f31 100644 --- a/src/test/java/com/hanaro/triptogether/trip/service/TripServiceTest.java +++ b/src/test/java/com/hanaro/triptogether/trip/service/TripServiceTest.java @@ -12,6 +12,7 @@ import com.hanaro.triptogether.team.service.impl.TeamServiceImpl; import com.hanaro.triptogether.trip.domain.Trip; import com.hanaro.triptogether.trip.domain.TripRepository; +import com.hanaro.triptogether.trip.dto.response.TripListResDto; import com.hanaro.triptogether.trip.dto.response.TripResDto; import com.hanaro.triptogether.tripCity.domain.TripCity; import com.hanaro.triptogether.tripCity.service.TripCityService; @@ -82,6 +83,7 @@ static void init() { .preferenceType(PreferenceType.모두) .teamNotice("지각비 5만원") .createdBy(member1) + .preferTrip(trip) .build(); country = CountryEntity.builder() .countryIdx(1L) @@ -144,15 +146,25 @@ void getTripsByTeam_success() { given(tripRepository.findAllByTeam_TeamIdx(trip.getTeam().getTeamIdx())).willReturn(List.of(trip, trip2)); given(tripCityService.getTripCountry(trip.getTripIdx())).willReturn(trip.getTripCities()); given(tripCityService.getTripCountry(trip2.getTripIdx())).willReturn(trip2.getTripCities()); + given(teamService.findTeamByTeamIdx(trip.getTeam().getTeamIdx())).willReturn(Team.builder() + .teamIdx(1L) + .teamName("teamName") + .account(mock(Account.class)) + .teamType(TeamType.여행) + .preferenceType(PreferenceType.모두) + .teamNotice("지각비 5만원") + .createdBy(member1) + .preferTrip(trip) + .build()); //when - List dtos = tripService.getTripsByTeam(trip.getTeam().getTeamIdx()); + TripListResDto dto = tripService.getTripsByTeam(trip.getTeam().getTeamIdx()); //then - assertEquals(2, dtos.size()); - assertEquals(trip.getTripIdx(), dtos.get(0).getTripIdx()); - assertEquals(trip2.getTripIdx(), dtos.get(1).getTripIdx()); + assertEquals(2, dto.getTrips().size()); + assertEquals(trip.getTripIdx(), dto.getTrips().get(0).getTripIdx()); + assertEquals(trip2.getTripIdx(), dto.getTrips().get(1).getTripIdx()); } @Test void getTripsByTeam_invalidTeamIdx() {