Skip to content

Commit

Permalink
Merge pull request #175 from zipdabang/feature/174
Browse files Browse the repository at this point in the history
Feature/174 🐛  레시피 api 관련 버그 수정
  • Loading branch information
Hanvp authored Oct 9, 2023
2 parents 24056c2 + 066d71f commit c1d6cc8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@AllArgsConstructor
public enum RecipeStatus implements BaseCode{

RECIPE_NOT_FOUND(HttpStatus.OK, 2100, "조회된 목록이 없습니다"),
RECIPE_NOT_FOUND(HttpStatus.OK, 2100, "조회된 레시피 목록이 없습니다"),
COMMENT_NOT_FOUND(HttpStatus.OK, 2101, "조회된 댓글 목록이 없습니다"),

//BAD_REQUEST
NULL_RECIPE_ERROR(HttpStatus.OK, 4100, "레시피 작성시 누락된 내용이 있습니다."),
Expand All @@ -33,7 +34,9 @@ public enum RecipeStatus implements BaseCode{
//BAD_REQUEST
COMMENT_OWNER(HttpStatus.OK, 4110, "본인의 댓글입니다. 좋아요/스크랩/신고/차단할 수 없습니다"),
//BAD_REQUEST
NO_TEMP_RECIPE_EXIST(HttpStatus.OK, 4111, "해당 임시저장 Id가 존재하지 않습니다.");
NO_TEMP_RECIPE_EXIST(HttpStatus.OK, 4111, "해당 임시저장 Id가 존재하지 않습니다."),
NOT_MATCH_RECIPE(HttpStatus.OK, 4112, "해당 댓글은 넘겨준 레시피 Id에 존재하지 않습니다. 레시피 Id를 올바르게 보내주세요")
;

private final HttpStatus httpStatus;
private final Integer code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static RecipeResponseDto.PerCategoryPreview toPerCategoryPreview(Long cat
public static RecipeResponseDto.RecipePreviewDto toRecipePreviewDto(Recipe recipe, Member member, Integer rank) {
return RecipeResponseDto.RecipePreviewDto.builder()
.recipeId(recipe.getId())
.thumbnailUrl(recipe.getThumbnailUrl())
.recipeName(recipe.getName())
.nickname(recipe.getMember().getNickname())
.likes(recipe.getTotalLike())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,24 +443,17 @@ public List<Recipe> getTop5RecipePerCategory(Long categoryId) {

List<Recipe> recipeList = new ArrayList<>();

if (categoryId == 0){
recipeList = queryFactory
.selectFrom(recipe)
.limit(5)
.orderBy(recipe.totalLike.desc(), recipe.createdAt.desc())
.fetch();
}
else {
recipeList = queryFactory
.selectFrom(recipe)
.join(recipe.categoryMappingList, recipeCategoryMapping).fetchJoin()
.where(
recipeCategoryMapping.category.id.eq(categoryId)
)
.limit(5)
.orderBy(recipe.totalLike.desc(), recipe.createdAt.desc())
.fetch();
}

recipeList = queryFactory
.selectFrom(recipe)
.join(recipe.categoryMappingList, recipeCategoryMapping).fetchJoin()
.where(
recipeCategoryMapping.category.id.eq(categoryId)
)
.limit(5)
.orderBy(recipe.totalLike.desc(), recipe.createdAt.desc())
.fetch();


log.info(recipeList.toString());

Expand Down Expand Up @@ -656,13 +649,14 @@ public Comment createComment(String content, Long recipeId, Member member) {

@Override
public Page<Comment> commentList(Integer pageIndex, Long recipeId, Member member) {
recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(RecipeStatus.NO_RECIPE_EXIST));
Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(RecipeStatus.NO_RECIPE_EXIST));

QComment qComment = comment;

List<Comment> content = queryFactory
.selectFrom(comment)
.where(blockedMemberNotInForComment(member))
.where(blockedMemberNotInForComment(member),
comment.recipe.eq(findRecipe))
.orderBy(comment.createdAt.desc())
.offset(pageIndex*pageSize)
.limit(pageSize)
Expand All @@ -672,7 +666,12 @@ public Page<Comment> commentList(Integer pageIndex, Long recipeId, Member member
JPAQuery<Long> count = queryFactory
.select(comment.count())
.from(comment)
.where(blockedMemberNotInForComment(member));
.where(blockedMemberNotInForComment(member),
comment.recipe.eq(findRecipe)
);

if (count.fetchOne() == 0)
throw new RecipeException(RecipeStatus.COMMENT_NOT_FOUND);

return PageableExecutionUtils.getPage(content,PageRequest.of(pageIndex,pageSize), ()->count.fetchOne());
}
Expand All @@ -689,12 +688,14 @@ public Boolean deleteComment(Long recipeId, Long commentId, Member member) {
Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(RecipeStatus.NO_RECIPE_EXIST));
Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(RecipeStatus.NO_COMMENT_EXIST));

if (findComment.getMember().equals(member) && findComment.getRecipe().equals(findRecipe)) {
if (!findComment.getMember().equals(member))
throw new RecipeException(RecipeStatus.NOT_COMMENT_OWNER);
else if (!findComment.getRecipe().equals(findRecipe))
throw new RecipeException(RecipeStatus.NOT_MATCH_RECIPE);
else{
commentRepository.deleteById(commentId);
findRecipe.updateComment(-1);
}
else
throw new RecipeException(RecipeStatus.NOT_COMMENT_OWNER);

return commentRepository.existsById(recipeId) == false;
}
Expand All @@ -705,12 +706,13 @@ public Comment updateComment(RecipeRequestDto.updateCommentDto request, Long rec
Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(RecipeStatus.NO_RECIPE_EXIST));
Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(RecipeStatus.NO_COMMENT_EXIST));


if (findComment.getMember().equals(member) && findComment.getRecipe().equals(findRecipe)) {
if (!findComment.getMember().equals(member))
throw new RecipeException(RecipeStatus.NOT_COMMENT_OWNER);
else if (!findComment.getRecipe().equals(findRecipe))
throw new RecipeException(RecipeStatus.NOT_MATCH_RECIPE);
else{
return findComment.updateContent(request.getComment());
}
else
throw new RecipeException(RecipeStatus.NOT_COMMENT_OWNER);
}

@Transactional(readOnly = false)
Expand All @@ -720,14 +722,16 @@ public Long reportComment(Long recipeId, Long commentId, Long reportId, Member m
Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(RecipeStatus.NO_COMMENT_EXIST));
Report findReport = reportRepository.findById(reportId).orElseThrow(() -> new RecipeException(CommonStatus.NO_REPORT_EXIST));

if (!findComment.getMember().equals(member) && findComment.getRecipe().equals(findRecipe)) {
if (findComment.getMember().equals(member))
throw new RecipeException(RecipeStatus.COMMENT_OWNER);
else if (!findComment.getRecipe().equals(findRecipe))
throw new RecipeException(RecipeStatus.NOT_MATCH_RECIPE);
else{
ReportedComment mapping = RecipeConverter.toCommentReport(findReport, findComment, member);
reportedCommentRepository.save(mapping);

return findComment.getId();
}
else
throw new RecipeException(RecipeStatus.COMMENT_OWNER);
}

// 내가 좋아요 누른 레시피 목록 DTO 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public ResponseDto<RecipeResponseDto.CommentDto> createComment(@RequestBody Reci
@Operation(summary = "댓글 목록 화면 API 🔑 ✔", description = "댓글 API입니다. pageIndex로 페이징")
@ApiResponses({
@ApiResponse(responseCode = "2000", description = "OK, 목록이 있을 땐 이 응답임"),
@ApiResponse(responseCode = "2100", description = "OK, 목록이 없을 경우", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "2101", description = "OK, 조회된 댓글 목록이 없을 경우", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4003", description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4005", description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4008", description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
Expand Down Expand Up @@ -638,6 +638,7 @@ else if (pageIndex < 1)
@ApiResponse(responseCode = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4107", description = "BAD_REQUEST, 해당 commentId를 가진 댓글이 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4108", description = "BAD_REQUEST, 본인이 작성한 댓글이 아닙니다. 삭제할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4112", description = "BAD_REQUEST, 해당 댓글은 넘겨준 레시피 Id에 존재하지 않습니다. 레시피 Id를 올바르게 보내주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@Parameters({
Expand All @@ -663,6 +664,7 @@ public ResponseDto<String> deleteComment(@PathVariable(name = "recipeId") Long r
@ApiResponse(responseCode = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4107", description = "BAD_REQUEST, 해당 commentId를 가진 댓글이 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4108", description = "BAD_REQUEST, 본인이 작성한 댓글이 아닙니다. 수정할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4112", description = "BAD_REQUEST, 해당 댓글은 넘겨준 레시피 Id에 존재하지 않습니다. 레시피 Id를 올바르게 보내주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@Parameters({
Expand All @@ -686,6 +688,7 @@ public ResponseDto<RecipeResponseDto.CommentDto> updateComment(@RequestBody Reci
@ApiResponse(responseCode = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4107", description = "BAD_REQUEST, 해당 commentId를 가진 댓글이 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4110", description = "BAD_REQUEST, 본인의 댓글입니다. 신고/차단할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4112", description = "BAD_REQUEST, 해당 댓글은 넘겨준 레시피 Id에 존재하지 않습니다. 레시피 Id를 올바르게 보내주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@Parameters({
Expand Down Expand Up @@ -750,27 +753,4 @@ else if (page < 1)

return ResponseDto.of(recipeService.getScrapRecipes(page, member));
}


// @Operation(summary = "댓글 차단 API 🔑 ✔", description = "댓글 차단 API입니다.")
// @ApiResponses({
// @ApiResponse(responseCommonStatus = "2000", description = "OK, 댓글이 차단 되었습니다."),
// @ApiResponse(responseCommonStatus = "4003", description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
// @ApiResponse(responseCommonStatus = "4005", description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
// @ApiResponse(responseCommonStatus = "4008", description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
// @ApiResponse(responseCommonStatus = "4052", description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
// @ApiResponse(responseCommonStatus = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
// @ApiResponse(responseCommonStatus = "4107", description = "BAD_REQUEST, 해당 commentId를 가진 댓글이 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
// @ApiResponse(responseCommonStatus = "4110", description = "BAD_REQUEST, 본인의 댓글입니다. 신고/차단할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
// @ApiResponse(responseCommonStatus = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
// })
// @Parameters({
// @Parameter(name = "member", hidden = true),
// })
// @GetMapping("/members/recipes/{recipeId}/{commentId}/block")
// public ResponseDto<String> blockComment(@PathVariable(name = "recipeId") Long recipeId, @PathVariable(name = "commentId") Long commentId, @CheckTempMember @AuthMember Member member) {
// Long blockCommentId = recipeService.blockComment(recipeId, commentId, member);
//
// return ResponseDto.of(blockCommentId+"번 댓글이 차단되었습니다.");
// }
}

0 comments on commit c1d6cc8

Please sign in to comment.