Skip to content

Commit

Permalink
Merge pull request #167 from zipdabang/feature/160
Browse files Browse the repository at this point in the history
Feature/160 ✨ ♻️ 레시피 관련 수정 요구사항 반영
  • Loading branch information
Hanvp authored Oct 6, 2023
2 parents f44917e + 25674d8 commit 2abff86
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 197 deletions.
30 changes: 0 additions & 30 deletions src/main/java/zipdabang/server/apiPayload/code/CommonStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ public enum CommonStatus implements BaseCode {



//recipe response
RECIPE_NOT_FOUND(HttpStatus.OK, 2100, "조회된 목록이 없습니다"),

// market response

WATCHED_NOT_FOUND(HttpStatus.OK, 2150, "조회했던 아이템이 없습니다."),
Expand Down Expand Up @@ -97,33 +94,6 @@ public enum CommonStatus implements BaseCode {

// market error

//recipe error

//BAD_REQUEST
NULL_RECIPE_ERROR(HttpStatus.OK, 4100, "레시피 작성시 누락된 내용이 있습니다."),
//BAD_REQUEST
NO_RECIPE_EXIST(HttpStatus.OK, 4101, "해당 레시피가 존재하지 않습니다."),
//BAD_REQUEST
BLOCKED_USER_RECIPE(HttpStatus.OK, 4102, "차단한 사용자의 레시피입니다."),
//BAD_REQUEST
WRITTEN_BY_TYPE_ERROR(HttpStatus.OK, 4103, "레시피 작성자 타입이 잘못되었습니다. all, influencer, common중 하나로 보내주세요."),
//BAD_REQUEST
ORDER_BY_TYPE_ERROR(HttpStatus.OK, 4104, "조회 방식 타입이 잘못되었습니다. likes, views, latest중 하나로 보내주세요."),
//BAD_REQUEST
NO_RECIPE_CATEGORY_EXIST(HttpStatus.OK, 4105, "해당 id를 가진 레시피 카테고리가 없습니다. 잘못 보내줬어요"),
//BAD_REQUEST
NOT_RECIPE_OWNER(HttpStatus.OK, 4106, "본인이 작성한 레시피가 아닙니다. 변경할 수 없습니다"),
//BAD_REQUEST
NO_COMMENT_EXIST(HttpStatus.OK, 4107, "해당 댓글이 존재하지 않습니다."),
//BAD_REQUEST
NOT_COMMENT_OWNER(HttpStatus.OK, 4108, "본인이 작성한 댓글이 아닙니다. 변경할 수 없습니다"),
//BAD_REQUEST
RECIPE_OWNER(HttpStatus.OK, 4109, "본인의 레시피입니다. 좋아요/스크랩/신고/차단할 수 없습니다"),
//BAD_REQUEST
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"),
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/zipdabang/server/apiPayload/code/RecipeStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package zipdabang.server.apiPayload.code;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum RecipeStatus implements BaseCode{

RECIPE_NOT_FOUND(HttpStatus.OK, 2100, "조회된 목록이 없습니다"),

//BAD_REQUEST
NULL_RECIPE_ERROR(HttpStatus.OK, 4100, "레시피 작성시 누락된 내용이 있습니다."),
//BAD_REQUEST
NO_RECIPE_EXIST(HttpStatus.OK, 4101, "해당 레시피가 존재하지 않습니다."),
//BAD_REQUEST
BLOCKED_USER_RECIPE(HttpStatus.OK, 4102, "차단한 사용자의 레시피입니다."),
//BAD_REQUEST
WRITTEN_BY_TYPE_ERROR(HttpStatus.OK, 4103, "레시피 작성자 타입이 잘못되었습니다. all, influencer, common중 하나로 보내주세요."),
//BAD_REQUEST
ORDER_BY_TYPE_ERROR(HttpStatus.OK, 4104, "조회 방식 타입이 잘못되었습니다. likes, views, latest중 하나로 보내주세요."),
//BAD_REQUEST
NO_RECIPE_CATEGORY_EXIST(HttpStatus.OK, 4105, "해당 id를 가진 레시피 카테고리가 없습니다. 잘못 보내줬어요"),
//BAD_REQUEST
NOT_RECIPE_OWNER(HttpStatus.OK, 4106, "본인이 작성한 레시피가 아닙니다. 변경할 수 없습니다"),
//BAD_REQUEST
NO_COMMENT_EXIST(HttpStatus.OK, 4107, "해당 댓글이 존재하지 않습니다."),
//BAD_REQUEST
NOT_COMMENT_OWNER(HttpStatus.OK, 4108, "본인이 작성한 댓글이 아닙니다. 변경할 수 없습니다"),
//BAD_REQUEST
RECIPE_OWNER(HttpStatus.OK, 4109, "본인의 레시피입니다. 좋아요/스크랩/신고/차단할 수 없습니다"),
//BAD_REQUEST
COMMENT_OWNER(HttpStatus.OK, 4110, "본인의 댓글입니다. 좋아요/스크랩/신고/차단할 수 없습니다"),
//BAD_REQUEST
NO_TEMP_RECIPE_EXIST(HttpStatus.OK, 4111, "해당 임시저장 Id가 존재하지 않습니다.");

private final HttpStatus httpStatus;
private final Integer code;
private final String message;

@Override
public Reason getReason() {
return Reason.builder()
.message(message)
.code(code)
.isSuccess((code >= 2000 && code < 3000) ? true : false)
.build();
}

@Override
public Reason getReasonHttpStatus() {
return Reason.builder()
.message(message)
.code(code)
.isSuccess((code >= 2000 && code < 3000) ? true : false)
.httpStatus(httpStatus)
.build()
;
}
}
49 changes: 41 additions & 8 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.web.multipart.MultipartFile;
//import zipdabang.server.aws.s3.AmazonS3Manager;
import zipdabang.server.apiPayload.code.CommonStatus;
import zipdabang.server.apiPayload.code.RecipeStatus;
import zipdabang.server.aws.s3.AmazonS3Manager;
import zipdabang.server.apiPayload.exception.handler.RecipeException;
import zipdabang.server.domain.Report;
Expand All @@ -22,6 +23,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -60,24 +62,28 @@ public class RecipeConverter {
private static TimeConverter staticTimeConverter;

public static RecipeResponseDto.PerCategoryPreview toPerCategoryPreview(Long categoryId, List<Recipe> recipeList, Member member) {

AtomicInteger index = new AtomicInteger(1);

return RecipeResponseDto.PerCategoryPreview.builder()
.categoryId(categoryId)
.totalElements(recipeList.size())
.recipeList(recipeList.stream()
.map(recipe -> toRecipePreviewDto(recipe,member))
.map(recipe -> toRecipePreviewDto(recipe,member, index.getAndIncrement()))
.collect(Collectors.toList()))
.build();
}

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

Expand Down Expand Up @@ -110,6 +116,32 @@ public static RecipeResponseDto.RecipePageListDto toPagingRecipeDtoList(Page<Rec

}

public static RecipeResponseDto.WeekBestDtoList toWeekBestDtoList(List<WeeklyBestRecipe> bestRecipes, Member member) {
return RecipeResponseDto.WeekBestDtoList.builder()
.recipeList(bestRecipes.stream()
.map(bestRecipe -> toResponseWeekBestDto(bestRecipe.getRecipe(), member, bestRecipe.getRanking()))
.collect(Collectors.toList()))
.totalElements(bestRecipes.size())
.build();
}

private static RecipeResponseDto.RecipeSimpleDtoBest toResponseWeekBestDto(Recipe recipe, Member member, Integer rank) {
return RecipeResponseDto.RecipeSimpleDtoBest.builder()
.rank(rank)
.recipeId(recipe.getId())
.recipeName(recipe.getName())
.nickname(recipe.getMember().getNickname())
.thumbnailUrl(recipe.getThumbnailUrl())
.createdAt(staticTimeConverter.ConvertTime(recipe.getCreatedAt()))
.updatedAt(staticTimeConverter.ConvertTime(recipe.getUpdatedAt()))
.likes(recipe.getTotalLike())
.comments(recipe.getTotalComments())
.scraps(recipe.getTotalScrap())
.isLiked(staticLikesRepository.findByRecipeAndMember(recipe, member).isPresent())
.isScrapped(staticScrapRepository.findByRecipeAndMember(recipe,member).isPresent())
.build();
}

public static RecipeResponseDto.RecipeListDto toPreviewRecipeDtoList(List<Recipe> recipes, Member member) {
return RecipeResponseDto.RecipeListDto.builder()
.recipeList(recipes.stream()
Expand Down Expand Up @@ -159,7 +191,7 @@ public static List<Step> toStep(RecipeRequestDto.CreateRecipeDto request, Recipe
return request.getSteps().stream()
.map(step-> {
if (step.getDescription() == null)
throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR);
throw new RecipeException(RecipeStatus.NULL_RECIPE_ERROR);
try {
return toStepDto(step, recipe, stepImages);
} catch (IOException e) {
Expand Down Expand Up @@ -217,6 +249,7 @@ public static RecipeResponseDto.TempRecipeStatusDto toTempRecipeStatusDto(TempRe
public static RecipeResponseDto.RecipeInfoDto toRecipeInfoDto(Recipe recipe, Boolean isOwner, Boolean isLiked, Boolean isScrapped, Member member) {
return RecipeResponseDto.RecipeInfoDto.builder()
.recipeInfo(toResponseRecipeDto(recipe, isLiked, isScrapped, member))
.ownerId(recipe.getMember().getMemberId())
.isOwner(isOwner)
.steps(toResponseStepDto(recipe))
.ingredients(toResponseIngredientDto(recipe))
Expand Down Expand Up @@ -274,7 +307,7 @@ public static RecipeResponseDto.RecipeDto toResponseRecipeDto(Recipe recipe, Boo
public static Recipe toRecipe(RecipeRequestDto.CreateRecipeDto request, MultipartFile thumbnail, Member member) throws IOException {

Recipe recipe = Recipe.builder()
.isInfluencer(member.isInfluencer())
.isBarista(member.isBarista())
.name(request.getName())
.intro(request.getIntro())
.recipeTip(request.getRecipeTip())
Expand All @@ -286,7 +319,7 @@ public static Recipe toRecipe(RecipeRequestDto.CreateRecipeDto request, Multipar
if(thumbnail != null)
imageUrl = uploadThumbnail(thumbnail);
else
throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR);
throw new RecipeException(RecipeStatus.NULL_RECIPE_ERROR);
recipe.setThumbnail(imageUrl);

return recipe;
Expand All @@ -295,7 +328,7 @@ public static Recipe toRecipe(RecipeRequestDto.CreateRecipeDto request, Multipar
public static TempRecipe toTempRecipe(RecipeRequestDto.TempRecipeDto request, MultipartFile thumbnail, Member member) throws IOException {

TempRecipe tempRecipe = TempRecipe.builder()
.isInfluencer(member.isInfluencer())
.isBarista(member.isBarista())
.name(request.getName())
.intro(request.getIntro())
.recipeTip(request.getRecipeTip())
Expand Down Expand Up @@ -349,7 +382,7 @@ private static Step toStepDto(RecipeRequestDto.StepDto step, Recipe recipe, List
if(stepImages != null)
imageUrl = uploadStepImage(stepImage);
else
throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR);
throw new RecipeException(RecipeStatus.NULL_RECIPE_ERROR);
createdStep.setImage(imageUrl);

return createdStep;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/zipdabang/server/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Member extends BaseEntity {
private GenderType gender;

@Column(columnDefinition = "boolean default false")
private boolean isInfluencer;
private boolean isBarista;

@Column(length = 5)
private String zipCode;
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/zipdabang/server/domain/recipe/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public class Recipe extends BaseEntity {
private Long id;

@Column(nullable = false)
private Boolean isInfluencer;
private Boolean isBarista;

@Column(nullable = false)
private Boolean isOfficial;

@Column(nullable = false)
private String name;
Expand All @@ -43,8 +46,9 @@ public class Recipe extends BaseEntity {
@Column(nullable = false)
private String time;

@Column(columnDefinition = "FLOAT DEFAULT 0")
private Float starScore;
@Column(columnDefinition = "BIGINT DEFAULT 0")
private Long totalComments;

@Column(columnDefinition = "BIGINT DEFAULT 0")
private Long totalView;

Expand Down Expand Up @@ -96,6 +100,11 @@ public Recipe setThumbnail(String imageUrl) {
return this;
}

public Recipe updateComment(Integer i) {
this.totalComments += i;
return this;
}

public Recipe updateLike(Integer i){
this.weekLike += i;
this.totalLike += i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TempRecipe extends BaseEntity {
private Long id;

@Column(nullable = false)
private Boolean isInfluencer;
private Boolean isBarista;

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,8 @@
import java.util.Optional;

public interface RecipeRepository extends JpaRepository<Recipe, Long> {
List<Recipe> findTop5ByMemberNotInOrderByCreatedAtDesc(List<Member> members);
List<Recipe> findTop5ByIsInfluencerTrueAndMemberNotInOrderByCreatedAtDesc(List<Member> members);
List<Recipe> findTop5ByIsInfluencerFalseAndMemberNotInOrderByCreatedAtDesc(List<Member> members);

List<Recipe> findTop5ByOrderByCreatedAtDesc();

List<Recipe> findTop5ByIsInfluencerTrueOrderByCreatedAtDesc();

List<Recipe> findTop5ByIsInfluencerFalseOrderByCreatedAtDesc();

Page<Recipe> findByIdIn(List<Long> recipeIdList, PageRequest createdAt);

Page<Recipe> findByIdInAndMemberNotIn(List<Long> recipeIdList, List<Member> blockedMember, PageRequest createdAt);

List<Recipe> findTop5ByIdInAndNameContainingOrderByCreatedAtDesc(List<Long> recipeIdList, String keyword);

List<Recipe> findTop5ByIdInAndNameContainingAndMemberNotInOrderByCreatedAtDesc(List<Long> recipeIdList, String keyword, List<Member> blockedMember);

Page<Recipe> findByIdInAndNameContaining(List<Long> recipeIdList, String keyword, PageRequest createdAt);

Page<Recipe> findByIdInAndNameContainingAndMemberNotIn(List<Long> recipeIdList, String keyword, List<Member> blockedMember, PageRequest createdAt);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package zipdabang.server.repository.recipeRepositories;

import org.springframework.data.jpa.repository.JpaRepository;
import zipdabang.server.domain.recipe.WeeklyBestRecipe;

public interface WeeklyBestRecipeRepository extends JpaRepository<WeeklyBestRecipe, Long> {
}
6 changes: 6 additions & 0 deletions src/main/java/zipdabang/server/service/RecipeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ public interface RecipeService {
TempRecipe tempUpdate(Long tempId, RecipeRequestDto.TempRecipeDto request, MultipartFile thumbnail, List<MultipartFile> stepImages, Member member) throws IOException;

List<Recipe> getTop5RecipePerCategory(Long categoryId);

List<Recipe> getRecipeByOwnerPreview(Long memberId);

Page<Recipe> getRecipeByOwner(Integer pageIndex, Long memberId);

List<WeeklyBestRecipe> WeekBestRecipe();
}
Loading

0 comments on commit 2abff86

Please sign in to comment.