diff --git a/src/main/java/zipdabang/server/converter/RecipeConverter.java b/src/main/java/zipdabang/server/converter/RecipeConverter.java index 623ec4b..7072d62 100644 --- a/src/main/java/zipdabang/server/converter/RecipeConverter.java +++ b/src/main/java/zipdabang/server/converter/RecipeConverter.java @@ -154,7 +154,6 @@ public static RecipeResponseDto.RecipePageListDto toPagingRecipeDtoList(Page bestRecipes, Member member) { diff --git a/src/main/java/zipdabang/server/repository/memberRepositories/BlockedMemberRepository.java b/src/main/java/zipdabang/server/repository/memberRepositories/BlockedMemberRepository.java index f5bb807..daeda93 100644 --- a/src/main/java/zipdabang/server/repository/memberRepositories/BlockedMemberRepository.java +++ b/src/main/java/zipdabang/server/repository/memberRepositories/BlockedMemberRepository.java @@ -4,6 +4,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import zipdabang.server.domain.member.BlockedMember; import zipdabang.server.domain.member.Member; @@ -13,8 +14,10 @@ public interface BlockedMemberRepository extends JpaRepository { List findByOwner(Member owner); - @Query("select b.blocked from BlockedMember b") - Page findBlockedByOwner(Member owner, PageRequest pageRequest); + @Query("select b.blocked from BlockedMember b where b.owner = :owner ") + List findBlockedByOwner(Member owner); + @Query("select b.blocked from BlockedMember b where b.owner = :owner ") + Page findBlockedByOwner(@Param("owner") Member owner, PageRequest pageRequest); Optional findByOwnerAndBlocked(Member owner, Member blocked); boolean existsByOwnerAndBlocked(Member owner, Member blocked); diff --git a/src/main/java/zipdabang/server/repository/recipeRepositories/LikesRepository.java b/src/main/java/zipdabang/server/repository/recipeRepositories/LikesRepository.java index 6e5b404..a841a93 100644 --- a/src/main/java/zipdabang/server/repository/recipeRepositories/LikesRepository.java +++ b/src/main/java/zipdabang/server/repository/recipeRepositories/LikesRepository.java @@ -1,6 +1,11 @@ package zipdabang.server.repository.recipeRepositories; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import zipdabang.server.domain.member.BlockedMember; import zipdabang.server.domain.member.Member; import zipdabang.server.domain.recipe.Likes; import zipdabang.server.domain.recipe.Recipe; @@ -9,5 +14,8 @@ public interface LikesRepository extends JpaRepository { + @Query("select l.recipe from Likes l where l.member = :owner and l.recipe.member not in ( select b.blocked from BlockedMember b where b.owner = :owner ) ") + Page findRecipeByMember(@Param("owner") Member owner, PageRequest pageRequest); + Optional findByRecipeAndMember(Recipe recipe, Member member); } diff --git a/src/main/java/zipdabang/server/repository/recipeRepositories/ScrapRepository.java b/src/main/java/zipdabang/server/repository/recipeRepositories/ScrapRepository.java index c44534e..a178e66 100644 --- a/src/main/java/zipdabang/server/repository/recipeRepositories/ScrapRepository.java +++ b/src/main/java/zipdabang/server/repository/recipeRepositories/ScrapRepository.java @@ -1,6 +1,10 @@ package zipdabang.server.repository.recipeRepositories; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import zipdabang.server.domain.member.Member; import zipdabang.server.domain.recipe.Recipe; import zipdabang.server.domain.recipe.Scrap; @@ -8,6 +12,8 @@ import java.util.Optional; public interface ScrapRepository extends JpaRepository { + @Query("select s.recipe from Scrap s where s.member = :owner and s.recipe.member not in ( select b.blocked from BlockedMember b where b.owner = :owner ) ") + Page findRecipeByMember(@Param("owner") Member owner, PageRequest pageRequest); Optional findByRecipeAndMember(Recipe recipe, Member member); } diff --git a/src/main/java/zipdabang/server/service/RecipeService.java b/src/main/java/zipdabang/server/service/RecipeService.java index 0a0ab73..8e2d10d 100644 --- a/src/main/java/zipdabang/server/service/RecipeService.java +++ b/src/main/java/zipdabang/server/service/RecipeService.java @@ -5,6 +5,7 @@ import zipdabang.server.domain.member.Member; import zipdabang.server.domain.recipe.*; import zipdabang.server.web.dto.requestDto.RecipeRequestDto; +import zipdabang.server.web.dto.responseDto.RecipeResponseDto; import java.io.IOException; import java.util.List; @@ -71,4 +72,6 @@ public interface RecipeService { Recipe createFromTempRecipe(Long tempId, RecipeRequestDto.RecipeCategoryList categoryList, Member member); TempRecipe getTempRecipe(Long tempId); + RecipeResponseDto.RecipePageListDto getLikeRecipes(Integer page, Member member); + RecipeResponseDto.RecipePageListDto getScrapRecipes(Integer page, Member member); } diff --git a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java index 5c7b9ce..0196904 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java @@ -32,6 +32,7 @@ import zipdabang.server.repository.recipeRepositories.*; import zipdabang.server.service.RecipeService; import zipdabang.server.web.dto.requestDto.RecipeRequestDto; +import zipdabang.server.web.dto.responseDto.RecipeResponseDto; import java.io.IOException; import java.util.ArrayList; @@ -370,7 +371,7 @@ else if (writtenby.equals("official")) private BooleanExpression blockedMemberNotInForRecipe(Member member) { List blockedMember = getBlockedMember(member); - return blockedMember.isEmpty() ? null : recipe.member.notIn(blockedMember); + return blockedMember.isEmpty() ? null : recipe.member.notIn(blockedMember); } private List getBlockedMember(Member member) { @@ -728,4 +729,20 @@ public Long reportComment(Long recipeId, Long commentId, Long reportId, Member m else throw new RecipeException(RecipeStatus.COMMENT_OWNER); } + + // 내가 좋아요 누른 레시피 목록 DTO 조회 + @Override + @Transactional + public RecipeResponseDto.RecipePageListDto getLikeRecipes(Integer page, Member member) { + Page likesRecipes = likesRepository.findRecipeByMember(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt"))); + return RecipeConverter.toPagingRecipeDtoList(likesRecipes, member); + } + + // 내가 스크랩 누른 레시피 목록 DTO 조회 + @Override + @Transactional + public RecipeResponseDto.RecipePageListDto getScrapRecipes(Integer page, Member member) { + Page scrapRecipes = scrapRepository.findRecipeByMember(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt"))); + return RecipeConverter.toPagingRecipeDtoList(scrapRecipes, member); + } } diff --git a/src/main/java/zipdabang/server/web/controller/RecipeRestController.java b/src/main/java/zipdabang/server/web/controller/RecipeRestController.java index ac0f3a6..52173b3 100644 --- a/src/main/java/zipdabang/server/web/controller/RecipeRestController.java +++ b/src/main/java/zipdabang/server/web/controller/RecipeRestController.java @@ -16,6 +16,7 @@ import org.springframework.web.multipart.MultipartFile; import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.apiPayload.code.RecipeStatus; +import zipdabang.server.apiPayload.exception.handler.MemberException; import zipdabang.server.apiPayload.reponse.ResponseDto; import zipdabang.server.auth.handler.annotation.AuthMember; import zipdabang.server.apiPayload.exception.handler.RecipeException; @@ -696,4 +697,80 @@ public ResponseDto reportComment(@PathVariable Long recipeId, @PathVaria return ResponseDto.of(reportedCommentId+"번 댓글이 신고되었습니다."); } + + @Operation(summary = "내가 좋아요 누른 레시피 목록 조회 API 🔑 ✔", description = "내가 좋아요 누른 레시피 목록 조회 API입니다.") + @ApiResponses({ + @ApiResponse(responseCode = "2000", description = "OK, 좋아요 누른 레시피 조회 성공"), + @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))), + @ApiResponse(responseCode = "4052", description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + @ApiResponse(responseCode = "4054", description = "BAD_REQEUST , 페이지 번호가 없거나 0 이하", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + @ApiResponse(responseCode = "4055", description = "BAD_REQEUST , 페이지 번호가 초과함", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + @ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + }) + @Parameters({ + @Parameter(name = "member", hidden = true), + @Parameter(name = "page", description = "페이지 번호, 1부터 시작") + }) + @GetMapping("/members/likeRecipes") + public ResponseDto memberLikeRecipeList(@CheckTempMember @AuthMember Member member, @RequestParam(name = "page", required = true) @CheckPage Integer page) { + if (page == null) + page = 1; + else if (page < 1) + throw new MemberException(CommonStatus.UNDER_PAGE_INDEX_ERROR); + page -= 1; + + return ResponseDto.of(recipeService.getLikeRecipes(page, member)); + } + + + @Operation(summary = "내가 스크랩 누른 레시피 목록 조회 API 🔑 ✔", description = "내가 스크랩 누른 레시피 목록 조회 API입니다.") + @ApiResponses({ + @ApiResponse(responseCode = "2000", description = "OK, 스크랩 누른 레시피 조회 성공"), + @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))), + @ApiResponse(responseCode = "4052", description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + @ApiResponse(responseCode = "4054", description = "BAD_REQEUST , 페이지 번호가 없거나 0 이하", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + @ApiResponse(responseCode = "4055", description = "BAD_REQEUST , 페이지 번호가 초과함", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + @ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), + }) + @Parameters({ + @Parameter(name = "member", hidden = true), + @Parameter(name = "page", description = "페이지 번호, 1부터 시작") + }) + @GetMapping("/members/scrapRecipes") + public ResponseDto memberScrapRecipeList(@CheckTempMember @AuthMember Member member, @RequestParam(name = "page", required = true) @CheckPage Integer page) { + if (page == null) + page = 1; + else if (page < 1) + throw new MemberException(CommonStatus.UNDER_PAGE_INDEX_ERROR); + 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+"번 댓글이 차단되었습니다."); +// } }