Skip to content

Commit

Permalink
Merge pull request #114 from UMC-TripPiece/91-map-color-and-edit
Browse files Browse the repository at this point in the history
feat:Add mapId to API responses and support updates by user info
  • Loading branch information
generalban authored Jan 15, 2025
2 parents 65084df + fb21133 commit 5ff4404
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/main/java/umc/TripPiece/repository/MapRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import umc.TripPiece.domain.Map;

import java.util.List;
import java.util.Optional; // 추가된 임포트

public interface MapRepository extends JpaRepository<Map, Long> {

Expand All @@ -27,6 +28,10 @@ public interface MapRepository extends JpaRepository<Map, Long> {
@Query("SELECT COUNT(DISTINCT m.city.id) FROM Map m WHERE m.userId = :userId")
long countDistinctCityByUserId(Long userId);

// 유저 ID와 국가 코드, 도시 ID로 맵을 조회하는 메소드
@Query("SELECT m FROM Map m WHERE m.userId = :userId AND m.countryCode = :countryCode AND m.city.id = :cityId")
Optional<Map> findByUserIdAndCountryCodeAndCityId(Long userId, String countryCode, Long cityId);

// 유저 ID와 국가 코드로 맵을 조회하는 메소드 (마커 반환을 위한 사용)
Map findByCountryCodeAndUserId(String countryCode, Long userId);
}
23 changes: 8 additions & 15 deletions src/main/java/umc/TripPiece/web/controller/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

import umc.TripPiece.apiPayload.code.status.ErrorStatus;
import umc.TripPiece.apiPayload.exception.handler.NotFoundHandler;
import umc.TripPiece.domain.jwt.JWTUtil;
import umc.TripPiece.service.MapService;
import umc.TripPiece.validation.annotation.ExistEntity;
import umc.TripPiece.web.dto.request.MapRequestDto;


import org.springframework.validation.annotation.Validated;

import umc.TripPiece.apiPayload.ApiResponse;
Expand All @@ -33,6 +33,7 @@
public class MapController {

private final MapService mapService;
private final JWTUtil jwtUtil; // 추가: jwtUtil 객체 주입

@GetMapping("/{userId}")
@Operation(summary = "유저별 맵 불러오기 API", description = "유저별 맵 리스트 반환")
Expand Down Expand Up @@ -64,41 +65,33 @@ public ApiResponse<List<MapResponseDto.getMarkerResponse>> getMarkers(@RequestHe
return ApiResponse.onSuccess(markers);
}

// 맵 색상 수정 엔드포인트
@PutMapping("/color/{mapId}")
@Operation(summary = "맵 색상 수정 API", description = "맵의 색상을 수정")
public ApiResponse<MapResponseDto> updateMapColor(@PathVariable(name = "mapId") Long mapId, @RequestBody @Valid MapColorDto colorDto) {
MapResponseDto updatedMap = mapService.updateMapColor(mapId, colorDto.getColor());
return ApiResponse.onSuccess(updatedMap);
}

// 맵 색상 삭제 엔드포인트
@DeleteMapping("/color/delete/{mapId}")
@Operation(summary = "맵 색상 삭제 API", description = "맵의 색상을 삭제")
public ApiResponse<Void> deleteMapColor(@PathVariable(name = "mapId") Long mapId) {
mapService.deleteMapColor(mapId);
return ApiResponse.onSuccess(null);
}

// 여러 색상 선택 엔드포인트
@PutMapping("/colors/{mapId}")
@Operation(summary = "맵 여러 색상 선택 API", description = "맵의 색상을 여러 개 선택")
public ApiResponse<MapResponseDto> updateMultipleMapColors(@PathVariable(name = "mapId") Long mapId, @RequestBody MapColorsDto colorsDto) {
MapResponseDto updatedMap = mapService.updateMultipleMapColors(mapId, colorsDto.getColors());
return ApiResponse.onSuccess(updatedMap);
}

@GetMapping("/{userId}/visited-countries")
@GetMapping("/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();

public ApiResponse<MapStatsResponseDto> getVisitedCountries(@RequestHeader("Authorization") String token) {
String tokenWithoutBearer = token.substring(7); // Bearer 제거
Long userId = jwtUtil.getUserIdFromToken(tokenWithoutBearer); // jwtUtil 사용
MapStatsResponseDto response = mapService.getVisitedCountriesWithProfile(userId);
return ApiResponse.onSuccess(response);
}

Expand All @@ -112,4 +105,4 @@ public ApiResponse<List<MapResponseDto.searchDto>> searchCities(@RequestParam St
return ApiResponse.onSuccess(result);
}
}
}
}

0 comments on commit 5ff4404

Please sign in to comment.