From e66823e2a4765a17fcde72c8df351b0690ac0e64 Mon Sep 17 00:00:00 2001 From: Kim Jiyoon Date: Thu, 8 Aug 2024 13:46:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=BC=EC=A0=95=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ScheduleImageService.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ScheduleImageService.java diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ScheduleImageService.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ScheduleImageService.java new file mode 100644 index 00000000..7bd129c0 --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ScheduleImageService.java @@ -0,0 +1,31 @@ +package com.isp.backend.domain.scheduleImage.service; + +import com.isp.backend.domain.schedule.entity.Schedule; +import com.isp.backend.domain.schedule.repository.ScheduleRepository; +import com.isp.backend.domain.scheduleImage.dto.SaveScheduleImageRequest; +import com.isp.backend.domain.scheduleImage.dto.SaveScheduleImageResponse; +import com.isp.backend.domain.scheduleImage.entity.ScheduleImage; +import com.isp.backend.domain.scheduleImage.repository.ScheduleImageRepository; +import com.isp.backend.domain.scheduleImage.repository.ScheduleImageS3Repository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +@Service +@RequiredArgsConstructor +public class ScheduleImageService implements SaveImageService { + + private final ScheduleImageS3Repository scheduleImageS3Repository; + private final ScheduleRepository scheduleRepository; + private final ScheduleImageRepository scheduleImageRepository; + + @Override + public SaveScheduleImageResponse save(SaveScheduleImageRequest request, MultipartFile image) { + String imagePath = scheduleImageS3Repository.save(request, image); + Schedule schedule = scheduleRepository.findById(request.scheduleId()).orElseThrow(IllegalArgumentException::new); + ScheduleImage scheduleImage = new ScheduleImage(schedule, imagePath); + + scheduleImageRepository.save(scheduleImage); + return new SaveScheduleImageResponse(scheduleImage); + } +} \ No newline at end of file