From 8eec877730ea962255ff8a1a8f872af2368e58b8 Mon Sep 17 00:00:00 2001 From: hysong4u Date: Sat, 10 Feb 2024 00:34:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=20=ED=86=A0=EB=84=88=EB=A8=BC?= =?UTF-8?q?=ED=8A=B8=20=EC=A4=91=EB=B3=B5=20=EC=B0=B8=EC=97=AC=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/sweet/domain/gift/controller/GiftController.java | 2 +- .../org/sopt/sweet/domain/gift/service/GiftService.java | 8 +++++++- src/main/java/org/sopt/sweet/global/error/ErrorCode.java | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sopt/sweet/domain/gift/controller/GiftController.java b/src/main/java/org/sopt/sweet/domain/gift/controller/GiftController.java index 49e1e49..88e1385 100644 --- a/src/main/java/org/sopt/sweet/domain/gift/controller/GiftController.java +++ b/src/main/java/org/sopt/sweet/domain/gift/controller/GiftController.java @@ -43,7 +43,7 @@ public ResponseEntity> deleteMyGift(@UserId Long userId, @Pat @GetMapping("/tournament/{roomId}") public ResponseEntity> getTournamentGiftList(@UserId Long userId, @PathVariable Long roomId) { - List tournamentGiftList = giftService.getTournamentGiftList(roomId); + List tournamentGiftList = giftService.getTournamentGiftList(userId, roomId); return SuccessResponse.ok(tournamentGiftList); } diff --git a/src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java b/src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java index 83c999b..81392fa 100644 --- a/src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java +++ b/src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java @@ -136,8 +136,14 @@ private Gift findByIdOrThrow(Long giftId) { } @Transactional(readOnly = true) - public List getTournamentGiftList(Long roomId) { + public List getTournamentGiftList(Long memberId, Long roomId) { Room room = findRoomByIdOrThrow(roomId); + RoomMember roomMember = roomMemberRepository.findByRoomIdAndMemberId(roomId, memberId); + + if(roomMember.isTournamentParticipation()){ + throw new BusinessException(ALREADY_PARTICIPATED_TOURNAMENT); + } + List gifts = giftRepository.findByRoom(room); return mapGiftsToTournamentLists(gifts); } diff --git a/src/main/java/org/sopt/sweet/global/error/ErrorCode.java b/src/main/java/org/sopt/sweet/global/error/ErrorCode.java index 4807a65..a4730d5 100644 --- a/src/main/java/org/sopt/sweet/global/error/ErrorCode.java +++ b/src/main/java/org/sopt/sweet/global/error/ErrorCode.java @@ -18,7 +18,7 @@ public enum ErrorCode { MEMBER_GIFT_COUNT_EXCEEDED(HttpStatus.BAD_REQUEST, "최대 선물 등록 개수를 초과하였습니다."), TOURNAMENT_START_DATE_PASSED(HttpStatus.BAD_REQUEST, "토너먼트 시작 날짜가 지났습니다"), ROOM_OWNER_CANNOT_DELETE_SELF(HttpStatus.BAD_REQUEST, "방 개설자는 스스로를 삭제할 수 없습니다."), - + ALREADY_PARTICIPATED_TOURNAMENT(HttpStatus.BAD_REQUEST, "이미 참가한 토너먼트입니다."), /** * 401 Unauthorized */ @@ -30,7 +30,6 @@ public enum ErrorCode { INVALID_REFRESH_TOKEN_VALUE(HttpStatus.UNAUTHORIZED, "리프레시 토큰의 값이 올바르지 않습니다."), EXPIRED_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "리프레시 토큰이 만료되었습니다. 다시 로그인해 주세요."), NOT_MATCH_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "일치하지 않는 리프레시 토큰입니다."), - /** * 403 Forbidden */ From be6c79081554140a7f4e03119af71158bcd02029 Mon Sep 17 00:00:00 2001 From: hysong4u Date: Sat, 10 Feb 2024 01:31:23 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[refactor]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=BB=AC=20=ED=99=98=EA=B2=BD=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/sweet/domain/member/controller/OAuthApi.java | 9 ++++++++- .../sweet/domain/member/controller/OAuthController.java | 4 ++-- .../sopt/sweet/domain/member/service/OAuthService.java | 7 ++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sopt/sweet/domain/member/controller/OAuthApi.java b/src/main/java/org/sopt/sweet/domain/member/controller/OAuthApi.java index a7cde22..09b1a2d 100644 --- a/src/main/java/org/sopt/sweet/domain/member/controller/OAuthApi.java +++ b/src/main/java/org/sopt/sweet/domain/member/controller/OAuthApi.java @@ -14,6 +14,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; @Tag(name = "소셜로그인", description = "소셜로그인 관련 API") @@ -38,7 +39,13 @@ ResponseEntity> kakaoLogin( required = true, example = "gGMvN1u_dgHdTizP8uUf7HZHNls_3G4X8qbKTwihE0x5W6f3E6acGDDsc80KPXLrAAABjO-2eHHUNEQ5evY1pg" ) - @RequestParam("code") String code + @RequestParam("code") String code, + @Parameter( + description = "환경변수", + required = true, + example = "development" + ) + @RequestHeader("X-Environment") String environment ); @ApiResponses( diff --git a/src/main/java/org/sopt/sweet/domain/member/controller/OAuthController.java b/src/main/java/org/sopt/sweet/domain/member/controller/OAuthController.java index 4b0f96c..d2e9007 100644 --- a/src/main/java/org/sopt/sweet/domain/member/controller/OAuthController.java +++ b/src/main/java/org/sopt/sweet/domain/member/controller/OAuthController.java @@ -22,8 +22,8 @@ public class OAuthController implements OAuthApi { private final OAuthService oAuthService; @GetMapping("/kakao/login") - public ResponseEntity> kakaoLogin(@RequestParam("code") String code) { - KakaoUserInfoResponseDto userInfo = oAuthService.kakaoCallback(code); + public ResponseEntity> kakaoLogin(@RequestParam("code") String code, @RequestHeader("X-Environment") String environment) { + KakaoUserInfoResponseDto userInfo = oAuthService.kakaoCallback(code, environment); MemberTokenResponseDto memberToken = oAuthService.saveToken(userInfo.memberId()); Map loginResponse = new HashMap<>(); diff --git a/src/main/java/org/sopt/sweet/domain/member/service/OAuthService.java b/src/main/java/org/sopt/sweet/domain/member/service/OAuthService.java index 3eb551f..973f64c 100644 --- a/src/main/java/org/sopt/sweet/domain/member/service/OAuthService.java +++ b/src/main/java/org/sopt/sweet/domain/member/service/OAuthService.java @@ -59,7 +59,7 @@ private String issueNewRefreshToken(Long memberId) { private final RedisTemplate redisTemplate; // 카카오 로그인 시 회원 정보 조회 - public KakaoUserInfoResponseDto kakaoCallback(String code) { + public KakaoUserInfoResponseDto kakaoCallback(String code, String environment) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.add("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); @@ -68,6 +68,11 @@ public KakaoUserInfoResponseDto kakaoCallback(String code) { params.add("grant_type", "authorization_code"); params.add("client_id", clientId); params.add("redirect_uri", redirectUri); + if ("development".equals(environment)) { + params.add("redirect_uri", redirectUri); + } else { + params.add("redirect_uri", "http://localhost:5137/api/oauth/kakao/login"); + } params.add("code", code); HttpEntity> kakaoTokenRequest =