diff --git a/src/main/java/com/elice/ustory/domain/recommand/RecommendController.java b/src/main/java/com/elice/ustory/domain/recommand/RecommendController.java index ad8915c..4af4cda 100644 --- a/src/main/java/com/elice/ustory/domain/recommand/RecommendController.java +++ b/src/main/java/com/elice/ustory/domain/recommand/RecommendController.java @@ -1,7 +1,7 @@ package com.elice.ustory.domain.recommand; -import com.elice.ustory.domain.paper.dto.PaperListResponse; import com.elice.ustory.domain.recommand.dto.MainRecommendResponse; +import com.elice.ustory.domain.recommand.dto.RecommendPaperDTO; import com.elice.ustory.domain.recommand.dto.RecommendPaperResponse; import com.elice.ustory.global.Validation.PageableValidation; import com.elice.ustory.global.exception.dto.ErrorResponse; @@ -43,13 +43,13 @@ public ResponseEntity> getMainRecommend(@RequestPara @Operation(summary = "Get Recommend Papers", description = "추천하는 장소에 따른 페이퍼들을 보여줍니다.
좋아요의 개수 순으로 반환됩니다.") @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = RecommendPaperResponse.class)))), + @ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = RecommendPaperDTO.class)))), @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) }) @GetMapping("/papers") - public ResponseEntity> getRecommendPaper(@RequestParam(name = "recommendPaperKey") String recommendPaperKey) { - List recommendPaper = recommendService.getRecommendPaper(recommendPaperKey); - return ResponseEntity.ok(recommendPaper); + public ResponseEntity getRecommendPaper(@RequestParam(name = "recommendPaperKey") String recommendPaperKey) { + RecommendPaperResponse recommendPapers = recommendService.getRecommendPaper(recommendPaperKey); + return ResponseEntity.ok(recommendPapers); } @Operation(summary = "Reset Recommend Redis DataBase", description = "새로운 추천 리스트들을 보여줍니다.
원래는 자정마다 변경됩니다.
실행시키면 주소 개수에 따라 추천이 변경됩니다.") diff --git a/src/main/java/com/elice/ustory/domain/recommand/RecommendService.java b/src/main/java/com/elice/ustory/domain/recommand/RecommendService.java index 784faa7..2596d59 100644 --- a/src/main/java/com/elice/ustory/domain/recommand/RecommendService.java +++ b/src/main/java/com/elice/ustory/domain/recommand/RecommendService.java @@ -29,6 +29,8 @@ public class RecommendService { private static final String NOT_FOUND_PAPER_MESSAGE = "%d: 해당하는 페이퍼가 존재하지 않습니다."; private static final String NOT_FOUND_PAPERS = "어떠한 페이퍼도 찾을 수 없습니다."; + private static final String NOT_FOUND_STORE = "상호명을 불러올 수 없습니다."; + /** * 매일 자정마다 추천 페이퍼들을 뽑아낸다. (생명주기 또한 자정까지) * @@ -96,24 +98,34 @@ public List getRecommendM(int page, int size) { } - public List getRecommendPaper(String recommendPaperKey) { + public RecommendPaperResponse getRecommendPaper(String recommendPaperKey) { - List recommendPaperResponses = new ArrayList<>(); + List recommendPaperResponses = new ArrayList<>(); + RecommendPaperResponse recommendPaperResponse = new RecommendPaperResponse(); List paperIds = recommendRedisService.getData(recommendPaperKey).getPaperIds(); for (Long paperId : paperIds) { Paper paper = paperRepository.findById(paperId).orElseThrow(() -> new NotFoundException(String.format(NOT_FOUND_PAPER_MESSAGE, paperId))); - RecommendPaperResponse recommendPaperResponse = new RecommendPaperResponse(paper); + RecommendPaperDTO recommendPaperDTO = new RecommendPaperDTO(paper); Integer countGreatById = greatRepository.countGreatById(paperId); - recommendPaperResponse.setCountGreat(countGreatById); + recommendPaperDTO.setCountGreat(countGreatById); - recommendPaperResponses.add(recommendPaperResponse); + recommendPaperResponses.add(recommendPaperDTO); } recommendPaperResponses.sort((r1, r2) -> Integer.compare(r2.getCountGreat(), r1.getCountGreat())); - return recommendPaperResponses; + if (recommendPaperResponses.isEmpty()) { + throw new NotFoundException(NOT_FOUND_STORE); + } + + Paper paper = paperRepository.findById(recommendPaperResponses.get(0).getPaperId()).orElseThrow(() -> new NotFoundException(NOT_FOUND_STORE)); + + recommendPaperResponse.setStore(paper.getAddress().getStore()); + recommendPaperResponse.setRecommendPaper(recommendPaperResponses); + + return recommendPaperResponse; } } diff --git a/src/main/java/com/elice/ustory/domain/recommand/dto/RecommendPaperDTO.java b/src/main/java/com/elice/ustory/domain/recommand/dto/RecommendPaperDTO.java new file mode 100644 index 0000000..ec37052 --- /dev/null +++ b/src/main/java/com/elice/ustory/domain/recommand/dto/RecommendPaperDTO.java @@ -0,0 +1,33 @@ +package com.elice.ustory.domain.recommand.dto; + +import com.elice.ustory.domain.paper.entity.Paper; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class RecommendPaperDTO { + + @Schema(description = "상호명", example = "진양면옥") + private String paperTitle; + + @Schema(description = "좋아요 수", example = "1") + private int countGreat; + + @Schema(description = "썸네일 이미지", example = "https://~~~~~~") + private String imgUrl; + + @Schema(description = "페이퍼 이미지", example = "1") + private long paperId; + + public RecommendPaperDTO(Paper paper) { + this.paperTitle = paper.getTitle(); + this.imgUrl = paper.getThumbnailImageUrl(); + this.paperId = paper.getId(); + } +} diff --git a/src/main/java/com/elice/ustory/domain/recommand/dto/RecommendPaperResponse.java b/src/main/java/com/elice/ustory/domain/recommand/dto/RecommendPaperResponse.java index f961fe7..9bfdf49 100644 --- a/src/main/java/com/elice/ustory/domain/recommand/dto/RecommendPaperResponse.java +++ b/src/main/java/com/elice/ustory/domain/recommand/dto/RecommendPaperResponse.java @@ -1,33 +1,18 @@ package com.elice.ustory.domain.recommand.dto; -import com.elice.ustory.domain.paper.entity.Paper; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import java.util.List; + @Getter @Setter @NoArgsConstructor -@AllArgsConstructor public class RecommendPaperResponse { - @Schema(description = "상호명", example = "진양면옥") - private String paperTitle; - - @Schema(description = "좋아요 수", example = "1") - private int countGreat; - - @Schema(description = "썸네일 이미지", example = "https://~~~~~~") - private String imgUrl; + private String store; - @Schema(description = "페이퍼 이미지", example = "1") - private long paperId; + private List recommendPaper; - public RecommendPaperResponse(Paper paper) { - this.paperTitle = paper.getTitle(); - this.imgUrl = paper.getThumbnailImageUrl(); - this.paperId = paper.getId(); - } }