diff --git a/src/main/java/com/example/CatchStudy/controller/ManagerController.java b/src/main/java/com/example/CatchStudy/controller/ManagerController.java index 1f9f8f8..7b5e46e 100644 --- a/src/main/java/com/example/CatchStudy/controller/ManagerController.java +++ b/src/main/java/com/example/CatchStudy/controller/ManagerController.java @@ -23,16 +23,11 @@ public class ManagerController { private final ManagerService managerService; @PostMapping("/manager") - public Response saveStudyCafe(@RequestParam String cafeName, @RequestParam AddressRequestDto address, - @RequestParam String openingHours, @RequestParam String closedHours, - @RequestParam String closedDay, @RequestParam String cafePhone, - @RequestParam Integer seats, @RequestParam RoomInfoRequestDto roomInfo, - @RequestParam List usageFee, @RequestParam MultipartFile titleImage, - @RequestParam List multipleImages, @RequestParam MultipartFile seatChartImage) { - ManagerRequestDto managerRequestDto = new ManagerRequestDto( - cafeName, address, openingHours, closedHours, closedDay, cafePhone, seats, roomInfo, usageFee, titleImage, multipleImages, seatChartImage); + public Response saveStudyCafe(@RequestPart(value = "data") ManagerRequestDto managerRequestDto, + @RequestPart(value = "title_image", required = false) MultipartFile titleImage, + @RequestPart(value = "multiple_images", required = false) List multipleImages) { - managerService.saveStudyCafe(managerRequestDto); + managerService.saveStudyCafe(managerRequestDto, titleImage, multipleImages); System.out.println(managerRequestDto.getClosedDay()); System.out.println(managerRequestDto.getCafeName()); System.out.println(managerRequestDto.getSeats()); @@ -41,19 +36,15 @@ public Response saveStudyCafe(@RequestParam String cafeName, @RequestParam Addre } @PatchMapping("/manager") - public Response updateStudyCafe(@RequestPart(value = "data") ManagerRequestDto requestDto, + public Response updateStudyCafe(@RequestPart(value = "data") ManagerRequestDto managerRequestDto, @RequestPart(value = "title_image", required = false) MultipartFile titleImage, - @RequestPart(value = "multiple_images", required = false) List multipleImages, - @RequestPart(value = "seat_chart_image", required = false) MultipartFile seatChartImage) { - ManagerRequestDto managerRequestDto = new ManagerRequestDto( - requestDto, titleImage, multipleImages, seatChartImage); - + @RequestPart(value = "multiple_images", required = false) List multipleImages) { System.out.println(managerRequestDto.getCafePhone()); System.out.println(managerRequestDto.getCafeName()); System.out.println(managerRequestDto.getAddress().getCity()); System.out.println(managerRequestDto.getRoomInfo().getCancelAvailableTime()); - managerService.updateStudyCafe(managerRequestDto); + managerService.updateStudyCafe(managerRequestDto, titleImage, multipleImages); return Response.success(); } diff --git a/src/main/java/com/example/CatchStudy/domain/dto/request/ManagerRequestDto.java b/src/main/java/com/example/CatchStudy/domain/dto/request/ManagerRequestDto.java index 3c4fa42..859744b 100644 --- a/src/main/java/com/example/CatchStudy/domain/dto/request/ManagerRequestDto.java +++ b/src/main/java/com/example/CatchStudy/domain/dto/request/ManagerRequestDto.java @@ -24,9 +24,6 @@ public class ManagerRequestDto { private Integer seats; private RoomInfoRequestDto roomInfo; private List usageFee; - private MultipartFile titleImage; - private List multipleImages; - private MultipartFile seatChartImage; public ManagerRequestDto(ManagerRequestDto requestDto, MultipartFile titleImage, List multipleImages, MultipartFile seatChartImage) { @@ -38,8 +35,5 @@ public ManagerRequestDto(ManagerRequestDto requestDto, MultipartFile titleImage, this.seats = requestDto.getSeats(); this.roomInfo = requestDto.getRoomInfo(); this.usageFee = requestDto.getUsageFee(); - this.titleImage = titleImage; - this.multipleImages = multipleImages; - this.seatChartImage = seatChartImage; } } diff --git a/src/main/java/com/example/CatchStudy/service/CafeImageService.java b/src/main/java/com/example/CatchStudy/service/CafeImageService.java index 9d3eea7..5aad546 100644 --- a/src/main/java/com/example/CatchStudy/service/CafeImageService.java +++ b/src/main/java/com/example/CatchStudy/service/CafeImageService.java @@ -25,15 +25,11 @@ public class CafeImageService { private final CafeImageRepository cafeImageRepository; private final S3Service s3Service; - public void saveCafeImages(MultipartFile thumbnail, MultipartFile seatChart, List multipleImages, StudyCafe studyCafe) { + public void saveCafeImages(MultipartFile thumbnail, List multipleImages, StudyCafe studyCafe) { String thumbnailUrl = s3Service.upload(thumbnail); CafeImage cafeThumbnailImage = new CafeImage(ImageType.thumbnail, thumbnailUrl, studyCafe); cafeImageRepository.save(cafeThumbnailImage); - String seatChartUrl = s3Service.upload(seatChart); - CafeImage cafeSeatChartImage = new CafeImage(ImageType.seatingChart, seatChartUrl, studyCafe); - cafeImageRepository.save(cafeSeatChartImage); - for(MultipartFile imageFile : multipleImages) { String imageFileUrl = s3Service.upload(imageFile); CafeImage cafeImage = new CafeImage(ImageType.cafeImage, imageFileUrl, studyCafe); @@ -41,22 +37,19 @@ public void saveCafeImages(MultipartFile thumbnail, MultipartFile seatChart, Lis } } - public void deleteCafeImages(MultipartFile thumbnail, MultipartFile seatChart, List multipleImages, StudyCafe studyCafe) { + public void deleteCafeImages(MultipartFile thumbnail, List multipleImages, StudyCafe studyCafe) { List images = cafeImageRepository.findAllByStudyCafe_CafeId(studyCafe.getCafeId()); String thumbnailUrl = ""; - String seatChartUrl = ""; List multipleImageUrls = new ArrayList<>(); for(CafeImage image : images) { switch (image.getImageType()) { case thumbnail -> thumbnailUrl = image.getCafeImage(); - case seatingChart -> seatChartUrl = image.getCafeImage(); case cafeImage -> multipleImageUrls.add(image.getCafeImage()); } } if(thumbnail != null) s3Service.deleteImageFromS3(thumbnailUrl); - if(seatChart != null) s3Service.deleteImageFromS3(seatChartUrl); if(multipleImages != null) { for(String url : multipleImageUrls) s3Service.deleteImageFromS3(url); } diff --git a/src/main/java/com/example/CatchStudy/service/ManagerService.java b/src/main/java/com/example/CatchStudy/service/ManagerService.java index 4afc141..54ec303 100644 --- a/src/main/java/com/example/CatchStudy/service/ManagerService.java +++ b/src/main/java/com/example/CatchStudy/service/ManagerService.java @@ -36,7 +36,7 @@ public class ManagerService { private final CafeImageRepository cafeImageRepository; @Transactional - public void saveStudyCafe(ManagerRequestDto managerRequestDto) { + public void saveStudyCafe(ManagerRequestDto managerRequestDto, MultipartFile thumbnail, List multipleImages) { long userId = usersService.getCurrentUserId(); Users user = usersRepository.findByUserId(userId).orElseThrow(() -> new CatchStudyException(ErrorCode.USER_NOT_FOUND)); @@ -65,14 +65,11 @@ public void saveStudyCafe(ManagerRequestDto managerRequestDto) { } // 이미지 저장 - MultipartFile thumbnail = managerRequestDto.getTitleImage(); // 썸네일 - MultipartFile seatChart = managerRequestDto.getSeatChartImage(); // 좌석배치도 - List multipleImages = managerRequestDto.getMultipleImages(); // 카페 이미지 - cafeImageService.saveCafeImages(thumbnail, seatChart, multipleImages, savedStudyCafe); + cafeImageService.saveCafeImages(thumbnail, multipleImages, savedStudyCafe); } @Transactional - public void updateStudyCafe(ManagerRequestDto managerRequestDto) { + public void updateStudyCafe(ManagerRequestDto managerRequestDto, MultipartFile thumbnail, List multipleImages) { long userId = usersService.getCurrentUserId(); LocalTime openingHours = LocalTime.parse(managerRequestDto.getOpeningHours(), DateTimeFormatter.ofPattern("HH:mm")); LocalTime closedHours = LocalTime.parse(managerRequestDto.getOpeningHours(), DateTimeFormatter.ofPattern("HH:mm")); @@ -97,11 +94,8 @@ public void updateStudyCafe(ManagerRequestDto managerRequestDto) { seatService.saveSeat(Integer.toString(i), studyCafe); } - MultipartFile thumbnail = managerRequestDto.getTitleImage(); - MultipartFile seatChart = managerRequestDto.getSeatChartImage(); - List multipleImages = managerRequestDto.getMultipleImages(); - cafeImageService.deleteCafeImages(thumbnail, seatChart, multipleImages, studyCafe); - cafeImageService.saveCafeImages(thumbnail, seatChart, multipleImages, studyCafe); + cafeImageService.deleteCafeImages(thumbnail, multipleImages, studyCafe); + cafeImageService.saveCafeImages(thumbnail, multipleImages, studyCafe); } public ManagerResponseDto getStudyCafe() {