diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/carousel/domain/service/CarouselManagerService.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/carousel/domain/service/CarouselManagerService.java index 1c51ea0d..4bb8a6f0 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/carousel/domain/service/CarouselManagerService.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/carousel/domain/service/CarouselManagerService.java @@ -2,6 +2,8 @@ import java.util.List; +import com.depromeet.breadmapbackend.domain.admin.carousel.domain.CarouselManager; +import com.depromeet.breadmapbackend.domain.admin.carousel.domain.CarouselType; import com.depromeet.breadmapbackend.domain.admin.carousel.domain.dto.command.CreateCarouselCommand; import com.depromeet.breadmapbackend.domain.admin.carousel.domain.dto.command.UpdateCarouselOrderCommand; import com.depromeet.breadmapbackend.domain.admin.post.domain.dto.info.CarouselInfo; @@ -22,4 +24,6 @@ public interface CarouselManagerService { List getCarousels(); void toggleCarousel(final Long carouselId, final boolean isCarousel); + + CarouselManager getCarouselByTargetIdAndCarouselType(final Long carouselId, final CarouselType carouselType); } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/carousel/domain/service/CarouselManagerServiceImpl.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/carousel/domain/service/CarouselManagerServiceImpl.java index 7c632015..a2abe7d3 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/carousel/domain/service/CarouselManagerServiceImpl.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/carousel/domain/service/CarouselManagerServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.transaction.annotation.Transactional; import com.depromeet.breadmapbackend.domain.admin.carousel.domain.CarouselManager; +import com.depromeet.breadmapbackend.domain.admin.carousel.domain.CarouselType; import com.depromeet.breadmapbackend.domain.admin.carousel.domain.dto.command.CreateCarouselCommand; import com.depromeet.breadmapbackend.domain.admin.carousel.domain.dto.command.UpdateCarouselOrderCommand; import com.depromeet.breadmapbackend.domain.admin.carousel.repository.CarouselRepository; @@ -96,6 +97,15 @@ public void toggleCarousel(final Long carouselId, final boolean isCarousel) { }); } + @Override + public CarouselManager getCarouselByTargetIdAndCarouselType( + final Long carouselId, + final CarouselType carouselType + ) { + return carouselRepository.findByTargetIdAndCarouselType(carouselId, carouselType) + .orElseThrow(() -> new DaedongException(DaedongStatus.CAROUSEL_NOT_FOUND)); + } + @Override public List getCarousels() { return carouselRepository.findByCarouseledIsOrderByCarouselOrderAsc(true) diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/feed/service/CurationFeedService.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/feed/service/CurationFeedService.java index b8741c53..14e69c22 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/feed/service/CurationFeedService.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/feed/service/CurationFeedService.java @@ -8,6 +8,9 @@ import com.depromeet.breadmapbackend.domain.admin.Admin; import com.depromeet.breadmapbackend.domain.admin.AdminRepository; +import com.depromeet.breadmapbackend.domain.admin.carousel.domain.CarouselType; +import com.depromeet.breadmapbackend.domain.admin.carousel.domain.dto.command.CreateCarouselCommand; +import com.depromeet.breadmapbackend.domain.admin.carousel.domain.service.CarouselManagerService; import com.depromeet.breadmapbackend.domain.admin.category.domain.Category; import com.depromeet.breadmapbackend.domain.admin.category.repository.CategoryRepository; import com.depromeet.breadmapbackend.domain.admin.feed.domain.CurationBakery; @@ -42,6 +45,7 @@ public class CurationFeedService implements FeedService { private final CategoryRepository categoryRepository; private final ProductRepository productRepository; private final FlagBakeryRepository flagBakeryRepository; + private final CarouselManagerService carouselManagerService; @Transactional @Override @@ -58,6 +62,16 @@ public Long addFeed(Long adminId, FeedRequestDto requestDto) { feed.addAll(bakeries, curationBakeries); CurationFeed newFeed = repository.save(feed); + + carouselManagerService.saveCarousel( + new CreateCarouselCommand( + CarouselType.CURATION, + newFeed.getId(), + requestDto.getCommon().getThumbnailUrl(), + true + ) + ); + return newFeed.getId(); } @@ -74,6 +88,9 @@ public void updateFeed(Long adminId, Long feedId, FeedRequestDto updateDto) { List curationBakeries = FeedAssembler.toCurationBakery(feed, bakeries, updateDto); feed.update(updateFeed, bakeries, curationBakeries); + + carouselManagerService.getCarouselByTargetIdAndCarouselType(feedId, CarouselType.CURATION) + .updateBannerImage(updateDto.getCommon().getThumbnailUrl()); } @Override diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/bakery/ranking/ScoredBakeryJpaRepository.java b/src/main/java/com/depromeet/breadmapbackend/domain/bakery/ranking/ScoredBakeryJpaRepository.java index cbc85dae..ebefd4ad 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/bakery/ranking/ScoredBakeryJpaRepository.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/bakery/ranking/ScoredBakeryJpaRepository.java @@ -21,6 +21,7 @@ public interface ScoredBakeryJpaRepository extends JpaRepository findScoredBakeryByCalculatedDate( @Param("calculatedDate") final LocalDate calculatedDate, @@ -30,7 +31,8 @@ List findScoredBakeryByCalculatedDate( @Query("select sb " + "from ScoredBakery sb " + "join fetch sb.bakery b " - + "where sb.calculatedDate between :startDate and :endDate") + + "where sb.calculatedDate between :startDate and :endDate " + + "and b.status = 'POSTING' ") List findScoredBakeryWithStartDate( @Param("startDate") final LocalDate startDate, @Param("endDate") final LocalDate endDate diff --git a/src/test/java/com/depromeet/breadmapbackend/domain/admin/feed/controller/FeedAdminControllerTest.java b/src/test/java/com/depromeet/breadmapbackend/domain/admin/feed/controller/FeedAdminControllerTest.java index 0b5a8514..3b62c04e 100644 --- a/src/test/java/com/depromeet/breadmapbackend/domain/admin/feed/controller/FeedAdminControllerTest.java +++ b/src/test/java/com/depromeet/breadmapbackend/domain/admin/feed/controller/FeedAdminControllerTest.java @@ -30,6 +30,8 @@ import org.springframework.test.web.servlet.ResultActions; import com.depromeet.breadmapbackend.domain.admin.Admin; +import com.depromeet.breadmapbackend.domain.admin.carousel.domain.CarouselManager; +import com.depromeet.breadmapbackend.domain.admin.carousel.domain.CarouselType; import com.depromeet.breadmapbackend.domain.admin.category.domain.Category; import com.depromeet.breadmapbackend.domain.admin.feed.domain.CurationBakery; import com.depromeet.breadmapbackend.domain.admin.feed.domain.CurationFeed; @@ -209,6 +211,7 @@ public void setDown() { categoryRepository.deleteAllInBatch(); userRepository.deleteAllInBatch(); adminRepository.deleteAllInBatch(); + carouselRepository.deleteAllInBatch(); } @Test @@ -355,6 +358,15 @@ public void setDown() { void 큐레이션피드_수정_테스트() throws Exception { //given + final CarouselManager carouselManager = CarouselManager.builder() + .targetId(curation.getId()) + .carouseled(true) + .carouselType(CarouselType.CURATION) + .bannerImage(customAWSS3Properties.getCloudFront() + "/" + "productImage.jpg") + .carouselOrder(1) + .build(); + + carouselRepository.save(carouselManager); CommonFeedRequestDto updateCommon = CommonFeedRequestDto.builder() .subTitle("업데이트된 큐레이션 테스트 피드") diff --git a/src/test/java/com/depromeet/breadmapbackend/utils/ControllerTest.java b/src/test/java/com/depromeet/breadmapbackend/utils/ControllerTest.java index c1a21170..e0d5af2a 100644 --- a/src/test/java/com/depromeet/breadmapbackend/utils/ControllerTest.java +++ b/src/test/java/com/depromeet/breadmapbackend/utils/ControllerTest.java @@ -22,6 +22,7 @@ import com.depromeet.breadmapbackend.domain.admin.AdminRepository; import com.depromeet.breadmapbackend.domain.admin.AdminService; +import com.depromeet.breadmapbackend.domain.admin.carousel.repository.CarouselRepository; import com.depromeet.breadmapbackend.domain.admin.category.repository.CategoryRepository; import com.depromeet.breadmapbackend.domain.admin.category.service.CategoryService; import com.depromeet.breadmapbackend.domain.admin.feed.repository.CurationBakeryRepository; @@ -227,6 +228,9 @@ public abstract class ControllerTest { @Autowired DataSource dataSource; + @Autowired + protected CarouselRepository carouselRepository; + @BeforeEach void beforeEach() throws Exception {