Skip to content

Commit

Permalink
Merge branch 'backend/feature-143-country-map-marking' into dev_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
yo0oni committed Aug 29, 2024
2 parents 15c272d + 1789462 commit f3ee51a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)
Expand All @@ -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<ScheduleListResponse> 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<Void> delete(@PathVariable(name = "scheduleImageId") Long scheduleImageId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ScheduleLocationResponse> locationSchedules;
}
Original file line number Diff line number Diff line change
@@ -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<Long> scheduleIds;
}
Original file line number Diff line number Diff line change
@@ -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<ScheduleListResponse> uid);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -36,6 +42,26 @@ public SaveScheduleImageResponse save(SaveScheduleImageRequest request, Multipar
return new SaveScheduleImageResponse(scheduleImage);
}


@Override
public ReadScheduleImageCountriesResponse readCountries(List<ScheduleListResponse> schedules) {
Map<Coordinate, List<Long>> 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<ScheduleLocationResponse> 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<ScheduleImage> scheduleImages = scheduleImageRepository.findByScheduleId(scheduleId);
Expand All @@ -57,4 +83,5 @@ public ResponseEntity<Void> delete(Long scheduleImageId) {
scheduleImageRepository.deleteById(scheduleImageId);
return ResponseEntity.noContent().build();
}

}

0 comments on commit f3ee51a

Please sign in to comment.