diff --git a/src/main/java/zipdabang/server/converter/RecipeConverter.java b/src/main/java/zipdabang/server/converter/RecipeConverter.java index 69409d5..373c76c 100644 --- a/src/main/java/zipdabang/server/converter/RecipeConverter.java +++ b/src/main/java/zipdabang/server/converter/RecipeConverter.java @@ -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; @@ -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; @@ -43,6 +41,7 @@ public class RecipeConverter { // private static CategoryRepository staticCategoryRepository; private static RecipeCategoryRepository staticRecipeCategoryRepository; + private static RecipeBannerRepository staticRecipeBannerRepository; private static AmazonS3Manager staticAmazonS3Manager; @@ -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; @@ -290,4 +290,20 @@ public static RecipeResponseDto.RecipeCategoryDto toRecipeCategoryDto (RecipeCat .build(); } + public static RecipeResponseDto.RecipeBannerImageDto toRecipeBannerImageDto(List recipeBannerList) { + return RecipeResponseDto.RecipeBannerImageDto.builder() + .bannerList(toRecipeBannerDto(recipeBannerList)) + .size(recipeBannerList.size()) + .build(); + } + + private static List toRecipeBannerDto(List recipeBannerList) { + return recipeBannerList.stream() + .map(recipeBanner -> RecipeResponseDto.RecipeBannerDto.builder() + .order(recipeBanner.getInOrder()) + .imageUrl(recipeBanner.getImageUrl()) + .searchKeyword(recipeBanner.getSearchKeyword()) + .build()) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/zipdabang/server/domain/recipe/RecipeBanner.java b/src/main/java/zipdabang/server/domain/recipe/RecipeBanner.java new file mode 100644 index 0000000..579874b --- /dev/null +++ b/src/main/java/zipdabang/server/domain/recipe/RecipeBanner.java @@ -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; +} diff --git a/src/main/java/zipdabang/server/repository/recipeRepositories/RecipeBannerRepository.java b/src/main/java/zipdabang/server/repository/recipeRepositories/RecipeBannerRepository.java new file mode 100644 index 0000000..5be7451 --- /dev/null +++ b/src/main/java/zipdabang/server/repository/recipeRepositories/RecipeBannerRepository.java @@ -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 { +} diff --git a/src/main/java/zipdabang/server/service/RecipeService.java b/src/main/java/zipdabang/server/service/RecipeService.java index cec358f..e6f90b4 100644 --- a/src/main/java/zipdabang/server/service/RecipeService.java +++ b/src/main/java/zipdabang/server/service/RecipeService.java @@ -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; @@ -12,6 +13,8 @@ public interface RecipeService { + List getRecipeBannerList(); + Recipe create(RecipeRequestDto.CreateRecipeDto request, MultipartFile thumbnail, List stepImages, Member member)throws IOException; Recipe getRecipe(Long recipeId, Member member); diff --git a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java index 98f5469..9d2a589 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java @@ -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; @@ -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; @@ -214,46 +212,6 @@ public List getAllRecipeCategories() { return recipeCategoryRepository.findAll(); } - /* - @Override - public Page recipeListByCategoryAndLikes(Long categoryId, Integer pageIndex, Member member) { - - List blockedMember= blockedMemberRepository.findByOwner(member).stream() - .map(blockedInfo -> blockedInfo.getBlocked()) - .collect(Collectors.toList()); - - List 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 recipeListByCategoryAndViews(Long categoryId, Integer pageIndex, Member member) { - - List blockedMember= blockedMemberRepository.findByOwner(member).stream() - .map(blockedInfo -> blockedInfo.getBlocked()) - .collect(Collectors.toList()); - - List 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 recipeListByCategory(Long categoryId, Integer pageIndex, Member member, String order) { @@ -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 getRecipeBannerList() { + return recipeBannerRepository.findAll(); + } } diff --git a/src/main/java/zipdabang/server/web/controller/RecipeController.java b/src/main/java/zipdabang/server/web/controller/RecipeController.java index 0160a7d..4f173f1 100644 --- a/src/main/java/zipdabang/server/web/controller/RecipeController.java +++ b/src/main/java/zipdabang/server/web/controller/RecipeController.java @@ -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; @@ -297,7 +298,7 @@ public ResponseDto 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))), @@ -308,7 +309,8 @@ public ResponseDto recipeLikeOrCancel(@PathVa }) @GetMapping("/members/recipes/banners") public ResponseDto showBanners() { - return null; + List recipeBannerList = recipeService.getRecipeBannerList(); + return ResponseDto.of(RecipeConverter.toRecipeBannerImageDto(recipeBannerList)); } @Operation(summary = "레시피 카테고리 조회 API 🔑 ✔️", description = "레시피 카테고리 조회 API입니다.") diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4e5bf01..5dd9984 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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