Skip to content
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
Expand Up @@ -29,13 +29,13 @@ public ResponseEntity<ApiResponse<List<SearchCryptoResponse>>> searchByKeyword(@
}

@Override
@GetMapping("/{id}")
public ResponseEntity<ApiResponse<SearchCryptoResponse>> findById(@PathVariable(value = "id") Long id) {
if (ObjectUtils.isEmpty(id)) {
throw new CustomException(ErrorCode.INVALID_INPUT_VALUE, "코인 ID가 필요합니다.");
@GetMapping("/{ticker}")
public ResponseEntity<ApiResponse<SearchCryptoResponse>> findByTicker(@PathVariable(value = "ticker") String ticker) {
if (ObjectUtils.isEmpty(ticker)) {
throw new CustomException(ErrorCode.INVALID_INPUT_VALUE, "코인 티커가 필요합니다.");
}

Crypto crypto = searchCryptoUsecase.findById(id)
Crypto crypto = searchCryptoUsecase.findByTicker(ticker)
.orElseThrow(() -> new CustomException(ErrorCode.CRYPTO_NOT_FOUND));

return ResponseEntity.ok(ApiResponse.success(SearchCryptoResponse.of(crypto)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ public interface SearchCryptoControllerSwagger {
"success": true,
"data": [
{
"id": 1,
"ticker": "BTC",
"name": "비트코인",
"logoUrl": "https://example.com/btc.png",
"currentPrice": 135000000.0,
"tradingVolume": 500000000000.0
},
{
"id": 2,
"ticker": "BCH",
"name": "비트코인캐시",
"logoUrl": "https://example.com/bch.png",
Expand Down Expand Up @@ -99,10 +97,12 @@ ResponseEntity<ApiResponse<List<SearchCryptoResponse>>> searchByKeyword(
@Operation(
summary = "코인 상세 조회",
description = """
코인 ID를 기반으로 암호화폐 상세 정보를 조회합니다.
코인 티커를 기반으로 암호화폐 상세 정보를 조회합니다.

- 코인의 현재가, 거래대금 등 상세 정보를 제공합니다.
- 존재하지 않는 ID로 조회 시 404 에러가 반환됩니다.
- 존재하지 않는 티커로 조회 시 404 에러가 반환됩니다.

**티커 예시:** BTC, ETH, XRP, SOL 등
"""
)
@ApiResponses(value = {
Expand All @@ -118,7 +118,6 @@ ResponseEntity<ApiResponse<List<SearchCryptoResponse>>> searchByKeyword(
{
"success": true,
"data": {
"id": 1,
"ticker": "BTC",
"name": "비트코인",
"logoUrl": "https://example.com/btc.png",
Expand All @@ -133,18 +132,18 @@ ResponseEntity<ApiResponse<List<SearchCryptoResponse>>> searchByKeyword(
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "400",
description = "잘못된 요청 (ID 누락)",
description = "잘못된 요청 (티커 누락)",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(
name = "ID 누락 오류",
name = "티커 누락 오류",
value = """
{
"success": false,
"data": null,
"error": {
"code": "INVALID_INPUT_VALUE",
"message": "코인 ID가 필요합니다."
"message": "코인 티커가 필요합니다."
}
}
"""
Expand Down Expand Up @@ -172,11 +171,11 @@ ResponseEntity<ApiResponse<List<SearchCryptoResponse>>> searchByKeyword(
)
)
})
ResponseEntity<ApiResponse<SearchCryptoResponse>> findById(
ResponseEntity<ApiResponse<SearchCryptoResponse>> findByTicker(
@Parameter(
name = "id",
description = "코인 고유 ID",
name = "ticker",
description = "코인 티커 (심볼)",
required = true,
example = "1"
) Long id);
example = "BTC"
) String ticker);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public List<Crypto> searchByKeyword(String keyword) {
}

@Override
public Optional<Crypto> findById(Long id) {
return cryptoRepository.findById(id);
public Optional<Crypto> findByTicker(String ticker) {
return cryptoRepository.findById(ticker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
public interface SearchCryptoUsecase {
List<Crypto> searchByKeyword(String keyword);

Optional<Crypto> findById(Long id);
Optional<Crypto> findByTicker(String ticker);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

public interface SearchCryptoPort {
List<Crypto> searchByKeyword(String keyword);
Optional<Crypto> findById(Long id);
Optional<Crypto> findByTicker(String ticker);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public List<Crypto> searchByKeyword(String keyword) {
}

@Override
public Optional<Crypto> findById(Long id) {
return searchCryptoPort.findById(id);
public Optional<Crypto> findByTicker(String ticker) {
return searchCryptoPort.findByTicker(ticker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;


public interface CryptoRepository extends JpaRepository<Crypto, Long>, CryptoDslRepository {
public interface CryptoRepository extends JpaRepository<Crypto, String>, CryptoDslRepository {

@Query("SELECT c FROM Crypto c WHERE c.name LIKE %:keyword% OR c.ticker LIKE %:keyword% ORDER BY c.tradingVolume DESC LIMIT 4")
List<Crypto> searchByKeyword(@Param("keyword") String keyword);
Expand Down
Loading