Skip to content

Commit

Permalink
conflict resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
CYY1007 committed Oct 3, 2023
2 parents 7e0cfb1 + 82a614f commit c6ac000
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/main/java/zipdabang/server/base/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ public enum Code {
//BAD_REQUEST
NOT_COMMENT_OWNER(HttpStatus.OK, 4108, "본인이 작성한 댓글이 아닙니다. 변경할 수 없습니다"),
//BAD_REQUEST
RECIPE_OWNER(HttpStatus.OK, 4109, "본인의 레시피입니다. 신고/차단할 수 없습니다"),
RECIPE_OWNER(HttpStatus.OK, 4109, "본인의 레시피입니다. 좋아요/스크랩/신고/차단할 수 없습니다"),
//BAD_REQUEST
COMMENT_OWNER(HttpStatus.OK, 4110, "본인의 댓글입니다. 신고/차단할 수 없습니다"),
COMMENT_OWNER(HttpStatus.OK, 4110, "본인의 댓글입니다. 좋아요/스크랩/신고/차단할 수 없습니다"),
//BAD_REQUEST
NO_TEMP_RECIPE_EXIST(HttpStatus.OK, 4111, "해당 임시저장 Id가 존재하지 않습니다."),


//INTERNAL_SERVER_ERROR
INTERNAL_ERROR(HttpStatus.OK, 5000, "Internal server Error"),
//INTERNAL_SERVER_ERROR
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ public class RecipeConverter {
private static AmazonS3Manager staticAmazonS3Manager;
private static TimeConverter staticTimeConverter;

public static RecipeResponseDto.PerCategoryPreview toPerCategoryPreview(Long categoryId, List<Recipe> recipeList, Member member) {
return RecipeResponseDto.PerCategoryPreview.builder()
.categoryId(categoryId)
.totalElements(recipeList.size())
.recipeList(recipeList.stream()
.map(recipe -> toRecipePreviewDto(recipe,member))
.collect(Collectors.toList()))
.build();
}

public static RecipeResponseDto.RecipePreviewDto toRecipePreviewDto(Recipe recipe, Member member) {
return RecipeResponseDto.RecipePreviewDto.builder()
.recipeId(recipe.getId())
.recipeName(recipe.getName())
.nickname(recipe.getMember().getNickname())
.likes(recipe.getTotalLike())
.scraps(recipe.getTotalScrap())
.isLiked(staticLikesRepository.findByRecipeAndMember(recipe, member).isPresent())
.isScrapped(staticScrapRepository.findByRecipeAndMember(recipe,member).isPresent())
.build();
}


@PostConstruct
public void init() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/zipdabang/server/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class Member extends BaseEntity {
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Inquery> inqueryList;


// 나를 따르는 놈들
@OneToMany(mappedBy = "followee", cascade = CascadeType.ALL)
private List<Follow> myFollowerList;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/zipdabang/server/service/RecipeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ public interface RecipeService {
TempRecipe tempCreate(RecipeRequestDto.TempRecipeDto request, MultipartFile thumbnail, List<MultipartFile> stepImages, Member member) throws IOException;

TempRecipe tempUpdate(Long tempId, RecipeRequestDto.TempRecipeDto request, MultipartFile thumbnail, List<MultipartFile> stepImages, Member member) throws IOException;

List<Recipe> getTop5RecipePerCategory(Long categoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import static zipdabang.server.domain.recipe.QComment.comment;
Expand Down Expand Up @@ -306,6 +307,9 @@ private List<Member> getBlockedMember(Member member) {
public Recipe updateLikeOnRecipe(Long recipeId, Member member) {
Recipe recipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST));

if(recipe.getMember() == member)
throw new RecipeException(Code.RECIPE_OWNER);

Optional<Likes> likesExist = likesRepository.findByRecipeAndMember(recipe,member);

if(likesExist.isEmpty()) {
Expand All @@ -325,6 +329,9 @@ public Recipe updateLikeOnRecipe(Long recipeId, Member member) {
public Recipe updateScrapOnRecipe(Long recipeId, Member member) {
Recipe recipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST));

if(recipe.getMember() == member)
throw new RecipeException(Code.RECIPE_OWNER);

Optional<Scrap> scrapExist = scrapRepository.findByRecipeAndMember(recipe,member);

if(scrapExist.isEmpty()) {
Expand All @@ -344,6 +351,27 @@ public List<RecipeCategory> getAllRecipeCategories() {
return recipeCategoryRepository.findAll();
}

@Override
public List<Recipe> getTop5RecipePerCategory(Long categoryId) {
QRecipe qRecipe = recipe;
QRecipeCategoryMapping qRecipeCategoryMapping = recipeCategoryMapping;

AtomicLong index = new AtomicLong(1);
List<Recipe> 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());

return recipeList;
}

@Override
public Page<Recipe> recipeListByCategory(Long categoryId, Integer pageIndex, Member member, String order) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package zipdabang.server.validation.annotation;


import zipdabang.server.validation.validator.ExistRecipeCategoryValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

@Documented
@Constraint(validatedBy = ExistRecipeCategoryValidator.class)
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface ExistRecipeCategory {
String message() default "범위에 없는 categoryId를 전달했습니다.";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package zipdabang.server.validation.validator;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import zipdabang.server.base.Code;
import zipdabang.server.domain.recipe.RecipeCategory;
import zipdabang.server.repository.recipeRepositories.RecipeCategoryRepository;
import zipdabang.server.validation.annotation.ExistRecipeCategory;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Optional;

@Component
@RequiredArgsConstructor
public class ExistRecipeCategoryValidator implements ConstraintValidator<ExistRecipeCategory,Long> {

private final RecipeCategoryRepository recipeCategoryRepository;

@Override
public void initialize(ExistRecipeCategory constraintAnnotation) {
ConstraintValidator.super.initialize(constraintAnnotation);
}

@Override
public boolean isValid(Long value, ConstraintValidatorContext context) {
Optional<RecipeCategory> findRecipeCategory = recipeCategoryRepository.findById(value);
if(findRecipeCategory.isEmpty()){
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(Code.NO_RECIPE_CATEGORY_EXIST.toString()).addConstraintViolation();
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ public ResponseDto<MemberResponseDto.TempLoginDto> tempLogin() {
@Parameters({
@Parameter(name = "member", hidden = true),
})
@PostMapping(value = "/members/inquiries",consumes ={ MediaType.MULTIPART_FORM_DATA_VALUE } )
public ResponseDto<MemberResponseDto.MemberInqueryResultDto> createInquery(@CheckTempMember @AuthMember Member member, @ModelAttribute @Valid MemberRequestDto.InqueryDto request){
@PostMapping(value = "/members/inquiries", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseDto<MemberResponseDto.MemberInqueryResultDto> createInquery(@CheckTempMember @AuthMember Member member, @ModelAttribute @Valid MemberRequestDto.InqueryDto request) {
Inquery inquery = memberService.createInquery(member, request);
return ResponseDto.of(MemberConverter.toMemberInqueryResultDto(inquery));
}
Expand All @@ -333,11 +333,12 @@ public ResponseDto<MemberResponseDto.MemberInqueryResultDto> createInquery(@Chec
@ApiResponse(responseCode = "4055", description = "BAD_REQEUST , 페이지 번호가 초과함", content = @Content(schema = @Schema(implementation = ResponseDto.class))),

})
public ResponseDto<MemberResponseDto.InqueryListDto> showInquery(@CheckTempMember @AuthMember Member member, @RequestParam(name = "page",required = true) @CheckPage Integer page){
public ResponseDto<MemberResponseDto.InqueryListDto> showInquery(@CheckTempMember @AuthMember Member member, @RequestParam(name = "page", required = true) @CheckPage Integer page) {
Page<Inquery> inqueryPage = memberService.findInquery(member, page);
return ResponseDto.of(MemberConverter.toInqueryListDto(inqueryPage));
}
@Operation(summary = "[figma 더보기 - 회원 탈퇴] 회원 탈퇴 API ✔️🔑", description = "회원 탈퇴 API입니다.<br> 테스트를 위해 임시로 해당 유저의 상세주소를 \"TEST\" 로 설정하면(상세정보 수정 API - zipCode) 탈퇴 불가능한 경우로 처리되도록 해놨습니다.<br> deregisterTypes 종류 <br>"+

@Operation(summary = "[figma 더보기 - 회원 탈퇴] 회원 탈퇴 API ✔️🔑", description = "회원 탈퇴 API입니다.<br> 테스트를 위해 임시로 해당 유저의 상세주소를 \"TEST\" 로 설정하면(상세정보 수정 API - zipCode) 탈퇴 불가능한 경우로 처리되도록 해놨습니다.<br> deregisterTypes 종류 <br>" +
"- NOTHING_TO_BUY(\"사고싶은 물건이 없어요.\"),<br>" +
"- DISINTERESTED(\"앱을 이용하지 않아요.\"),<br>" +
"- UNCOMFORTABLE(\"앱 이용이 불편해요.\"),<br>" +
Expand Down Expand Up @@ -413,6 +414,7 @@ else if (page < 1)
}



@Operation(summary = "🎪팔로우하기/취소하기 API", description = "팔로우하기 API 입니다.")
@PostMapping("/members/followings/{targetId}")
@Parameters({
Expand Down Expand Up @@ -458,3 +460,4 @@ public ResponseDto<MemberResponseDto.FollowerListDto> getFollowerMember(@CheckPa
return ResponseDto.of(MemberConverter.toFollowerListDto(follower, member));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.view.RedirectView;
import zipdabang.server.auth.handler.annotation.AuthMember;
import zipdabang.server.base.Code;
import zipdabang.server.base.ResponseDto;
Expand All @@ -24,6 +23,7 @@
import zipdabang.server.domain.recipe.*;
import zipdabang.server.service.RecipeService;
import zipdabang.server.validation.annotation.CheckTempMember;
import zipdabang.server.validation.annotation.ExistRecipeCategory;
import zipdabang.server.web.dto.requestDto.RecipeRequestDto;
import zipdabang.server.web.dto.responseDto.RecipeResponseDto;

Expand Down Expand Up @@ -192,10 +192,7 @@ public ResponseDto<RecipeResponseDto.SearchRecipePreviewListDto> searchRecipePre
@Parameter(name = "keyword", description = "query string 검색할 단어")
})
@GetMapping(value = "/members/recipes/search/{categoryId}")
public ResponseDto<RecipeResponseDto.RecipePageListDto> searchRecipe(@PathVariable Long categoryId, @RequestParam(name = "keyword") String keyword, @RequestParam(name = "pageIndex", required = false) Integer pageIndex, @AuthMember Member member) {

if (recipeService.checkRecipeCategoryExist(categoryId) == false)
throw new RecipeException(Code.NO_RECIPE_CATEGORY_EXIST);
public ResponseDto<RecipeResponseDto.RecipePageListDto> searchRecipe(@ExistRecipeCategory @PathVariable Long categoryId, @RequestParam(name = "keyword") String keyword, @RequestParam(name = "pageIndex", required = false) Integer pageIndex, @AuthMember Member member) {

if (pageIndex == null)
pageIndex = 1;
Expand All @@ -214,6 +211,31 @@ else if (pageIndex < 1)
return ResponseDto.of(RecipeConverter.toPagingRecipeDtoList(recipes, member));
}

@Operation(summary = "🍹figma 레시피2, 레시피 카테고리 별 top5 화면 API 🔑 ✔", description = "레시피 카테고리별 top5 조회 화면 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "2000", description = "OK, 목록이 있을 땐 이 응답임"),
@ApiResponse(responseCode = "2100", 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))),
@ApiResponse(responseCode = "4052", description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4105", description = "BAD_REQUEST, 해당 id를 가진 레시피 카테고리가 없습니다. 잘못 보내줬어요", 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),
})
@GetMapping(value = "/members/recipes/categories/{categoryId}/top5")
public ResponseDto<RecipeResponseDto.PerCategoryPreview> RecipeCategoryTop5(@ExistRecipeCategory @PathVariable Long categoryId, @AuthMember Member member) {

List<Recipe> recipeList = recipeService.getTop5RecipePerCategory(categoryId);

log.info(recipeList.toString());

return ResponseDto.of(RecipeConverter.toPerCategoryPreview(categoryId, recipeList ,member));
}

@Operation(summary = "🍹figma 레시피2, 카테고리 별 레시피 목록 조회 API 🔑 ✔", description = "카테고리 별 레시피 목록 조회 화면 API입니다. pageIndex로 페이징")
@ApiResponses({
@ApiResponse(responseCode = "2000", description = "OK, 목록이 있을 땐 이 응답임"),
Expand All @@ -235,10 +257,7 @@ else if (pageIndex < 1)
@Parameter(name = "order", description = "query string 조회 방식. 인기순: likes, 조회순: views, 최신순: latest로 넘겨주세요, 기본값 latest")
})
@GetMapping(value = "/members/recipes/categories/{categoryId}")
public ResponseDto<RecipeResponseDto.RecipePageListDto> recipeListByCategory(@PathVariable Long categoryId, @RequestParam(name = "order", required = false) String order, @RequestParam(name = "pageIndex", required = false) Integer pageIndex, @AuthMember Member member) {

if (recipeService.checkRecipeCategoryExist(categoryId) == false)
throw new RecipeException(Code.NO_RECIPE_CATEGORY_EXIST);
public ResponseDto<RecipeResponseDto.RecipePageListDto> recipeListByCategory(@ExistRecipeCategory @PathVariable Long categoryId, @RequestParam(name = "order", required = false) String order, @RequestParam(name = "pageIndex", required = false) Integer pageIndex, @AuthMember Member member) {

if (pageIndex == null)
pageIndex = 1;
Expand Down Expand Up @@ -337,6 +356,7 @@ public ResponseDto<RecipeResponseDto.RecipeListDto> recipeWeekBest(@AuthMember M
@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 = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4109", description = "BAD_REQUEST, 본인의 레시피입니다. 좋아요/스크랩할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@Parameters({
Expand All @@ -357,6 +377,7 @@ public ResponseDto<RecipeResponseDto.RecipeStatusDto> recipeScrapOrCancel(@PathV
@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 = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4109", description = "BAD_REQUEST, 본인의 레시피입니다. 좋아요/스크랩할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@Parameters({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ public static class TempRecipeStatusDto{
private String calledAt;
}

@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class PerCategoryPreview{
private List<RecipePreviewDto> recipeList;
private Long categoryId;
private Integer totalElements;
}

@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class RecipePreviewDto {
private Long recipeId;
private String recipeName;
private String nickname;
private String thumbnailUrl;
private Long likes;
private Long scraps;
private Boolean isLiked;
private Boolean isScrapped;
}

@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down

0 comments on commit c6ac000

Please sign in to comment.