From 9999c1834102a4e97db889b3a01d9a00cb68261a Mon Sep 17 00:00:00 2001 From: Kim Jiyoon Date: Thu, 29 Aug 2024 15:16:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[#143]=20Feat:=20=EB=82=98=EB=9D=BC?= =?UTF-8?q?=EB=B3=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=A7=88=ED=82=B9?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20API=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ScheduleImageController.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 ca20b740..a7fcd1b0 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,17 +1,25 @@ package com.isp.backend.domain.scheduleImage.controller; +import com.isp.backend.domain.schedule.dto.response.ScheduleListResponse; +import com.isp.backend.domain.schedule.service.ScheduleService; import com.isp.backend.domain.scheduleImage.dto.request.SaveScheduleImageRequest; +import com.isp.backend.domain.scheduleImage.dto.response.ReadScheduleImageCountriesResponse; 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.ReadScheduleImageCountriesService; import com.isp.backend.domain.scheduleImage.service.ReadScheduleImageService; import com.isp.backend.domain.scheduleImage.service.SaveScheduleImageService; +import com.isp.backend.global.security.CustomUserDetails; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + @RestController @RequiredArgsConstructor @RequestMapping("/scheduleImages") @@ -20,6 +28,8 @@ public class ScheduleImageController { private final SaveScheduleImageService saveScheduleImageService; private final ReadScheduleImageService readScheduleImageService; private final DeleteScheduleImageService deleteScheduleImageService; + private final ReadScheduleImageCountriesService readScheduleImageCountriesService; + private final ScheduleService scheduleService; @PostMapping @ResponseStatus(HttpStatus.CREATED) @@ -28,12 +38,21 @@ public SaveScheduleImageResponse create(@RequestPart(value = "image", required = return saveScheduleImageService.save(request, image); } + @GetMapping("/countries") + @ResponseStatus(HttpStatus.OK) + public ReadScheduleImageCountriesResponse readAll(@AuthenticationPrincipal CustomUserDetails userDetails) { + String memberUid = userDetails.getUsername(); + List schedules = scheduleService.getScheduleList(memberUid); + return readScheduleImageCountriesService.readCountries(schedules); + } + @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) { From 2cc0cc3f50daaded22789539488804a13ab0691e Mon Sep 17 00:00:00 2001 From: Kim Jiyoon Date: Thu, 29 Aug 2024 15:16:28 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[#143]=20Feat:=20=EB=82=98=EB=9D=BC?= =?UTF-8?q?=EB=B3=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=A7=88=ED=82=B9?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20DTO=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReadScheduleImageCountriesResponse.java | 12 ++++++++++++ .../dto/response/ScheduleLocationResponse.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ReadScheduleImageCountriesResponse.java create mode 100644 backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ScheduleLocationResponse.java diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ReadScheduleImageCountriesResponse.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ReadScheduleImageCountriesResponse.java new file mode 100644 index 00000000..24ccd2c6 --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ReadScheduleImageCountriesResponse.java @@ -0,0 +1,12 @@ +package com.isp.backend.domain.scheduleImage.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@Getter +@AllArgsConstructor +public class ReadScheduleImageCountriesResponse { + private List locationSchedules; +} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ScheduleLocationResponse.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ScheduleLocationResponse.java new file mode 100644 index 00000000..c11795d3 --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/dto/response/ScheduleLocationResponse.java @@ -0,0 +1,14 @@ +package com.isp.backend.domain.scheduleImage.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@Getter +@AllArgsConstructor +public class ScheduleLocationResponse { + private double latitude; + private double longitude; + private List scheduleIds; +} \ No newline at end of file From 17894629aba205fea5421f4641056c19f2d1802c Mon Sep 17 00:00:00 2001 From: Kim Jiyoon Date: Thu, 29 Aug 2024 15:16:50 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[#143]=20Feat:=20=EB=82=98=EB=9D=BC?= =?UTF-8?q?=EB=B3=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=A7=88=ED=82=B9?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EB=B9=84=EC=A6=88=EB=8B=88?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84=20=EB=B0=8F?= =?UTF-8?q?=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReadScheduleImageCountriesService.java | 10 +++++++ .../service/ScheduleImageService.java | 29 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ReadScheduleImageCountriesService.java diff --git a/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ReadScheduleImageCountriesService.java b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ReadScheduleImageCountriesService.java new file mode 100644 index 00000000..3a29730e --- /dev/null +++ b/backend/src/main/java/com/isp/backend/domain/scheduleImage/service/ReadScheduleImageCountriesService.java @@ -0,0 +1,10 @@ +package com.isp.backend.domain.scheduleImage.service; + +import com.isp.backend.domain.schedule.dto.response.ScheduleListResponse; +import com.isp.backend.domain.scheduleImage.dto.response.ReadScheduleImageCountriesResponse; + +import java.util.List; + +public interface ReadScheduleImageCountriesService { + ReadScheduleImageCountriesResponse readCountries(List uid); +} \ 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 ad83f983..380a3a38 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 @@ -1,10 +1,14 @@ package com.isp.backend.domain.scheduleImage.service; +import com.isp.backend.domain.gpt.entity.Coordinate; +import com.isp.backend.domain.schedule.dto.response.ScheduleListResponse; import com.isp.backend.domain.schedule.entity.Schedule; import com.isp.backend.domain.schedule.repository.ScheduleRepository; import com.isp.backend.domain.scheduleImage.dto.request.SaveScheduleImageRequest; +import com.isp.backend.domain.scheduleImage.dto.response.ReadScheduleImageCountriesResponse; import com.isp.backend.domain.scheduleImage.dto.response.ReadScheduleImageResponse; import com.isp.backend.domain.scheduleImage.dto.response.SaveScheduleImageResponse; +import com.isp.backend.domain.scheduleImage.dto.response.ScheduleLocationResponse; import com.isp.backend.domain.scheduleImage.entity.ScheduleImage; import com.isp.backend.domain.scheduleImage.repository.ScheduleImageRepository; import com.isp.backend.domain.scheduleImage.repository.ScheduleImageS3Repository; @@ -14,13 +18,15 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor -public class ScheduleImageService implements SaveScheduleImageService, ReadScheduleImageService, DeleteScheduleImageService { +public class ScheduleImageService implements SaveScheduleImageService, ReadScheduleImageService, DeleteScheduleImageService, ReadScheduleImageCountriesService { private final ScheduleImageS3Repository scheduleImageS3Repository; private final ScheduleRepository scheduleRepository; @@ -36,6 +42,26 @@ public SaveScheduleImageResponse save(SaveScheduleImageRequest request, Multipar return new SaveScheduleImageResponse(scheduleImage); } + + @Override + public ReadScheduleImageCountriesResponse readCountries(List schedules) { + Map> locationSchedules = new HashMap<>(); + + for (ScheduleListResponse schedule : schedules) { + Coordinate coordinate = new Coordinate(schedule.getLatitude(), schedule.getLongitude()); + locationSchedules.computeIfAbsent(coordinate, k -> new ArrayList<>()).add(schedule.getId()); + } + + List responses = locationSchedules.entrySet().stream() + .map(entry -> new ScheduleLocationResponse( + entry.getKey().getLatitude(), + entry.getKey().getLongitude(), + entry.getValue())) + .collect(Collectors.toList()); + + return new ReadScheduleImageCountriesResponse(responses); + } + @Override public ReadScheduleImageResponse read(Long scheduleId) { List scheduleImages = scheduleImageRepository.findByScheduleId(scheduleId); @@ -57,4 +83,5 @@ public ResponseEntity delete(Long scheduleImageId) { scheduleImageRepository.deleteById(scheduleImageId); return ResponseEntity.noContent().build(); } + } \ No newline at end of file