-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ScheduleImageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |