Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ : Feature/102 레시피 배너 도메인 추가 및 api 완성 #104

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
import org.springframework.web.multipart.MultipartFile;
//import zipdabang.server.aws.s3.AmazonS3Manager;
import zipdabang.server.aws.s3.AmazonS3Manager;
import zipdabang.server.domain.Category;
import zipdabang.server.domain.etc.Uuid;
import zipdabang.server.domain.member.Member;
import zipdabang.server.domain.recipe.*;
import zipdabang.server.repository.CategoryRepository;
import zipdabang.server.repository.recipeRepositories.*;
import zipdabang.server.web.dto.requestDto.RecipeRequestDto;
import zipdabang.server.web.dto.responseDto.RecipeResponseDto;
import zipdabang.server.web.dto.responseDto.RootResponseDto;

import javax.annotation.PostConstruct;
import java.io.IOException;
Expand All @@ -33,6 +30,7 @@ public class RecipeConverter {
private final ScrapRepository scrapRepository;
// private final CategoryRepository categoryRepository;
private final RecipeCategoryRepository recipeCategoryRepository;
private final RecipeBannerRepository recipeBannerRepository;
private final AmazonS3Manager amazonS3Manager;

private static RecipeRepository staticRecipeRepository;
Expand All @@ -43,6 +41,7 @@ public class RecipeConverter {

// private static CategoryRepository staticCategoryRepository;
private static RecipeCategoryRepository staticRecipeCategoryRepository;
private static RecipeBannerRepository staticRecipeBannerRepository;
private static AmazonS3Manager staticAmazonS3Manager;


Expand All @@ -52,6 +51,7 @@ public void init() {
this.staticRecipeCategoryMappingRepository = this.recipeCategoryMappingRepository;
// this.staticCategoryRepository = this.categoryRepository;
this.staticRecipeCategoryRepository = this.recipeCategoryRepository;
this.staticRecipeBannerRepository = this.recipeBannerRepository;
this.staticAmazonS3Manager = this.amazonS3Manager;
this.staticLikesRepository = this.likesRepository;
this.staticScrapRepository = this.scrapRepository;
Expand Down Expand Up @@ -290,4 +290,20 @@ public static RecipeResponseDto.RecipeCategoryDto toRecipeCategoryDto (RecipeCat
.build();
}

public static RecipeResponseDto.RecipeBannerImageDto toRecipeBannerImageDto(List<RecipeBanner> recipeBannerList) {
return RecipeResponseDto.RecipeBannerImageDto.builder()
.bannerList(toRecipeBannerDto(recipeBannerList))
.size(recipeBannerList.size())
.build();
}

private static List<RecipeResponseDto.RecipeBannerDto> toRecipeBannerDto(List<RecipeBanner> recipeBannerList) {
return recipeBannerList.stream()
.map(recipeBanner -> RecipeResponseDto.RecipeBannerDto.builder()
.order(recipeBanner.getInOrder())
.imageUrl(recipeBanner.getImageUrl())
.searchKeyword(recipeBanner.getSearchKeyword())
.build())
.collect(Collectors.toList());
}
}
27 changes: 27 additions & 0 deletions src/main/java/zipdabang/server/domain/recipe/RecipeBanner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package zipdabang.server.domain.recipe;

import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import zipdabang.server.domain.common.BaseEntity;

import javax.persistence.*;
import java.time.LocalDate;

@Entity
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DynamicInsert
@DynamicUpdate
public class RecipeBanner extends BaseEntity {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Integer inOrder;
private String imageUrl;
private String searchKeyword;
private LocalDate expireDate;
}
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.RecipeBanner;

public interface RecipeBannerRepository extends JpaRepository<RecipeBanner, Long> {
}
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 @@ -4,6 +4,7 @@
import org.springframework.web.multipart.MultipartFile;
import zipdabang.server.domain.member.Member;
import zipdabang.server.domain.recipe.Recipe;
import zipdabang.server.domain.recipe.RecipeBanner;
import zipdabang.server.domain.recipe.RecipeCategory;
import zipdabang.server.web.dto.requestDto.RecipeRequestDto;

Expand All @@ -12,6 +13,8 @@

public interface RecipeService {

List<RecipeBanner> getRecipeBannerList();

Recipe create(RecipeRequestDto.CreateRecipeDto request, MultipartFile thumbnail, List<MultipartFile> stepImages, Member member)throws IOException;

Recipe getRecipe(Long recipeId, Member member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import zipdabang.server.converter.RecipeConverter;
import zipdabang.server.domain.member.BlockedMember;
import zipdabang.server.domain.member.Member;
import zipdabang.server.domain.recipe.Likes;
import zipdabang.server.domain.recipe.Recipe;
import zipdabang.server.domain.recipe.RecipeCategory;
import zipdabang.server.domain.recipe.Scrap;
import zipdabang.server.domain.recipe.*;
import zipdabang.server.repository.memberRepositories.BlockedMemberRepository;
import zipdabang.server.repository.recipeRepositories.*;
import zipdabang.server.service.RecipeService;
Expand All @@ -38,6 +35,7 @@ public class RecipeServiceImpl implements RecipeService {
private final RecipeRepository recipeRepository;
private final RecipeCategoryMappingRepository recipeCategoryMappingRepository;
private final RecipeCategoryRepository recipeCategoryRepository;
private final RecipeBannerRepository recipeBannerRepository;
private final StepRepository stepRepository;
private final IngredientRepository ingredientRepository;
private final LikesRepository likesRepository;
Expand Down Expand Up @@ -214,46 +212,6 @@ public List<RecipeCategory> getAllRecipeCategories() {
return recipeCategoryRepository.findAll();
}

/*
@Override
public Page<Recipe> recipeListByCategoryAndLikes(Long categoryId, Integer pageIndex, Member member) {
List<Member> blockedMember= blockedMemberRepository.findByOwner(member).stream()
.map(blockedInfo -> blockedInfo.getBlocked())
.collect(Collectors.toList());
List<Long> recipeIdList = recipeCategoryMappingRepository.findByCategory(categoryId).stream()
.map(categoryMapping -> categoryMapping.getRecipe().getId())
.collect(Collectors.toList());
if(blockedMember.isEmpty())
return recipeRepository.findByIdIn(recipeIdList,
PageRequest.of(pageIndex, pageSize, Sort.by(Sort.Direction.DESC, "totalLike")));
else
return recipeRepository.findByIdInAndMemberNotIn(recipeIdList,blockedMember,
PageRequest.of(pageIndex, pageSize, Sort.by(Sort.Direction.DESC, "totalLike")));
}
@Override
public Page<Recipe> recipeListByCategoryAndViews(Long categoryId, Integer pageIndex, Member member) {
List<Member> blockedMember= blockedMemberRepository.findByOwner(member).stream()
.map(blockedInfo -> blockedInfo.getBlocked())
.collect(Collectors.toList());
List<Long> recipeIdList = recipeCategoryMappingRepository.findByCategory(categoryId).stream()
.map(categoryMapping -> categoryMapping.getRecipe().getId())
.collect(Collectors.toList());
if(blockedMember.isEmpty())
return recipeRepository.findByIdIn(recipeIdList,
PageRequest.of(pageIndex, pageSize, Sort.by(Sort.Direction.DESC, "totalView")));
else
return recipeRepository.findByIdInAndMemberNotIn(recipeIdList,blockedMember,
PageRequest.of(pageIndex, pageSize, Sort.by(Sort.Direction.DESC, "totalView")));
}
*/
@Override
public Page<Recipe> recipeListByCategory(Long categoryId, Integer pageIndex, Member member, String order) {

Expand Down Expand Up @@ -291,4 +249,9 @@ else if(order.equals("latest"))
return recipeRepository.findByIdInAndMemberNotIn(recipeIdList,blockedMember,
PageRequest.of(pageIndex, pageSize, Sort.by(Sort.Direction.DESC, orderBy)));
}

@Override
public List<RecipeBanner> getRecipeBannerList() {
return recipeBannerRepository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import zipdabang.server.converter.RecipeConverter;
import zipdabang.server.domain.member.Member;
import zipdabang.server.domain.recipe.Recipe;
import zipdabang.server.domain.recipe.RecipeBanner;
import zipdabang.server.domain.recipe.RecipeCategory;
import zipdabang.server.service.RecipeService;
import zipdabang.server.validation.annotation.CheckTempMember;
Expand Down Expand Up @@ -297,7 +298,7 @@ public ResponseDto<RecipeResponseDto.RecipeStatusDto> recipeLikeOrCancel(@PathVa
return ResponseDto.of(RecipeConverter.toRecipeStatusDto(recipe));
}

@Operation(summary = "레시피 배너 이미지 API 🔑", description = "레시피 화면의 배너 이미지를 가져옵니다. order는 배너 순서를 의미합니다.")
@Operation(summary = "레시피 배너 이미지 API 🔑", description = "레시피 화면의 배너 이미지를 가져옵니다. order는 배너 순서를 의미합니다.")
@ApiResponses({
@ApiResponse(responseCode = "2000",description = "OK 성공"),
@ApiResponse(responseCode = "4003",description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
Expand All @@ -308,7 +309,8 @@ public ResponseDto<RecipeResponseDto.RecipeStatusDto> recipeLikeOrCancel(@PathVa
})
@GetMapping("/members/recipes/banners")
public ResponseDto<RecipeResponseDto.RecipeBannerImageDto> showBanners() {
return null;
List<RecipeBanner> recipeBannerList = recipeService.getRecipeBannerList();
return ResponseDto.of(RecipeConverter.toRecipeBannerImageDto(recipeBannerList));
}

@Operation(summary = "레시피 카테고리 조회 API 🔑 ✔️", description = "레시피 카테고리 조회 API입니다.")
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ spring:
enabled: always

## # local redis
redis:
host: localhost

# redis:
# host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com
# host: localhost

redis:
host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com
batch:
jdbc:
initialize-schema: always
Expand Down
Loading