Skip to content

Commit

Permalink
[refactor] Trip 전체 조회 api QueryString 방식으로 수정 (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
Combi153 committed Sep 20, 2023
1 parent b1dd885 commit 7006c6d
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@
import dev.tripdraw.common.auth.LoginUser;
import dev.tripdraw.member.domain.Member;
import dev.tripdraw.member.domain.MemberRepository;
import dev.tripdraw.trip.domain.*;
import dev.tripdraw.trip.dto.*;
import dev.tripdraw.trip.domain.Point;
import dev.tripdraw.trip.domain.PointRepository;
import dev.tripdraw.trip.domain.Trip;
import dev.tripdraw.trip.domain.TripRepository;
import dev.tripdraw.trip.domain.TripUpdateEvent;
import dev.tripdraw.trip.dto.PointCreateRequest;
import dev.tripdraw.trip.dto.PointCreateResponse;
import dev.tripdraw.trip.dto.PointResponse;
import dev.tripdraw.trip.dto.TripCreateResponse;
import dev.tripdraw.trip.dto.TripResponse;
import dev.tripdraw.trip.dto.TripSearchConditions;
import dev.tripdraw.trip.dto.TripSearchRequest;
import dev.tripdraw.trip.dto.TripUpdateRequest;
import dev.tripdraw.trip.dto.TripsSearchResponse;
import dev.tripdraw.trip.dto.TripsSearchResponseOfMember;
import dev.tripdraw.trip.query.TripPaging;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RequiredArgsConstructor
@Transactional
@Service
Expand Down Expand Up @@ -71,7 +83,7 @@ public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) {

@Transactional(readOnly = true)
public TripsSearchResponse readAll(TripSearchRequest tripSearchRequest) {
TripSearchConditions condition = tripSearchRequest.condition();
TripSearchConditions condition = tripSearchRequest.toTripSearchConditions();
TripPaging tripPaging = tripSearchRequest.toTripPaging();

List<Trip> trips = tripQueryService.readAllByQueryConditions(condition, tripPaging);
Expand Down
27 changes: 23 additions & 4 deletions backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
package dev.tripdraw.trip.dto;

import dev.tripdraw.trip.query.TripPaging;
import java.util.Set;
import lombok.Builder;

@Builder
public record TripSearchRequest(

TripSearchConditions condition,
TripSearchPaging paging
Set<Integer> years,
Set<Integer> months,
Set<Integer> daysOfWeek,
Set<Integer> ageRanges,
Set<Integer> genders,
String address,
Long lastViewedId,
Integer limit
) {

public TripSearchConditions toTripSearchConditions() {
return TripSearchConditions.builder()
.years(years)
.months(months)
.daysOfWeek(daysOfWeek)
.ageRanges(ageRanges)
.genders(genders)
.address(address)
.build();
}

public TripPaging toTripPaging() {
return paging.toTripPaging();
return new TripPaging(lastViewedId, limit);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package dev.tripdraw.trip.presentation;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;

import dev.tripdraw.common.auth.Auth;
import dev.tripdraw.common.auth.LoginUser;
import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired;
import dev.tripdraw.trip.application.TripService;
import dev.tripdraw.trip.dto.*;
import dev.tripdraw.trip.dto.PointCreateRequest;
import dev.tripdraw.trip.dto.PointCreateResponse;
import dev.tripdraw.trip.dto.PointResponse;
import dev.tripdraw.trip.dto.TripCreateResponse;
import dev.tripdraw.trip.dto.TripResponse;
import dev.tripdraw.trip.dto.TripSearchRequest;
import dev.tripdraw.trip.dto.TripUpdateRequest;
import dev.tripdraw.trip.dto.TripsSearchResponse;
import dev.tripdraw.trip.dto.TripsSearchResponseOfMember;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Trip", description = "여행 관련 API 명세")
@SwaggerAuthorizationRequired
Expand Down Expand Up @@ -108,7 +123,7 @@ public ResponseEntity<TripsSearchResponseOfMember> readAllOf(@Auth LoginUser log
@GetMapping("/trips")
public ResponseEntity<TripsSearchResponse> readAll(
@Auth LoginUser loginUser,
@RequestBody TripSearchRequest tripSearchRequest
TripSearchRequest tripSearchRequest
) {
TripsSearchResponse response = tripService.readAll(tripSearchRequest);
return ResponseEntity.ok(response);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dev.tripdraw.test.fixture;

import java.util.Map;
import java.util.Set;

public class TripSearchQueryParamsFixture {

public static Map<String, Object> limitParams(int limit) {
return Map.of("limit", limit);
}

public static Map<String, Object> lastViewedIdAndLimitParams(Long lastViewedId, int limit) {
return Map.of(
"lastViewedId", lastViewedId,
"limit", limit
);
}

public static Map<String, Object> yearsAndLimitParams(Set<Integer> years, int limit) {
return Map.of(
"years", years,
"limit", limit
);
}

public static Map<String, Object> monthsAndLimitParams(Set<Integer> months, int limit) {
return Map.of(
"months", months,
"limit", limit
);
}

public static Map<String, Object> daysOfWeekAndLimitParams(Set<Integer> daysOfWeek, int limit) {
return Map.of(
"daysOfWeek", daysOfWeek,
"limit", limit
);
}

public static Map<String, Object> ageRangesAndLimitParams(Set<Integer> ageRanges, int limit) {
return Map.of(
"ageRanges", ageRanges,
"limit", limit
);
}

public static Map<String, Object> gendersAndLimitParams(Set<Integer> genders, int limit) {
return Map.of(
"genders", genders,
"limit", limit
);
}

public static Map<String, Object> addressAndLimitParams(String address, int limit) {
return Map.of(
"address", address,
"limit", limit
);
}
}
Loading

0 comments on commit 7006c6d

Please sign in to comment.