Skip to content

Commit

Permalink
Wkzb 398 โœจ ๐Ÿ› ๋‚ด๊ฐ€ ์ข‹์•„์š”/์Šคํฌ๋žฉํ•œ ๋ ˆ์‹œํ”ผ ์กฐํšŒ, ์ฐจ๋‹จ ์œ ์ € ๋ชฉ๋ก ์กฐํšŒ API ์—๋Ÿฌ ์ˆ˜์ • (#171)
Browse files Browse the repository at this point in the history
* ๐Ÿ› ๋‚ด๊ฐ€ ์ฐจ๋‹จํ•œ ์œ ์ € ์กฐํšŒ ์ฟผ๋ฆฌ๋ฌธ ์ˆ˜์ •

* โœจ ๋‚ด๊ฐ€ ์ข‹์•„์š” ๋ˆ„๋ฅธ ๋ ˆ์‹œํ”ผ ์กฐํšŒ API

* โœจ ๋‚ด๊ฐ€ ์Šคํฌ๋žฉํ•œ ๋ ˆ์‹œํ”ผ ์กฐํšŒ API
  • Loading branch information
HyoBN authored Oct 8, 2023
1 parent ed8fd75 commit d651f1a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public static RecipeResponseDto.RecipePageListDto toPagingRecipeDtoList(Page<Rec
.isFirst(recipes.isFirst())
.isLast(recipes.isLast())
.build();

}

public static RecipeResponseDto.WeekBestDtoList toWeekBestDtoList(List<WeeklyBestRecipe> bestRecipes, Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -13,8 +14,10 @@
public interface BlockedMemberRepository extends JpaRepository<BlockedMember, Long> {
List<BlockedMember> findByOwner(Member owner);

@Query("select b.blocked from BlockedMember b")
Page<Member> findBlockedByOwner(Member owner, PageRequest pageRequest);
@Query("select b.blocked from BlockedMember b where b.owner = :owner ")
List<Member> findBlockedByOwner(Member owner);
@Query("select b.blocked from BlockedMember b where b.owner = :owner ")
Page<Member> findBlockedByOwner(@Param("owner") Member owner, PageRequest pageRequest);
Optional<BlockedMember> findByOwnerAndBlocked(Member owner, Member blocked);

boolean existsByOwnerAndBlocked(Member owner, Member blocked);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,5 +14,8 @@

public interface LikesRepository extends JpaRepository<Likes, Long> {

@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<Recipe> findRecipeByMember(@Param("owner") Member owner, PageRequest pageRequest);

Optional<Likes> findByRecipeAndMember(Recipe recipe, Member member);
}
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);

}
3 changes: 3 additions & 0 deletions src/main/java/zipdabang/server/service/RecipeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -370,7 +371,7 @@ else if (writtenby.equals("official"))
private BooleanExpression blockedMemberNotInForRecipe(Member member) {
List<Member> blockedMember = getBlockedMember(member);

return blockedMember.isEmpty() ? null : recipe.member.notIn(blockedMember);
return blockedMember.isEmpty() ? null : recipe.member.notIn(blockedMember);
}

private List<Member> getBlockedMember(Member member) {
Expand Down Expand Up @@ -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<Recipe> 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<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 @@ -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;
Expand Down Expand Up @@ -696,4 +697,80 @@ public ResponseDto<String> 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<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;

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 d651f1a

Please sign in to comment.