Skip to content

Commit

Permalink
fix: song, singer 검색 조건 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
somsom13 committed Oct 19, 2023
1 parent 626b645 commit 73c0091
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 49 deletions.
21 changes: 7 additions & 14 deletions backend/src/main/java/shook/shook/song/ui/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import shook.shook.song.application.ArtistSearchService;
import shook.shook.song.application.dto.ArtistResponse;
import shook.shook.song.application.dto.ArtistWithSongSearchResponse;
import shook.shook.song.ui.openapi.SearchApi;

@RequiredArgsConstructor
Expand All @@ -19,18 +17,13 @@ public class SearchController implements SearchApi {

private final ArtistSearchService artistSearchService;

@GetMapping(params = {"keyword", "type=singer,song"})
public ResponseEntity<List<ArtistWithSongSearchResponse>> searchArtistWithSongByKeyword(
@RequestParam(name = "type") final List<String> types,
@RequestParam(name = "keyword") final String keyword) {
return ResponseEntity.ok(artistSearchService.searchArtistsAndTopSongsByKeyword(keyword));
}

@GetMapping(params = {"keyword", "type=singer"})
public ResponseEntity<List<ArtistResponse>> searchArtistByKeyword(
@RequestParam(name = "type") final String type,
@RequestParam(name = "keyword") final String keyword) {
@GetMapping
public ResponseEntity<List<?>> search(@RequestParam(name = "type") final List<String> types,
@RequestParam(name = "keyword") final String keyword) {
if (types.containsAll(List.of("song", "singer"))) {
return ResponseEntity.ok(artistSearchService.searchArtistsAndTopSongsByKeyword(keyword));
}
return ResponseEntity.ok(artistSearchService.searchArtistsByKeyword(keyword));
}

// TODO: 2023-10-19 리팩터링: 검색 타입 enum 생성
}
49 changes: 14 additions & 35 deletions backend/src/main/java/shook/shook/song/ui/openapi/SearchApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,37 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import shook.shook.song.application.dto.ArtistResponse;
import shook.shook.song.application.dto.ArtistWithSongSearchResponse;

@Tag(name = "Singer Search", description = "가수 이름 검색 API")
@Tag(name = "Search", description = "검색 API")
public interface SearchApi {

@Operation(
summary = "검색어 입력 시 자동 완성되는 가수의 정보 검색",
description = "검색어 입력 시, 검색어로 시작하는 가수의 정보를 검색한다."
summary = "가수, 또는 가수와 노래 조회",
description = "가수를 가나다 순으로 조회한다."
)
@ApiResponse(
responseCode = "200",
description = "가수 검색 성공"
description = "가수 정보, (노래 목록) 검색 성공"
)
@GetMapping(value = "?type=singer", params = {"keyword"})
ResponseEntity<List<ArtistResponse>> searchArtistByKeyword(
@Parameter(name = "type", description = "검색 타입",
schema = @Schema(enumAsRef = true, allowableValues = {"singer"}))
@RequestParam(name = "type") final String type,
@Parameter(
name = "keyword",
description = "검색할 가수 키워드",
required = true
)
@RequestParam(name = "keyword") final String keyword
);

@Operation(
summary = "검색 시, 검색 결과 조회",
description = "검색 시, 검색어로 시작하거나 끝나는 가수와 해당 가수의 TOP3 노래가 조회된다."
@Parameter(
name = "type",
description = "검색 타입, singer&song OR singer",
required = true
)
@ApiResponse(
responseCode = "200",
description = "가수, TOP3 노래 검색 성공"
@Parameter(
name = "keyword",
description = "검색 키워드",
required = true
)
@GetMapping(value = "?type=singer,song", params = {"keyword"})
ResponseEntity<List<ArtistWithSongSearchResponse>> searchArtistWithSongByKeyword(
@Parameter(name = "type", description = "검색 타입",
schema = @Schema(enumAsRef = true, allowableValues = {"singer", "song"}))
@GetMapping("")
ResponseEntity<List<?>> search(
@RequestParam(name = "type") final List<String> types,
@Parameter(
name = "keyword",
description = "검색할 가수 키워드",
required = true
)
@RequestParam(name = "keyword") final String keyword
);
}

0 comments on commit 73c0091

Please sign in to comment.