diff --git a/src/main/java/com/book/backend/domain/openapi/service/ResponseParser.java b/src/main/java/com/book/backend/domain/openapi/service/ResponseParser.java index 3594719b..d63be42c 100644 --- a/src/main/java/com/book/backend/domain/openapi/service/ResponseParser.java +++ b/src/main/java/com/book/backend/domain/openapi/service/ResponseParser.java @@ -35,7 +35,7 @@ public LinkedList 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)) { // 중복 확인 @@ -60,6 +60,7 @@ public LinkedList hotTrend(JSONObject jsonResponse) { JSONArray results = (JSONArray) jsonResponse.get("results"); LinkedList responseList = new LinkedList<>(); + HashSet duplicateCheckSet = new HashSet<>(); if (results == null) { return responseList; @@ -73,23 +74,28 @@ public LinkedList 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; @@ -110,7 +116,9 @@ public LinkedList 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")) @@ -170,21 +178,26 @@ public LinkedList 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; } @@ -194,6 +207,7 @@ public LinkedList search(JSONObject jsonResponse){ JSONArray docs = (JSONArray) jsonResponse.get("docs"); LinkedList responseList = new LinkedList<>(); + HashSet duplicateCheckSet = new HashSet<>(); if (docs == null) { return responseList; @@ -203,17 +217,22 @@ public LinkedList 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; } @@ -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 responseList = new LinkedList<>(); BookInfoDto bookInfoDto = BookInfoDto.builder() .bookname(book.getAsString("bookname")) .authors(book.getAsString("authors")) @@ -271,22 +288,26 @@ public DetailResponseDto detail(JSONObject jsonResponse){ keywordList.add(o.getAsString("word")); } + HashSet duplicateCheckSet = new HashSet<>(); // 중복 체크 LinkedList 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 recommendBooksList = new LinkedList<>(); - HashSet duplicateCheckSet = new HashSet<>(); // 중복 체크 + duplicateCheckSet = new HashSet<>(); // 중복 체크 for(Object maniaRecBook : maniaRecBooks) { JSONObject o = (JSONObject) ((JSONObject) maniaRecBook).get("book");