Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 여행 목록에 선호 여행 번호 추가 #130

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,7 +24,7 @@ public TripResDto getTrip(@PathVariable("trip_idx") Long trip_idx) {
}

@GetMapping("/teams/{team_idx}")
public List<TripResDto> getTrips(@PathVariable("team_idx") Long team_idx) {
public TripListResDto getTrips(@PathVariable("team_idx") Long team_idx) {
return tripService.getTripsByTeam(team_idx);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<TripResDto> trips;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,14 +51,15 @@ public Trip findByTripIdx(Long tripIdx) {
return tripRepository.findById(tripIdx).orElseThrow(() -> new ApiException(ExceptionEnum.TRIP_NOT_FOUND));
}

public List<TripResDto> getTripsByTeam(Long teamIdx) {
teamService.findTeamByTeamIdx(teamIdx); // 팀 확인
public TripListResDto getTripsByTeam(Long teamIdx) {
Team team = teamService.findTeamByTeamIdx(teamIdx); // 팀 확인
List<Trip> trips = tripRepository.findAllByTeam_TeamIdx(teamIdx);
List<TripResDto> dtos = new ArrayList<>();
for (Trip trip : trips) {
dtos.add(toTripResDto(trip));
}
return dtos;

return TripListResDto.builder().trips(dtos).preferTripIdx(team.getPreferTrip().getTripIdx()).build();
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,6 +83,7 @@ static void init() {
.preferenceType(PreferenceType.모두)
.teamNotice("지각비 5만원")
.createdBy(member1)
.preferTrip(trip)
.build();
country = CountryEntity.builder()
.countryIdx(1L)
Expand Down Expand Up @@ -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<TripResDto> 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() {
Expand Down
Loading