11package fitfit .domain .clothes .controller ;
22
3+ import fitfit .domain .clothes .converter .ClothesConverter ;
34import fitfit .domain .clothes .dto .ClothesRequestDTO ;
45import fitfit .domain .clothes .dto .ClothesResponseDTO ;
6+ import fitfit .domain .clothes .entity .Clothes ;
57import fitfit .domain .clothes .service .ClothesCommandService ;
8+ import fitfit .domain .clothes .service .ClothesQueryService ;
9+ import fitfit .domain .search .dto .SearchResponseDTO ;
10+ import fitfit .domain .search .service .SearchCommandService ;
11+ import fitfit .domain .search .service .SearchQueryService ;
612import fitfit .global .apiPayload .ApiResponse ;
713import io .swagger .v3 .oas .annotations .Operation ;
814import io .swagger .v3 .oas .annotations .media .Content ;
1117import io .swagger .v3 .oas .annotations .tags .Tag ;
1218import jakarta .validation .Valid ;
1319import lombok .RequiredArgsConstructor ;
14- import org .springframework .http . MediaType ;
20+ import org .springframework .data . domain . Page ;
1521import org .springframework .web .bind .annotation .*;
1622
1723import java .io .IOException ;
2329public class ClothesRestController {
2430
2531 private final ClothesCommandService clothesCommandService ;
32+ private final ClothesQueryService clothesQueryService ;
33+ private final SearchCommandService searchCommandService ;
34+ private final SearchQueryService searchQueryService ;
2635
2736 @ PostMapping ("/post" )
2837 @ Operation (summary = "판매 옷 등록 API" , description = "자신이 판매할 옷의 정보를 등록하는 API입니다. 이미지는 Base64 인코딩된 문자열로 보내주세요." )
@@ -41,4 +50,62 @@ public ApiResponse<ClothesResponseDTO.CreateClothesResponse> registerClothes(
4150 ClothesResponseDTO .CreateClothesResponse response = clothesCommandService .createClothes (authorization , requestDto );
4251 return ApiResponse .onSuccess (response );
4352 }
53+
54+ @ GetMapping ("/search" )
55+ @ Operation (summary = "판매 옷 일반 검색 API" , description = """
56+ 키워드 검색을 통해 판매 옷 정보를 가져오는 API입니다. (존재하지 않는 키워드인 경우 빈 리스트로 응답)
57+ **페이지네이션(Pagination) 설명:**
58+ - `page` 파라미터는 요청할 페이지 번호입니다 (0부터 시작).
59+ - `size` 파라미터는 한 페이지에 가져올 아이템 개수입니다 (기본값은 백엔드에서 설정).
60+ - 응답은 `ClothesPageDTO` 형식으로 반환됩니다.
61+ - `clothesList`: 현재 페이지에 해당하는 옷 데이터 목록입니다.
62+ - `listSize`: 현재 페이지의 아이템 수입니다.
63+ - `totalPage`: 전체 페이지 수입니다.
64+ - `totalElements`: 전체 아이템 수입니다.
65+ - `isFirst`: 현재 페이지가 첫 페이지인지 여부입니다. (true/false)
66+ - `isLast`: 현재 페이지가 마지막 페이지인지 여부입니다. (true/false)
67+ """ )
68+ @ ApiResponses ({
69+ @ io .swagger .v3 .oas .annotations .responses .ApiResponse (responseCode = "200" , description = "OK, 성공" ),
70+ @ io .swagger .v3 .oas .annotations .responses .ApiResponse (responseCode = "400" , description = "Bad Request, 잘못된 요청 형식" , content = @ Content (schema = @ Schema (implementation = ApiResponse .class ))),
71+ @ io .swagger .v3 .oas .annotations .responses .ApiResponse (responseCode = "401" , description = "Unauthorized, 유효하지 않은 토큰" , content = @ Content (schema = @ Schema (implementation = ApiResponse .class )))
72+ })
73+ public ApiResponse <ClothesResponseDTO .ClothesPageDTO > searchClothes (
74+ @ RequestHeader (value = "Authorization" ) String authorization ,
75+ @ RequestParam (name = "keyword" ) String keyword , // 검색할 키워드를 요청 파라미터로 받음
76+ @ RequestParam (name = "page" ) Integer page // 페이지 번호를 요청 파라미터로 받음
77+ ) {
78+ searchCommandService .createSearchRecord (keyword , authorization );
79+ // 키워드와 페이지 번호로 옷을 검색
80+ Page <Clothes > clothesPage = clothesQueryService .findClothesByKeyword (keyword , page );
81+ // 검색 결과를 DTO로 변환하여 성공 응답 반환
82+ return ApiResponse .onSuccess (ClothesConverter .toClothesPageDTO (clothesPage ));
83+ }
84+
85+ @ GetMapping ("/search-record" )
86+ @ Operation (summary = "최근 검색어 조회 API" , description = """
87+ 최근 검색어 목록을 최신순으로 조회하는 API입니다.
88+ **페이지네이션(Pagination) 설명:**
89+ - `page` 파라미터는 요청할 페이지 번호입니다 (0부터 시작).
90+ - `size` 파라미터는 한 페이지에 가져올 아이템 개수입니다 (기본값은 백엔드에서 설정).
91+ - 응답은 `SearchRecordPageDTO` 형식으로 반환됩니다.
92+ - `searchRecordList`: 현재 페이지에 해당하는 검색 기록 데이터 목록입니다.
93+ - `listSize`: 현재 페이지의 아이템 수입니다.
94+ - `totalPage`: 전체 페이지 수입니다.
95+ - `totalElements`: 전체 아이템 수입니다.
96+ - `isFirst`: 현재 페이지가 첫 페이지인지 여부입니다. (true/false)
97+ - `isLast`: 현재 페이지가 마지막 페이지인지 여부입니다. (true/false)
98+ """ )
99+ @ ApiResponses ({
100+ @ io .swagger .v3 .oas .annotations .responses .ApiResponse (responseCode = "200" , description = "OK, 성공" ),
101+ @ io .swagger .v3 .oas .annotations .responses .ApiResponse (responseCode = "401" , description = "Unauthorized, 유효하지 않은 토큰" , content = @ Content (schema = @ Schema (implementation = ApiResponse .class ))),
102+ @ io .swagger .v3 .oas .annotations .responses .ApiResponse (responseCode = "404" , description = "Not Found, 존재하지 않는 회원" , content = @ Content (schema = @ Schema (implementation = ApiResponse .class )))
103+ })
104+ public ApiResponse <SearchResponseDTO .SearchRecordPageDTO > getSearchRecord (
105+ @ RequestHeader (value = "Authorization" ) String authorization ,
106+ @ RequestParam (name = "page" ) Integer page
107+ ) {
108+ SearchResponseDTO .SearchRecordPageDTO response = searchQueryService .getSearchRecord (authorization , page );
109+ return ApiResponse .onSuccess (response );
110+ }
44111}
0 commit comments