|
1 | 1 | package DiffLens.back_end.domain.library.controller; |
2 | 2 |
|
| 3 | +import DiffLens.back_end.domain.library.dto.LibraryRequestDto; |
3 | 4 | import DiffLens.back_end.domain.library.dto.LibraryResponseDTO; |
| 5 | +import DiffLens.back_end.domain.library.service.LibraryService; |
| 6 | +import DiffLens.back_end.domain.members.entity.Member; |
| 7 | +import DiffLens.back_end.domain.members.service.auth.CurrentUserService; |
4 | 8 | import DiffLens.back_end.global.responses.exception.ApiResponse; |
5 | 9 | import io.swagger.v3.oas.annotations.Operation; |
6 | 10 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 11 | +import jakarta.validation.Valid; |
7 | 12 | import lombok.RequiredArgsConstructor; |
8 | | -import org.springframework.web.bind.annotation.GetMapping; |
9 | | -import org.springframework.web.bind.annotation.RequestMapping; |
10 | | -import org.springframework.web.bind.annotation.RestController; |
| 13 | +import org.springframework.web.bind.annotation.*; |
11 | 14 |
|
12 | 15 | @Tag(name = "라이브러리 API") |
13 | 16 | @RestController |
14 | 17 | @RequestMapping("/libraries") |
15 | 18 | @RequiredArgsConstructor |
16 | 19 | public class LibraryController { |
17 | 20 |
|
18 | | - @GetMapping |
19 | | - @Operation(summary = "라이브러리 목록 조회 ( 미구현 )") |
20 | | - public ApiResponse<LibraryResponseDTO.ListResult> libraryList( /* 파라미터 추가 필요 */ ){ |
21 | | - LibraryResponseDTO.ListResult result = new LibraryResponseDTO.ListResult(); |
22 | | - return ApiResponse.onSuccess(result); |
23 | | - } |
| 21 | + private final LibraryService libraryService; |
| 22 | + private final CurrentUserService currentUserService; |
24 | 23 |
|
| 24 | + @GetMapping |
| 25 | + @Operation(summary = "라이브러리 목록 조회", description = """ |
| 26 | +
|
| 27 | + ## 개요 |
| 28 | + 인증된 사용자가 생성한 라이브러리 목록을 조회하는 API입니다. |
| 29 | +
|
| 30 | + ## 응답 |
| 31 | + - libraries : 라이브러리 목록 배열 |
| 32 | + - library_id : 라이브러리 ID |
| 33 | + - library_name : 라이브러리 이름 |
| 34 | + - tags : 라이브러리 분류 태그 리스트 |
| 35 | + - panel_count : 저장된 패널 개수 |
| 36 | + - created_at : 생성 시간 |
| 37 | + - page_info : 페이징 정보 (현재는 null, 추후 구현 예정) |
| 38 | +
|
| 39 | + ## 권한 |
| 40 | + 본인이 생성한 라이브러리만 조회할 수 있습니다. |
| 41 | +
|
| 42 | + ## 정렬 |
| 43 | + 최근 생성된 순서로 정렬됩니다. |
| 44 | +
|
| 45 | + """) |
| 46 | + public ApiResponse<LibraryResponseDTO.ListResult> libraryList() { |
| 47 | + Member member = currentUserService.getCurrentUser(); |
| 48 | + LibraryResponseDTO.ListResult result = libraryService.getLibrariesByMember(member); |
| 49 | + return ApiResponse.onSuccess(result); |
| 50 | + } |
| 51 | + |
| 52 | + @PostMapping |
| 53 | + @Operation(summary = "라이브러리 생성", description = """ |
| 54 | +
|
| 55 | + ## 개요 |
| 56 | + 검색 기록을 기반으로 라이브러리를 생성하는 API입니다. |
| 57 | +
|
| 58 | + ## Request Body |
| 59 | + - search_history_id : 저장할 검색 기록의 ID (필수) |
| 60 | + - library_name : 라이브러리 이름 (필수) |
| 61 | + - tags : 라이브러리 분류 태그 리스트 (필수) |
| 62 | + - panel_ids : 저장할 패널 ID 리스트 (선택, null이면 검색 기록의 모든 패널 저장) |
| 63 | +
|
| 64 | + ## 응답 |
| 65 | + - library_id : 생성된 라이브러리 ID |
| 66 | + - library_name : 라이브러리 이름 |
| 67 | + - search_history_id : 연결된 검색 기록 ID |
| 68 | + - panel_count : 저장된 패널 개수 |
| 69 | + - created_at : 생성 시간 |
| 70 | +
|
| 71 | + ## 권한 |
| 72 | + 본인의 검색 기록만 라이브러리로 저장할 수 있습니다. |
| 73 | +
|
| 74 | + """) |
| 75 | + public ApiResponse<LibraryResponseDTO.CreateResult> createLibrary( |
| 76 | + @RequestBody @Valid LibraryRequestDto.Create request) { |
| 77 | + Member member = currentUserService.getCurrentUser(); |
| 78 | + LibraryService.LibraryCreateResult createResult = libraryService.createLibrary(request, member); |
| 79 | + |
| 80 | + LibraryResponseDTO.CreateResult result = LibraryResponseDTO.CreateResult.from( |
| 81 | + createResult.getLibrary(), |
| 82 | + request.getSearchHistoryId(), |
| 83 | + createResult.getPanelCount()); |
| 84 | + return ApiResponse.onSuccess(result); |
| 85 | + } |
| 86 | + |
| 87 | + @GetMapping("/{libraryId}") |
| 88 | + @Operation(summary = "특정 라이브러리 상세 조회", description = """ |
| 89 | + ## 개요 |
| 90 | + 특정 라이브러리의 상세 정보를 조회하는 API입니다. |
| 91 | +
|
| 92 | + ## Path Parameters |
| 93 | + - libraryId : 조회할 라이브러리 ID |
| 94 | +
|
| 95 | + ## 응답 데이터 |
| 96 | + - 라이브러리 기본 정보 (이름, 태그, 생성일, 수정일) |
| 97 | + - 포함된 패널들의 상세 정보 |
| 98 | + - 연결된 검색기록들 -> 혹시 몰라 추가한 로직으로 필요 없다고 판단될 시 안쓰셔도 됩니다. |
| 99 | + - 패널 통계 정보 (성별, 연령대, 거주지 분포) -> 혹시 몰라 추가한 로직으로 필요 없다고 판단될 시 안쓰셔도 됩니다. |
| 100 | +
|
| 101 | + ## 권한 |
| 102 | + 본인이 생성한 라이브러리만 조회할 수 있습니다. |
| 103 | + """) |
| 104 | + public ApiResponse<LibraryResponseDTO.LibraryDetail> getLibraryDetail(@PathVariable Long libraryId) { |
| 105 | + Member member = currentUserService.getCurrentUser(); |
| 106 | + LibraryResponseDTO.LibraryDetail result = libraryService.getLibraryDetail(libraryId, member); |
| 107 | + return ApiResponse.onSuccess(result); |
| 108 | + } |
| 109 | + |
| 110 | + @PutMapping("/{libraryId}/search-histories/{searchHistoryId}") |
| 111 | + @Operation(summary = "기존 라이브러리에 새로운 검색기록 추가(병합)", description = """ |
| 112 | +
|
| 113 | + ## 개요 |
| 114 | + 기존 라이브러리에 검색기록을 추가하는 API입니다. |
| 115 | + 라이브러리의 패널 ID와 검색기록의 패널 ID를 병합하여 중복을 제거합니다. |
| 116 | +
|
| 117 | + ## Path Parameters |
| 118 | + - libraryId : 라이브러리 ID |
| 119 | + - searchHistoryId : 추가할 검색기록 ID |
| 120 | +
|
| 121 | + ## 응답 |
| 122 | + - library_id : 라이브러리 ID |
| 123 | + - library_name : 라이브러리 이름 |
| 124 | + - search_history_id : 추가된 검색기록 ID |
| 125 | + - panel_count : 새로 추가된 패널 개수 |
| 126 | + - panel_ids : 병합된 전체 패널 ID 리스트 |
| 127 | + - created_at : 생성 시간 |
| 128 | +
|
| 129 | + ## 권한 |
| 130 | + 본인의 라이브러리와 검색기록만 사용할 수 있습니다. |
| 131 | +
|
| 132 | + ## 예시 |
| 133 | + - 라이브러리 1번에 패널 ID [1, 2, 3]이 있음 |
| 134 | + - 검색기록 2번에 패널 ID [3, 4, 5]가 있음 |
| 135 | + - 결과: 라이브러리 1번에 패널 ID [1, 2, 3, 4, 5]가 됨 |
| 136 | +
|
| 137 | + """) |
| 138 | + public ApiResponse<LibraryResponseDTO.CreateResult> addSearchHistoryToLibrary( |
| 139 | + @PathVariable Long libraryId, |
| 140 | + @PathVariable Long searchHistoryId) { |
| 141 | + Member member = currentUserService.getCurrentUser(); |
| 142 | + LibraryService.LibraryCreateResult createResult = libraryService.addSearchHistoryToLibrary(libraryId, |
| 143 | + searchHistoryId, member); |
| 144 | + |
| 145 | + LibraryResponseDTO.CreateResult result = LibraryResponseDTO.CreateResult.from( |
| 146 | + createResult.getLibrary(), |
| 147 | + searchHistoryId, |
| 148 | + createResult.getPanelCount()); |
| 149 | + return ApiResponse.onSuccess(result); |
| 150 | + } |
25 | 151 | } |
0 commit comments