From 5a516a1d32afe75ccfe98d852ecb473acc0d0cfc Mon Sep 17 00:00:00 2001 From: seungin Date: Sun, 20 Jul 2025 19:15:47 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[refactor]=20=EC=9B=A8=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EC=A1=B4=EC=97=90=20=EB=8C=80=ED=91=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wayble/server/wayblezone/entity/WaybleZone.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/wayble/server/wayblezone/entity/WaybleZone.java b/src/main/java/com/wayble/server/wayblezone/entity/WaybleZone.java index 9f36d70a..ad0a4e42 100644 --- a/src/main/java/com/wayble/server/wayblezone/entity/WaybleZone.java +++ b/src/main/java/com/wayble/server/wayblezone/entity/WaybleZone.java @@ -57,4 +57,13 @@ public class WaybleZone extends BaseEntity { @OneToMany(mappedBy = "waybleZone", cascade = CascadeType.ALL, orphanRemoval = true) private List userPlaceMappings = new ArrayList<>(); + + // 대표 이미지 필드 추가 + @Column(name = "main_image_url") + private String mainImageUrl; + + // 혹시 필요할수도 있어서 추가해놓음 + public void setMainImageUrl(String mainImageUrl) { + this.mainImageUrl = mainImageUrl; + } } From 6a08c023c633b5dd48b4f4df1740e21673340c81 Mon Sep 17 00:00:00 2001 From: seungin Date: Sun, 20 Jul 2025 19:16:42 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[refactor]=20requestBody=EC=97=90=20userId?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/wayble/server/user/dto/UserPlaceRequestDto.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/wayble/server/user/dto/UserPlaceRequestDto.java b/src/main/java/com/wayble/server/user/dto/UserPlaceRequestDto.java index 5285ab76..6643f396 100644 --- a/src/main/java/com/wayble/server/user/dto/UserPlaceRequestDto.java +++ b/src/main/java/com/wayble/server/user/dto/UserPlaceRequestDto.java @@ -3,7 +3,6 @@ import jakarta.validation.constraints.NotNull; public record UserPlaceRequestDto( - @NotNull Long userId, @NotNull Long waybleZoneId, @NotNull String title ) {} From f6de6f902c1b6c5b8332271a648faf89a76b3ae8 Mon Sep 17 00:00:00 2001 From: seungin Date: Sun, 20 Jul 2025 19:52:19 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[refactor]=20=EC=9C=A0=EC=A0=80=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EC=9E=A5=EC=86=8C=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EA=B4=80=EB=A0=A8=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EB=B0=8F=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserPlaceController.java | 23 ++++++------------- .../server/user/service/UserPlaceService.java | 9 ++++---- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/wayble/server/user/controller/UserPlaceController.java b/src/main/java/com/wayble/server/user/controller/UserPlaceController.java index c6c3bf83..fc38fded 100644 --- a/src/main/java/com/wayble/server/user/controller/UserPlaceController.java +++ b/src/main/java/com/wayble/server/user/controller/UserPlaceController.java @@ -12,6 +12,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -22,7 +23,6 @@ public class UserPlaceController { private final UserPlaceService userPlaceService; - private final JwtTokenProvider jwtProvider; @PostMapping @@ -30,24 +30,20 @@ public class UserPlaceController { @ApiResponses({ @ApiResponse(responseCode = "200", description = "장소 저장 성공"), @ApiResponse(responseCode = "400", description = "이미 저장한 장소입니다."), - @ApiResponse(responseCode = "404", description = "해당 유저 또는 웨이블존이 존재하지 않음") + @ApiResponse(responseCode = "404", description = "해당 유저 또는 웨이블존이 존재하지 않음"), + @ApiResponse(responseCode = "403", description = "권한이 없습니다.") }) public CommonResponse saveUserPlace( @PathVariable Long userId, @RequestBody @Valid UserPlaceRequestDto request, @RequestHeader(value = "Authorization") String authorizationHeader ) { - String token = authorizationHeader.replace("Bearer ", ""); - if (!jwtProvider.validateToken(token)) { + Long tokenUserId = (Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + if (!userId.equals(tokenUserId)) { throw new ApplicationException(UserErrorCase.FORBIDDEN); } - Long tokenUserId = jwtProvider.getUserId(token); - // Path variable과 request body의 userId 일치 여부 확인 - if (!userId.equals(request.userId()) || !userId.equals(tokenUserId)) { - throw new ApplicationException(UserErrorCase.FORBIDDEN); - } - userPlaceService.saveUserPlace(request); + userPlaceService.saveUserPlace(userId, request); // userId 파라미터로 넘김 return CommonResponse.success("장소가 저장되었습니다."); } @@ -65,12 +61,7 @@ public CommonResponse> getUserPlaces( @PathVariable Long userId, @RequestHeader("Authorization") String authorizationHeader ) { - String token = authorizationHeader.replace("Bearer ", ""); - if (!jwtProvider.validateToken(token)) { - throw new ApplicationException(UserErrorCase.FORBIDDEN); - } - Long tokenUserId = jwtProvider.getUserId(token); - + Long tokenUserId = (Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (!userId.equals(tokenUserId)) { throw new ApplicationException(UserErrorCase.FORBIDDEN); } diff --git a/src/main/java/com/wayble/server/user/service/UserPlaceService.java b/src/main/java/com/wayble/server/user/service/UserPlaceService.java index 24885ee4..75e6d28a 100644 --- a/src/main/java/com/wayble/server/user/service/UserPlaceService.java +++ b/src/main/java/com/wayble/server/user/service/UserPlaceService.java @@ -29,9 +29,9 @@ public class UserPlaceService { private final UserPlaceWaybleZoneMappingRepository mappingRepository; @Transactional - public void saveUserPlace(UserPlaceRequestDto request) { + public void saveUserPlace(Long userId, UserPlaceRequestDto request) { // 유저 존재 확인 - User user = userRepository.findById(request.userId()) + User user = userRepository.findById(userId) .orElseThrow(() -> new ApplicationException(UserErrorCase.USER_NOT_FOUND)); // 웨이블존 존재 확인 @@ -39,7 +39,7 @@ public void saveUserPlace(UserPlaceRequestDto request) { .orElseThrow(() -> new ApplicationException(UserErrorCase.WAYBLE_ZONE_NOT_FOUND)); // 중복 저장 확인 - boolean alreadySaved = mappingRepository.existsByUserPlace_User_IdAndWaybleZone_Id(request.userId(), request.waybleZoneId()); + boolean alreadySaved = mappingRepository.existsByUserPlace_User_IdAndWaybleZone_Id(userId, request.waybleZoneId()); if (alreadySaved) { throw new ApplicationException(UserErrorCase.PLACE_ALREADY_SAVED); } @@ -72,8 +72,7 @@ public List getUserPlaces(Long userId) { WaybleZone waybleZone = mapping.getWaybleZone(); // 웨이블존 대표 이미지 가져오기 - String imageUrl = waybleZone.getWaybleZoneImageList().stream() - .findFirst().map(img -> img.getImageUrl()).orElse(null); + String imageUrl = waybleZone.getMainImageUrl(); return UserPlaceListResponseDto.builder() .place_id(userPlace.getId()) From 247efc7f07f94819f1b26de5962a3b228660c98d Mon Sep 17 00:00:00 2001 From: seungin Date: Mon, 21 Jul 2025 00:08:27 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[feat]=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B4=80=EB=A0=A8=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD/=EC=9D=91=EB=8B=B5=20Dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/user/dto/KakaoLoginRequestDto.java | 5 +++++ .../server/user/dto/KakaoLoginResponseDto.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/main/java/com/wayble/server/user/dto/KakaoLoginRequestDto.java create mode 100644 src/main/java/com/wayble/server/user/dto/KakaoLoginResponseDto.java diff --git a/src/main/java/com/wayble/server/user/dto/KakaoLoginRequestDto.java b/src/main/java/com/wayble/server/user/dto/KakaoLoginRequestDto.java new file mode 100644 index 00000000..57d3790c --- /dev/null +++ b/src/main/java/com/wayble/server/user/dto/KakaoLoginRequestDto.java @@ -0,0 +1,5 @@ +package com.wayble.server.user.dto; + +public record KakaoLoginRequestDto( + String accessToken +) {} \ No newline at end of file diff --git a/src/main/java/com/wayble/server/user/dto/KakaoLoginResponseDto.java b/src/main/java/com/wayble/server/user/dto/KakaoLoginResponseDto.java new file mode 100644 index 00000000..575d2d82 --- /dev/null +++ b/src/main/java/com/wayble/server/user/dto/KakaoLoginResponseDto.java @@ -0,0 +1,18 @@ +package com.wayble.server.user.dto; + +import lombok.Builder; + +@Builder +public record KakaoLoginResponseDto( + String accessToken, + String refreshToken, + boolean isNewUser, + UserDto user +) { + @Builder + public record UserDto( + Long id, + String nickname, + String email + ) {} +} \ No newline at end of file From daf042b41af93ad62154ab6828310ff744c8da7f Mon Sep 17 00:00:00 2001 From: seungin Date: Mon, 21 Jul 2025 00:09:48 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[feat]=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=ED=8C=8C?= =?UTF-8?q?=EC=8B=B1=EC=9A=A9=20Dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/user/dto/KakaoUserInfoDto.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/wayble/server/user/dto/KakaoUserInfoDto.java diff --git a/src/main/java/com/wayble/server/user/dto/KakaoUserInfoDto.java b/src/main/java/com/wayble/server/user/dto/KakaoUserInfoDto.java new file mode 100644 index 00000000..69a46937 --- /dev/null +++ b/src/main/java/com/wayble/server/user/dto/KakaoUserInfoDto.java @@ -0,0 +1,25 @@ +package com.wayble.server.user.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class KakaoUserInfoDto { + private Long id; + private KakaoAccount kakao_account; + + @Getter + @Setter + public static class KakaoAccount { + private String email; + private Profile profile; + + @Getter + @Setter + public static class Profile { + private String nickname; + private String profile_image_url; + } + } +} \ No newline at end of file