Skip to content

Commit

Permalink
Merge pull request #18 from TeamUStory/feat/recommend
Browse files Browse the repository at this point in the history
fix:추천 페이퍼 디테일에서 상호명 추가
  • Loading branch information
yungic authored Aug 18, 2024
2 parents eb2fd75 + 0954be4 commit 0476d9e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,13 +43,13 @@ public ResponseEntity<List<MainRecommendResponse>> getMainRecommend(@RequestPara

@Operation(summary = "Get Recommend Papers", description = "추천하는 장소에 따른 페이퍼들을 보여줍니다. <br> 좋아요의 개수 순으로 반환됩니다.")
@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<List<RecommendPaperResponse>> getRecommendPaper(@RequestParam(name = "recommendPaperKey") String recommendPaperKey) {
List<RecommendPaperResponse> recommendPaper = recommendService.getRecommendPaper(recommendPaperKey);
return ResponseEntity.ok(recommendPaper);
public ResponseEntity<RecommendPaperResponse> getRecommendPaper(@RequestParam(name = "recommendPaperKey") String recommendPaperKey) {
RecommendPaperResponse recommendPapers = recommendService.getRecommendPaper(recommendPaperKey);
return ResponseEntity.ok(recommendPapers);
}

@Operation(summary = "Reset Recommend Redis DataBase", description = "새로운 추천 리스트들을 보여줍니다. <br> 원래는 자정마다 변경됩니다. <br> 실행시키면 주소 개수에 따라 추천이 변경됩니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "상호명을 불러올 수 없습니다.";

/**
* 매일 자정마다 추천 페이퍼들을 뽑아낸다. (생명주기 또한 자정까지)
*
Expand Down Expand Up @@ -96,24 +98,34 @@ public List<MainRecommendResponse> getRecommendM(int page, int size) {

}

public List<RecommendPaperResponse> getRecommendPaper(String recommendPaperKey) {
public RecommendPaperResponse getRecommendPaper(String recommendPaperKey) {

List<RecommendPaperResponse> recommendPaperResponses = new ArrayList<>();
List<RecommendPaperDTO> recommendPaperResponses = new ArrayList<>();
RecommendPaperResponse recommendPaperResponse = new RecommendPaperResponse();

List<Long> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<RecommendPaperDTO> recommendPaper;

public RecommendPaperResponse(Paper paper) {
this.paperTitle = paper.getTitle();
this.imgUrl = paper.getThumbnailImageUrl();
this.paperId = paper.getId();
}
}

0 comments on commit 0476d9e

Please sign in to comment.