Skip to content

Commit

Permalink
feat: 일정 이미지를 저장하는 비즈니스 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yo0oni committed Aug 8, 2024
1 parent 2c43891 commit e66823e
Showing 1 changed file with 31 additions and 0 deletions.
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);
}
}

0 comments on commit e66823e

Please sign in to comment.