-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#40 책 검색, 책 상세 API
- Loading branch information
Showing
21 changed files
with
595 additions
and
10 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/com/book/backend/domain/detail/controller/DetailController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.book.backend.domain.detail.controller; | ||
|
||
import com.book.backend.domain.openapi.service.RequestValidate; | ||
import com.book.backend.domain.detail.service.DetailService; | ||
import com.book.backend.domain.openapi.dto.request.DetailRequestDto; | ||
import com.book.backend.domain.openapi.dto.response.DetailResponseDto; | ||
import com.book.backend.global.ResponseTemplate; | ||
import com.book.backend.global.log.RequestLogger; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import java.util.LinkedList; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/api/book") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class DetailController { | ||
private final DetailService detailService; | ||
private final RequestValidate requestValidate; | ||
private final ResponseTemplate responseTemplate; | ||
|
||
// 도서 상세 (8) API | ||
@Operation(summary="책 상세", description="특정 책 코드를 입력으로 받아 해당 책 상세 정보, 대출 주 연령대, 키워드, 같이 대출한 도서, 추천 도서를 반환합니다.", | ||
parameters = {@Parameter(name = "isbn", description = "책 코드")}, | ||
responses = {@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = DetailResponseDto.class)), | ||
description = DetailResponseDto.description)}) | ||
@GetMapping("/detail") | ||
public ResponseEntity<?> search(@RequestParam String isbn, String libCode) throws Exception { | ||
RequestLogger.param(new String[]{"isbn, libCode"}, isbn, libCode); | ||
requestValidate.isValidIsbn(isbn); | ||
requestValidate.isValidLibCode(libCode); | ||
|
||
DetailRequestDto requestDto = DetailRequestDto.builder().isbn13(isbn).build(); | ||
DetailResponseDto response = detailService.detail(requestDto); | ||
|
||
detailService.setLoanAvailable(response, libCode); | ||
|
||
return responseTemplate.success(response, HttpStatus.OK); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/book/backend/domain/detail/dto/BookInfoDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.book.backend.domain.detail.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class BookInfoDto { | ||
private String bookname; | ||
private String authors; | ||
private String publisher; | ||
private String bookImageURL; | ||
private String description; | ||
private String publication_year; | ||
private String isbn13; | ||
private String vol; | ||
private String class_no; | ||
private String class_nm; | ||
private String loanCnt; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/book/backend/domain/detail/dto/CoLoanBooksDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.book.backend.domain.detail.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class CoLoanBooksDto { | ||
private String bookname; | ||
private String authors; | ||
private String publisher; | ||
private String publication_year; | ||
private String isbn13; | ||
private String vol; | ||
private String loanCnt; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/book/backend/domain/detail/dto/KeywordDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.book.backend.domain.detail.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class KeywordDto { | ||
private String word; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/book/backend/domain/detail/dto/LoanHistoryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.book.backend.domain.detail.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class LoanHistoryDto { | ||
private String month; | ||
private String loanCnt; | ||
private String ranking; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/book/backend/domain/detail/dto/RecommendDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.book.backend.domain.detail.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class RecommendDto { | ||
// 마니아, 다독자 | ||
private String bookname; | ||
private String authors; | ||
private String publisher; | ||
private String publication_year; | ||
private String isbn13; | ||
private String vol; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/book/backend/domain/detail/dto/Top3LoanUserDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.book.backend.domain.detail.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class Top3LoanUserDto { | ||
private String age; | ||
private String gender; | ||
private String loanCnt; | ||
private String ranking; | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/book/backend/domain/detail/service/DetailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.book.backend.domain.detail.service; | ||
|
||
import com.book.backend.domain.openapi.dto.request.BookExistRequestDto; | ||
import com.book.backend.domain.openapi.dto.request.DetailRequestDto; | ||
import com.book.backend.domain.openapi.dto.response.BookExistResponseDto; | ||
import com.book.backend.domain.openapi.dto.response.DetailResponseDto; | ||
import com.book.backend.domain.openapi.dto.response.SearchResponseDto; | ||
import com.book.backend.domain.openapi.service.OpenAPI; | ||
import com.book.backend.domain.openapi.service.ResponseParser; | ||
import java.util.LinkedList; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.minidev.json.JSONObject; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Slf4j | ||
public class DetailService { | ||
private final OpenAPI openAPI; | ||
|
||
public DetailResponseDto detail(DetailRequestDto requestDto) throws Exception { | ||
log.trace("detail()"); | ||
String subUrl = "usageAnalysisList"; | ||
JSONObject jsonResponse = openAPI.connect(subUrl, requestDto, new SearchResponseDto()); | ||
ResponseParser responseParser = new ResponseParser(); | ||
return responseParser.detail(jsonResponse); | ||
} | ||
|
||
public void setLoanAvailable(DetailResponseDto response, String libCode) throws Exception { | ||
log.trace("setLoanAvailable()"); | ||
|
||
BookExistRequestDto bookExistRequestDto = BookExistRequestDto.builder() | ||
.libCode(libCode) | ||
.isbn13(response.getBookInfoDto().getIsbn13()).build(); | ||
String subUrl = "bookExist"; | ||
JSONObject jsonResponse = openAPI.connect(subUrl, bookExistRequestDto, new BookExistResponseDto()); | ||
ResponseParser responseParser = new ResponseParser(); | ||
|
||
response.setLoanAvailable(responseParser.loanAvailable(jsonResponse)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/book/backend/domain/openapi/dto/request/BookExistRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.book.backend.domain.openapi.dto.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class BookExistRequestDto implements OpenAPIRequestInterface{ | ||
private String libCode; | ||
private String isbn13; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/book/backend/domain/openapi/dto/request/DetailRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.book.backend.domain.openapi.dto.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class DetailRequestDto implements OpenAPIRequestInterface { | ||
private String isbn13; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/book/backend/domain/openapi/dto/request/SearchRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.book.backend.domain.openapi.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Builder | ||
@Setter | ||
public class SearchRequestDto implements OpenAPIRequestInterface { | ||
@NotBlank(message = "검색어를 입력해주세요.") | ||
private String title; | ||
private String author; | ||
private String keyword; | ||
private String pageNo; // 페이지 번호 | ||
private String pageSize; // 한 페이지에 담을 요소 수 | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/book/backend/domain/openapi/dto/response/BookExistResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.book.backend.domain.openapi.dto.response; | ||
|
||
public class BookExistResponseDto implements OpenAPIResponseInterface{ | ||
private String loanAvailable; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/book/backend/domain/openapi/dto/response/DetailResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.book.backend.domain.openapi.dto.response; | ||
|
||
import com.book.backend.domain.detail.dto.BookInfoDto; | ||
import com.book.backend.domain.detail.dto.CoLoanBooksDto; | ||
import com.book.backend.domain.detail.dto.Top3LoanUserDto; | ||
import com.book.backend.domain.detail.dto.RecommendDto; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Builder | ||
@Setter | ||
public class DetailResponseDto implements OpenAPIResponseInterface { | ||
private BookInfoDto bookInfoDto; | ||
private List<Top3LoanUserDto> top3LoanUserDtoList; | ||
private LinkedList<String> keywordDtoList; | ||
private LinkedList<CoLoanBooksDto> coLoanBooksDtoList; | ||
private LinkedList<RecommendDto> recommendResponseDtoList; | ||
private boolean loanAvailable; | ||
|
||
public static final String description = "bookInfoDto: 책 상세 정보 | top3LoanUserDtoList: 대출 주 연령대 | " | ||
+ "keywordDtoList: 책 연관 키워드 | coLoanBooksDtoList: 같이 대출한 도서 | recommendResponseDtoList: 추천 도서"; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/book/backend/domain/openapi/dto/response/SearchResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.book.backend.domain.openapi.dto.response; | ||
|
||
import com.book.backend.domain.openapi.dto.request.OpenAPIRequestInterface; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Setter | ||
public class SearchResponseDto implements OpenAPIResponseInterface, OpenAPIRequestInterface { | ||
private String bookname; | ||
private String authors; | ||
private String publisher; | ||
private String publication_year; | ||
private String isbn13; | ||
private String vol; | ||
private String bookImageURL; | ||
private String bookDtlUrl; | ||
private String loan_count; | ||
|
||
private boolean isLoanAvailable; | ||
|
||
public static final String description = "bookname: 책이름 | authors: 작가 옮긴이 | publisher: 출판사 | " | ||
+ "publication_year: 출판년도 | isbn13: 책 바코드 | vol: 권? | " | ||
+ "bookImageURL: 책 표지 URL | bookDtlUrl: 책 상세설명 URL | loan_count: 총? 대출 회수"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.