Skip to content

Commit

Permalink
Merge pull request #111 from UMC-TripPiece/91-map-color-and-edit
Browse files Browse the repository at this point in the history
Add visited countries cumulative API
  • Loading branch information
oyatplum authored Jan 10, 2025
2 parents 57e2bff + de75cd7 commit e2e3612
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/main/java/umc/TripPiece/service/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,33 @@ public MapStatsResponseDto getMapStatsByUserId(Long userId) {
);
}

// 방문한 나라 누적 정보 반환
public List<String> getVisitedCountries(Long userId) {
return mapRepository.findDistinctCountryCodesByUserId(userId);
}

public long getVisitedCountryCount(Long userId) {
return mapRepository.countDistinctCountryCodeByUserId(userId);
}

// 방문한 나라 누적 정보와 프로필 통합 반환
public MapStatsResponseDto getVisitedCountriesWithProfile(Long userId) {
List<String> visitedCountries = getVisitedCountries(userId);
long visitedCountryCount = getVisitedCountryCount(userId);

User user = userRepository.findById(userId)
.orElseThrow(() -> new IllegalArgumentException("User not found with id: " + userId));

return new MapStatsResponseDto(
visitedCountryCount,
visitedCountries.size(),
visitedCountries,
Collections.emptyList(), // 도시 ID 리스트는 필요 시 추가
user.getProfileImg(),
user.getNickname()
);
}

// 도시 및 국가 검색
public List<MapResponseDto.searchDto> searchCitiesCountry(String keyword) {
if (keyword == null || keyword.trim().isEmpty()) {
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/umc/TripPiece/web/controller/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,28 @@ public ApiResponse<MapResponseDto> updateMultipleMapColors(@PathVariable(name =
return ApiResponse.onSuccess(updatedMap);
}

@GetMapping("/{userId}/visited-countries")
@Operation(summary = "방문한 나라 누적 API", description = "사용자가 방문한 나라의 리스트와 카운트를 반환")
public ApiResponse<MapStatsResponseDto> getVisitedCountries(@PathVariable(name = "userId") Long userId) {
List<String> countryCodes = mapService.getVisitedCountries(userId);
long countryCount = mapService.getVisitedCountryCount(userId);

MapStatsResponseDto response = MapStatsResponseDto.builder()
.countryCodes(countryCodes)
.countryCount(countryCount)
.build();

return ApiResponse.onSuccess(response);
}

@GetMapping("/search")
@Operation(summary = "도시, 국가 검색 API", description = "도시, 국가 검색")
public ApiResponse<List<MapResponseDto.searchDto>> searchCities(@RequestParam String keyword){
public ApiResponse<List<MapResponseDto.searchDto>> searchCities(@RequestParam String keyword) {
List<MapResponseDto.searchDto> result = mapService.searchCitiesCountry(keyword);
if (result.isEmpty()) {
throw new NotFoundHandler(ErrorStatus.NOT_FOUND_CITY_COUNTRY);
}
else {
} else {
return ApiResponse.onSuccess(result);
}
}
}
}

0 comments on commit e2e3612

Please sign in to comment.