Skip to content

Commit

Permalink
Merge pull request #120 from BOOK-TALK/#119-prevent-duplication
Browse files Browse the repository at this point in the history
[feat] ResponseParser에 중복 방지 로직 추가
  • Loading branch information
chanwoo7 authored Aug 26, 2024
2 parents 4d468fc + 4790394 commit 5a7ab6d
Showing 1 changed file with 77 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LinkedList<RecommendListResponseDto> recommend(JSONObject jsonResponse) {
JSONObject docsElement = (JSONObject) o;
JSONObject book = (JSONObject) docsElement.get("book");

// 중복 추천 체크 (open api 가 중복되는 책을 추천함;;)
// 중복 체크
String duplicateCheckKey = book.getAsString("bookname") + book.getAsString("authors");

if (duplicateCheckSet.add(duplicateCheckKey)) { // 중복 확인
Expand All @@ -60,6 +60,7 @@ public LinkedList<HotTrendResponseDto> hotTrend(JSONObject jsonResponse) {

JSONArray results = (JSONArray) jsonResponse.get("results");
LinkedList<HotTrendResponseDto> responseList = new LinkedList<>();
HashSet<String> duplicateCheckSet = new HashSet<>();

if (results == null) {
return responseList;
Expand All @@ -73,23 +74,28 @@ public LinkedList<HotTrendResponseDto> hotTrend(JSONObject jsonResponse) {
JSONObject docsElement = (JSONObject) value;
JSONObject doc = (JSONObject) docsElement.get("doc");

responseList.add(HotTrendResponseDto.builder()
.no(doc.getAsString("no"))
.difference(doc.getAsString("difference"))
.baseWeekRank(doc.getAsString("baseWeekRank"))
.pastWeekRank(doc.getAsString("pastWeekRank"))
.bookname(doc.getAsString("bookname"))
.authors(doc.getAsString("authors"))
.publisher(doc.getAsString("publisher"))
.publication_year(doc.getAsString("publication_year"))
.isbn13(doc.getAsString("isbn13"))
.addition_symbol(doc.getAsString("addition_symbol"))
.vol(doc.getAsString("vol"))
.class_no(doc.getAsString("class_no"))
.class_nm(doc.getAsString("class_nm"))
.bookImageURL(doc.getAsString("bookImageURL"))
.bookDtlUrl(doc.getAsString("bookDtlUrl"))
.build());
// 중복 체크
String duplicateCheckKey = doc.getAsString("bookname") + doc.getAsString("authors");

if (duplicateCheckSet.add(duplicateCheckKey)) { // 중복 확인
responseList.add(HotTrendResponseDto.builder()
.no(doc.getAsString("no"))
.difference(doc.getAsString("difference"))
.baseWeekRank(doc.getAsString("baseWeekRank"))
.pastWeekRank(doc.getAsString("pastWeekRank"))
.bookname(doc.getAsString("bookname"))
.authors(doc.getAsString("authors"))
.publisher(doc.getAsString("publisher"))
.publication_year(doc.getAsString("publication_year"))
.isbn13(doc.getAsString("isbn13"))
.addition_symbol(doc.getAsString("addition_symbol"))
.vol(doc.getAsString("vol"))
.class_no(doc.getAsString("class_no"))
.class_nm(doc.getAsString("class_nm"))
.bookImageURL(doc.getAsString("bookImageURL"))
.bookDtlUrl(doc.getAsString("bookDtlUrl"))
.build());
}
}
}
return responseList;
Expand All @@ -110,7 +116,9 @@ public LinkedList<LoanItemSrchResponseDto> loanTrend(JSONObject jsonResponse) {
JSONObject docsElement = (JSONObject) o;
JSONObject doc = (JSONObject) docsElement.get("doc");

// 중복 체크
String duplicateCheckKey = doc.getAsString("bookname") + doc.getAsString("authors");

if (duplicateCheckSet.add(duplicateCheckKey)) {
responseList.add(LoanItemSrchResponseDto.builder()
.no(doc.getAsString("no"))
Expand Down Expand Up @@ -170,21 +178,26 @@ public LinkedList<LoanItemSrchResponseDto> loanItemSrch(JSONObject jsonResponse)
JSONObject docsElement = (JSONObject) o;
JSONObject doc = (JSONObject) docsElement.get("doc");

responseList.add(LoanItemSrchResponseDto.builder()
.no(doc.getAsString("no"))
.ranking(doc.getAsString("ranking"))
.bookname(doc.getAsString("bookname"))
.authors(doc.getAsString("authors"))
.publisher(doc.getAsString("publisher"))
.publication_year(doc.getAsString("publication_year"))
.isbn13(doc.getAsString("isbn13"))
.addition_symbol(doc.getAsString("addition_symbol"))
.class_no(doc.getAsString("class_no"))
.class_nm(doc.getAsString("class_nm"))
.loan_count(doc.getAsString("loan_count"))
.bookImageURL(doc.getAsString("bookImageURL"))
.bookDtlUrl(doc.getAsString("bookDtlUrl"))
.build());
// 중복 체크
String duplicateCheckKey = doc.getAsString("bookname") + doc.getAsString("authors");

if (duplicateCheckSet.add(duplicateCheckKey)) { // 중복 확인
responseList.add(LoanItemSrchResponseDto.builder()
.no(doc.getAsString("no"))
.ranking(doc.getAsString("ranking"))
.bookname(doc.getAsString("bookname"))
.authors(doc.getAsString("authors"))
.publisher(doc.getAsString("publisher"))
.publication_year(doc.getAsString("publication_year"))
.isbn13(doc.getAsString("isbn13"))
.addition_symbol(doc.getAsString("addition_symbol"))
.class_no(doc.getAsString("class_no"))
.class_nm(doc.getAsString("class_nm"))
.loan_count(doc.getAsString("loan_count"))
.bookImageURL(doc.getAsString("bookImageURL"))
.bookDtlUrl(doc.getAsString("bookDtlUrl"))
.build());
}
}
return responseList;
}
Expand All @@ -194,6 +207,7 @@ public LinkedList<SearchResponseDto> search(JSONObject jsonResponse){

JSONArray docs = (JSONArray) jsonResponse.get("docs");
LinkedList<SearchResponseDto> responseList = new LinkedList<>();
HashSet<String> duplicateCheckSet = new HashSet<>();

if (docs == null) {
return responseList;
Expand All @@ -203,17 +217,22 @@ public LinkedList<SearchResponseDto> search(JSONObject jsonResponse){
JSONObject docsElement = (JSONObject) o;
JSONObject doc = (JSONObject) docsElement.get("doc");

responseList.add(SearchResponseDto.builder()
.bookname(doc.getAsString("bookname"))
.authors(doc.getAsString("authors"))
.publisher(doc.getAsString("publisher"))
.publication_year(doc.getAsString("publication_year"))
.isbn13(doc.getAsString("isbn13"))
.vol(doc.getAsString("vol"))
.bookImageURL(doc.getAsString("bookImageURL"))
.bookDtlUrl(doc.getAsString("bookDtlUrl"))
.loan_count(doc.getAsString("loan_count"))
.build());
// 중복 체크
String duplicateCheckKey = doc.getAsString("bookname") + doc.getAsString("authors");

if (duplicateCheckSet.add(duplicateCheckKey)) { // 중복 확인
responseList.add(SearchResponseDto.builder()
.bookname(doc.getAsString("bookname"))
.authors(doc.getAsString("authors"))
.publisher(doc.getAsString("publisher"))
.publication_year(doc.getAsString("publication_year"))
.isbn13(doc.getAsString("isbn13"))
.vol(doc.getAsString("vol"))
.bookImageURL(doc.getAsString("bookImageURL"))
.bookDtlUrl(doc.getAsString("bookDtlUrl"))
.loan_count(doc.getAsString("loan_count"))
.build());
}
}
return responseList;
}
Expand All @@ -228,14 +247,12 @@ public boolean loanAvailable(JSONObject jsonResponse) {
public DetailResponseDto detail(JSONObject jsonResponse){
log.trace("ResponseParser > detail()");
JSONObject book = (JSONObject) jsonResponse.get("book");
JSONArray loanHistory = (JSONArray) jsonResponse.get("loanHistory");
JSONArray loanGrps = (JSONArray) jsonResponse.get("loanGrps");
JSONArray keywords = (JSONArray) jsonResponse.get("keywords");
JSONArray coLoanBooks = (JSONArray) jsonResponse.get("coLoanBooks");
JSONArray maniaRecBooks = (JSONArray) jsonResponse.get("maniaRecBooks");
JSONArray readerRecBooks = (JSONArray) jsonResponse.get("readerRecBooks");

LinkedList<DetailResponseDto> responseList = new LinkedList<>();
BookInfoDto bookInfoDto = BookInfoDto.builder()
.bookname(book.getAsString("bookname"))
.authors(book.getAsString("authors"))
Expand Down Expand Up @@ -271,22 +288,26 @@ public DetailResponseDto detail(JSONObject jsonResponse){
keywordList.add(o.getAsString("word"));
}

HashSet<String> duplicateCheckSet = new HashSet<>(); // 중복 체크
LinkedList<CoLoanBooksDto> coLoanBooksList = new LinkedList<>();
for (Object coLoanBook : coLoanBooks) {
JSONObject o = (JSONObject) ((JSONObject) coLoanBook).get("book");
coLoanBooksList.add(CoLoanBooksDto.builder()
.bookname(o.getAsString("bookname"))
.authors(o.getAsString("authors"))
.publisher(o.getAsString("publisher"))
.publication_year(o.getAsString("publication_year"))
.isbn13(o.getAsString("isbn13"))
.vol(o.getAsString("vol"))
.loanCnt(o.getAsString("loanCnt"))
.build());
String duplicateCheckKey = o.getAsString("bookname") + o.getAsString("authors");
if (duplicateCheckSet.add(duplicateCheckKey)) { // 중복 확인
coLoanBooksList.add(CoLoanBooksDto.builder()
.bookname(o.getAsString("bookname"))
.authors(o.getAsString("authors"))
.publisher(o.getAsString("publisher"))
.publication_year(o.getAsString("publication_year"))
.isbn13(o.getAsString("isbn13"))
.vol(o.getAsString("vol"))
.loanCnt(o.getAsString("loanCnt"))
.build());
}
}

LinkedList<RecommendDto> recommendBooksList = new LinkedList<>();
HashSet<String> duplicateCheckSet = new HashSet<>(); // 중복 체크
duplicateCheckSet = new HashSet<>(); // 중복 체크

for(Object maniaRecBook : maniaRecBooks) {
JSONObject o = (JSONObject) ((JSONObject) maniaRecBook).get("book");
Expand Down

0 comments on commit 5a7ab6d

Please sign in to comment.