diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/controller/ScheduleImageController.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/controller/ScheduleImageController.java index fb79ca5e..ca20b740 100644 --- a/backend/src/main/java/com/isp/backend/domain/scheduleImage/controller/ScheduleImageController.java +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/controller/ScheduleImageController.java @@ -1,10 +1,14 @@ package com.isp.backend.domain.scheduleImage.controller; -import com.isp.backend.domain.scheduleImage.dto.SaveScheduleImageRequest; -import com.isp.backend.domain.scheduleImage.dto.SaveScheduleImageResponse; -import com.isp.backend.domain.scheduleImage.service.SaveImageService; +import com.isp.backend.domain.scheduleImage.dto.request.SaveScheduleImageRequest; +import com.isp.backend.domain.scheduleImage.dto.response.ReadScheduleImageResponse; +import com.isp.backend.domain.scheduleImage.dto.response.SaveScheduleImageResponse; +import com.isp.backend.domain.scheduleImage.service.DeleteScheduleImageService; +import com.isp.backend.domain.scheduleImage.service.ReadScheduleImageService; +import com.isp.backend.domain.scheduleImage.service.SaveScheduleImageService; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -13,12 +17,27 @@ @RequestMapping("/scheduleImages") public class ScheduleImageController { - private final SaveImageService saveImageService; + private final SaveScheduleImageService saveScheduleImageService; + private final ReadScheduleImageService readScheduleImageService; + private final DeleteScheduleImageService deleteScheduleImageService; @PostMapping @ResponseStatus(HttpStatus.CREATED) public SaveScheduleImageResponse create(@RequestPart(value = "image", required = false) MultipartFile image, - @RequestPart(value = "saveScheduleImageRequest") SaveScheduleImageRequest request) { - return saveImageService.save(request, image); + @RequestPart(value = "saveScheduleImageRequest") SaveScheduleImageRequest request) { + return saveScheduleImageService.save(request, image); } + + @GetMapping("/{scheduleId}") + @ResponseStatus(HttpStatus.OK) + public ReadScheduleImageResponse read(@PathVariable(name = "scheduleId") Long scheduleId) { + return readScheduleImageService.read(scheduleId); + } + + @DeleteMapping("/{scheduleImageId}") + @ResponseStatus(HttpStatus.OK) + public ResponseEntity delete(@PathVariable(name = "scheduleImageId") Long scheduleImageId) { + return deleteScheduleImageService.delete(scheduleImageId); + } + } \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/SaveScheduleImageRequest.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/SaveScheduleImageRequest.java deleted file mode 100644 index 852acc87..00000000 --- a/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/SaveScheduleImageRequest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.isp.backend.domain.scheduleImage.dto; - -import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.time.LocalDateTime; - -@Getter -@NoArgsConstructor -public class SaveScheduleImageRequest { - private Long scheduleId; - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private LocalDateTime saveDate; - -// public Long scheduleId() { -// return scheduleId; -// } -} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/request/SaveScheduleImageRequest.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/request/SaveScheduleImageRequest.java new file mode 100644 index 00000000..7fbb33fb --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/request/SaveScheduleImageRequest.java @@ -0,0 +1,10 @@ +package com.isp.backend.domain.scheduleImage.dto.request; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class SaveScheduleImageRequest { + private Long scheduleId; +} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ReadScheduleImageResponse.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ReadScheduleImageResponse.java new file mode 100644 index 00000000..7feb915b --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ReadScheduleImageResponse.java @@ -0,0 +1,13 @@ +package com.isp.backend.domain.scheduleImage.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Map; + +@Getter +@AllArgsConstructor +public class ReadScheduleImageResponse { + private Long scheduleId; + private Map pathAndSaveDate; +} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/SaveScheduleImageResponse.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/SaveScheduleImageResponse.java similarity index 75% rename from backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/SaveScheduleImageResponse.java rename to backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/SaveScheduleImageResponse.java index d6270049..8a2427c8 100644 --- a/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/SaveScheduleImageResponse.java +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/SaveScheduleImageResponse.java @@ -1,4 +1,4 @@ -package com.isp.backend.domain.scheduleImage.dto; +package com.isp.backend.domain.scheduleImage.dto.response; import com.isp.backend.domain.scheduleImage.entity.ScheduleImage; import lombok.Getter; @@ -8,10 +8,12 @@ public class SaveScheduleImageResponse { private Long id; private Long scheduleId; private String path; + private String saveDate; public SaveScheduleImageResponse(ScheduleImage scheduleImage) { this.id = scheduleImage.getId(); this.scheduleId = scheduleImage.getSchedule().getId(); this.path = scheduleImage.getPath(); + this.saveDate = scheduleImage.getSaveDate(); } -} +} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/entity/ScheduleImage.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/entity/ScheduleImage.java index 49264ecc..19864d53 100644 --- a/backend/src/main/java/com/isp/backend/domain/scheduleImage/entity/ScheduleImage.java +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/entity/ScheduleImage.java @@ -4,6 +4,10 @@ import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; @Entity @Getter @@ -20,8 +24,16 @@ public class ScheduleImage { private Schedule schedule; private String path; + @CreatedDate + private String saveDate; + public ScheduleImage(Schedule schedule, String path) { this.schedule = schedule; this.path = path; } + + @PrePersist + public void onPrePersist(){ + this.saveDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + } } \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/repository/ScheduleImageRepository.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/repository/ScheduleImageRepository.java index bc05c3e5..a5b079f8 100644 --- a/backend/src/main/java/com/isp/backend/domain/scheduleImage/repository/ScheduleImageRepository.java +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/repository/ScheduleImageRepository.java @@ -3,5 +3,8 @@ import com.isp.backend.domain.scheduleImage.entity.ScheduleImage; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ScheduleImageRepository extends JpaRepository { + List findByScheduleId(Long scheduleId); } \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/repository/ScheduleImageS3Repository.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/repository/ScheduleImageS3Repository.java index 991f460f..2dbf3660 100644 --- a/backend/src/main/java/com/isp/backend/domain/scheduleImage/repository/ScheduleImageS3Repository.java +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/repository/ScheduleImageS3Repository.java @@ -1,6 +1,6 @@ package com.isp.backend.domain.scheduleImage.repository; -import com.isp.backend.domain.scheduleImage.dto.SaveScheduleImageRequest; +import com.isp.backend.domain.scheduleImage.dto.request.SaveScheduleImageRequest; import io.awspring.cloud.s3.S3Resource; import io.awspring.cloud.s3.S3Template; import lombok.AccessLevel; diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/DeleteScheduleImageService.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/DeleteScheduleImageService.java new file mode 100644 index 00000000..d51d5e01 --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/DeleteScheduleImageService.java @@ -0,0 +1,7 @@ +package com.isp.backend.domain.scheduleImage.service; + +import org.springframework.http.ResponseEntity; + +public interface DeleteScheduleImageService { + ResponseEntity delete(Long scheduleImageId); +} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ReadScheduleImageService.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ReadScheduleImageService.java new file mode 100644 index 00000000..e6c153f7 --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ReadScheduleImageService.java @@ -0,0 +1,7 @@ +package com.isp.backend.domain.scheduleImage.service; + +import com.isp.backend.domain.scheduleImage.dto.response.ReadScheduleImageResponse; + +public interface ReadScheduleImageService { + ReadScheduleImageResponse read(Long scheduleId); +} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/SaveImageService.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/SaveImageService.java deleted file mode 100644 index 17f55751..00000000 --- a/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/SaveImageService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.isp.backend.domain.scheduleImage.service; - -import com.isp.backend.domain.scheduleImage.dto.SaveScheduleImageRequest; -import com.isp.backend.domain.scheduleImage.dto.SaveScheduleImageResponse; -import org.springframework.web.multipart.MultipartFile; - -public interface SaveImageService { - - SaveScheduleImageResponse save(SaveScheduleImageRequest request, MultipartFile image); -} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/SaveScheduleImageService.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/SaveScheduleImageService.java new file mode 100644 index 00000000..eec4d95f --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/SaveScheduleImageService.java @@ -0,0 +1,10 @@ +package com.isp.backend.domain.scheduleImage.service; + +import com.isp.backend.domain.scheduleImage.dto.request.SaveScheduleImageRequest; +import com.isp.backend.domain.scheduleImage.dto.response.SaveScheduleImageResponse; +import org.springframework.web.multipart.MultipartFile; + +public interface SaveScheduleImageService { + + SaveScheduleImageResponse save(SaveScheduleImageRequest request, MultipartFile image); +} \ No newline at end of file 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 index 989eef97..ad83f983 100644 --- 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 @@ -2,18 +2,25 @@ 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.dto.request.SaveScheduleImageRequest; +import com.isp.backend.domain.scheduleImage.dto.response.ReadScheduleImageResponse; +import com.isp.backend.domain.scheduleImage.dto.response.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.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + @Service @RequiredArgsConstructor -public class ScheduleImageService implements SaveImageService { +public class ScheduleImageService implements SaveScheduleImageService, ReadScheduleImageService, DeleteScheduleImageService { private final ScheduleImageS3Repository scheduleImageS3Repository; private final ScheduleRepository scheduleRepository; @@ -28,4 +35,26 @@ public SaveScheduleImageResponse save(SaveScheduleImageRequest request, Multipar scheduleImageRepository.save(scheduleImage); return new SaveScheduleImageResponse(scheduleImage); } + + @Override + public ReadScheduleImageResponse read(Long scheduleId) { + List scheduleImages = scheduleImageRepository.findByScheduleId(scheduleId); + Map pathSaveDateMap = new HashMap<>(); + + scheduleImages.forEach(scheduleImage -> + pathSaveDateMap.put(scheduleImage.getSaveDate(), scheduleImage.getPath()) + ); + + return new ReadScheduleImageResponse(scheduleId, pathSaveDateMap); + } + + @Override + public ResponseEntity delete(Long scheduleImageId) { + if (!scheduleImageRepository.existsById(scheduleImageId)) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + } + + scheduleImageRepository.deleteById(scheduleImageId); + return ResponseEntity.noContent().build(); + } } \ No newline at end of file