diff --git a/src/main/java/zipdabang/server/apiPayload/code/RecipeStatus.java b/src/main/java/zipdabang/server/apiPayload/code/RecipeStatus.java index 94fec8a..1b8b7fc 100644 --- a/src/main/java/zipdabang/server/apiPayload/code/RecipeStatus.java +++ b/src/main/java/zipdabang/server/apiPayload/code/RecipeStatus.java @@ -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, "레시피 작성시 누락된 내용이 있습니다."), @@ -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; diff --git a/src/main/java/zipdabang/server/converter/RecipeConverter.java b/src/main/java/zipdabang/server/converter/RecipeConverter.java index 7072d62..1380953 100644 --- a/src/main/java/zipdabang/server/converter/RecipeConverter.java +++ b/src/main/java/zipdabang/server/converter/RecipeConverter.java @@ -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()) diff --git a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java index 0196904..209cb0d 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java @@ -443,24 +443,17 @@ public List getTop5RecipePerCategory(Long categoryId) { List 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()); @@ -656,13 +649,14 @@ public Comment createComment(String content, Long recipeId, Member member) { @Override public Page 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 content = queryFactory .selectFrom(comment) - .where(blockedMemberNotInForComment(member)) + .where(blockedMemberNotInForComment(member), + comment.recipe.eq(findRecipe)) .orderBy(comment.createdAt.desc()) .offset(pageIndex*pageSize) .limit(pageSize) @@ -672,7 +666,12 @@ public Page commentList(Integer pageIndex, Long recipeId, Member member JPAQuery 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()); } @@ -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; } @@ -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) @@ -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 조회 diff --git a/src/main/java/zipdabang/server/web/controller/RecipeRestController.java b/src/main/java/zipdabang/server/web/controller/RecipeRestController.java index 52173b3..ac422b2 100644 --- a/src/main/java/zipdabang/server/web/controller/RecipeRestController.java +++ b/src/main/java/zipdabang/server/web/controller/RecipeRestController.java @@ -593,7 +593,7 @@ public ResponseDto 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))), @@ -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({ @@ -663,6 +664,7 @@ public ResponseDto 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({ @@ -686,6 +688,7 @@ public ResponseDto 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({ @@ -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 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+"번 댓글이 차단되었습니다."); -// } }