Skip to content

Commit

Permalink
✨ 내가 스크랩한 레시피 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
HyoBN committed Oct 8, 2023
1 parent 6bf37a7 commit ef69110
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
3 changes: 0 additions & 3 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ private static RecipeResponseDto.SearchRecipePreviewByCategoryDto toSearchRecipe
}

private static RecipeResponseDto.RecipeSimpleDto toResponseRecipeSimpleDto(Recipe recipe, Member member) {
log.info("시작");
log.info("레시피 정보: "+recipe.getId().toString());
log.info(recipe.getIntro());
return RecipeResponseDto.RecipeSimpleDto.builder()
.recipeId(recipe.getId())
.categoryId(getCategoryIds(recipe))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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;

import java.util.Optional;

public interface ScrapRepository extends JpaRepository<Scrap, Long> {
@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<Recipe> findRecipeByMember(@Param("owner") Member owner, PageRequest pageRequest);
Optional<Scrap> findByRecipeAndMember(Recipe recipe, Member member);

}
1 change: 1 addition & 0 deletions src/main/java/zipdabang/server/service/RecipeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ public interface RecipeService {

TempRecipe getTempRecipe(Long tempId);
RecipeResponseDto.RecipePageListDto getLikeRecipes(Integer page, Member member);
RecipeResponseDto.RecipePageListDto getScrapRecipes(Integer page, Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -733,28 +733,16 @@ public Long reportComment(Long recipeId, Long commentId, Long reportId, Member m
// 내가 좋아요 누른 레시피 목록 DTO 조회
@Override
@Transactional
public RecipeResponseDto.RecipePageListDto getLikeRecipes(Integer page,Member member) {
// List<Member> blockedList = blockedMemberRepository.findBlockedByOwner(member);
public RecipeResponseDto.RecipePageListDto getLikeRecipes(Integer page, Member member) {
Page<Recipe> likesRecipes = likesRepository.findRecipeByMember(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt")));
log.info("서비스단에서 시작!");
log.info("엘리먼트 사이즈 : " + likesRecipes.getTotalElements());
log.info("컨텐츠 사이즈: " + likesRecipes.getContent().size());
List<Recipe> content = likesRecipes.getContent();
for (Recipe r : content) {
log.info("아이디 : " + r.getId());
log.info("인트로 : " + r.getIntro());
}
// List<Recipe> filteredRecipes = likesRecipes.getContent()
// .stream()
// .filter(likes -> !isBlockedMember(likes.getMember(), blockedList))
// .collect(Collectors.toList());
//
// Page<Recipe> recipes = new PageImpl<>(filteredRecipes);
return RecipeConverter.toPagingRecipeDtoList(likesRecipes, member);
}

private boolean isBlockedMember(Member recipeAuthor, List<Member> blockedMembers) {
return blockedMembers.stream()
.anyMatch(blockedMember -> blockedMember.equals(recipeAuthor));
// 내가 스크랩 누른 레시피 목록 DTO 조회
@Override
@Transactional
public RecipeResponseDto.RecipePageListDto getScrapRecipes(Integer page, Member member) {
Page<Recipe> scrapRecipes = scrapRepository.findRecipeByMember(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt")));
return RecipeConverter.toPagingRecipeDtoList(scrapRecipes, member);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ public ResponseDto<String> reportComment(@PathVariable Long recipeId, @PathVaria
return ResponseDto.of(reportedCommentId+"번 댓글이 신고되었습니다.");
}

@Operation(summary = "내가 좋아요 누른 레시피 목록 조회 API 🔑", description = "내가 좋아요 누른 레시피 목록 조회 API입니다.")
@Operation(summary = "내가 좋아요 누른 레시피 목록 조회 API 🔑", description = "내가 좋아요 누른 레시피 목록 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "2000", description = "OK, 좋아요 누른 레시피 조회 성공"),
@ApiResponse(responseCode = "4003", description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
Expand All @@ -714,18 +714,41 @@ public ResponseDto<String> reportComment(@PathVariable Long recipeId, @PathVaria
@Parameter(name = "page", description = "페이지 번호, 1부터 시작")
})
@GetMapping("/members/likeRecipes")
public ResponseDto<RecipeResponseDto.RecipePageListDto> memberRecipeList(@CheckTempMember @AuthMember Member member, @RequestParam(name = "page", required = true) @CheckPage Integer page) {
public ResponseDto<RecipeResponseDto.RecipePageListDto> 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<RecipeResponseDto.RecipePageListDto> 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;

// 1. 내가 좋아요 누른 레시피 목록 조회
// 2. 레시피 목록중 작성자가 내가 차단한 사람이면 제외
// 3. DTO List 형태로 return
return ResponseDto.of(recipeService.getScrapRecipes(page, member));
}


Expand Down

0 comments on commit ef69110

Please sign in to comment.