Skip to content

Commit

Permalink
Merge pull request #114 from SWEET-DEVELOPERS/feature/#113-gift
Browse files Browse the repository at this point in the history
[refactor] ํ† ๋„ˆ๋จผํŠธ ์ค‘๋ณต ์ฐธ์—ฌ ์˜ˆ์™ธ์ฒ˜๋ฆฌ & ๋กœ๊ทธ์ธ ๋กœ์ปฌ ํ™˜๊ฒฝ ๋ถ„๋ฆฌ
  • Loading branch information
hysong4u authored Feb 9, 2024
2 parents 78ed081 + be6c790 commit ce6e57e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ResponseEntity<SuccessResponse<?>> deleteMyGift(@UserId Long userId, @Pat

@GetMapping("/tournament/{roomId}")
public ResponseEntity<SuccessResponse<?>> getTournamentGiftList(@UserId Long userId, @PathVariable Long roomId) {
List<TournamentListsResponseDto> tournamentGiftList = giftService.getTournamentGiftList(roomId);
List<TournamentListsResponseDto> tournamentGiftList = giftService.getTournamentGiftList(userId, roomId);
return SuccessResponse.ok(tournamentGiftList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,14 @@ private Gift findByIdOrThrow(Long giftId) {
}

@Transactional(readOnly = true)
public List<TournamentListsResponseDto> getTournamentGiftList(Long roomId) {
public List<TournamentListsResponseDto> 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<Gift> gifts = giftRepository.findByRoom(room);
return mapGiftsToTournamentLists(gifts);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -38,7 +39,13 @@ ResponseEntity<SuccessResponse<?>> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class OAuthController implements OAuthApi {
private final OAuthService oAuthService;

@GetMapping("/kakao/login")
public ResponseEntity<SuccessResponse<?>> kakaoLogin(@RequestParam("code") String code) {
KakaoUserInfoResponseDto userInfo = oAuthService.kakaoCallback(code);
public ResponseEntity<SuccessResponse<?>> kakaoLogin(@RequestParam("code") String code, @RequestHeader("X-Environment") String environment) {
KakaoUserInfoResponseDto userInfo = oAuthService.kakaoCallback(code, environment);
MemberTokenResponseDto memberToken = oAuthService.saveToken(userInfo.memberId());

Map<String, Object> loginResponse = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private String issueNewRefreshToken(Long memberId) {
private final RedisTemplate<String, String> 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");
Expand All @@ -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<MultiValueMap<String, String>> kakaoTokenRequest =
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/sopt/sweet/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down

0 comments on commit ce6e57e

Please sign in to comment.