Skip to content

Commit

Permalink
Merge pull request #107 from Team-HMH/feat/#104-get-user-point-api
Browse files Browse the repository at this point in the history
feat - 유저 포인트 받기 api 구현
  • Loading branch information
kseysh authored Mar 11, 2024
2 parents c294ac6 + cd7da3e commit 56a29c0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/main/java/sopt/org/hmh/domain/user/controller/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,33 @@
@SecurityRequirement(name = JwtConstants.AUTHORIZATION)
public interface UserApi {

@Operation(
summary = "소셜 로그인")
@Operation(summary = "소셜 로그인")
ResponseEntity<BaseResponse<?>> orderLogin(
@Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken,
@RequestBody final SocialPlatformRequest request
);

@Operation(
summary = "회원 가입")
@Operation(summary = "회원 가입")
ResponseEntity<BaseResponse<?>> orderSignup(
@Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken,
@RequestHeader("OS") final String os,
@RequestBody final SocialSignUpRequest request
);

@Operation(
summary = "토큰 재발급")
@Operation(summary = "토큰 재발급")
ResponseEntity<BaseResponse<?>> orderReissue(
@Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String refreshToken
);

@Operation(
summary = "로그아웃")
@Operation(summary = "로그아웃")
ResponseEntity<BaseResponse<?>> orderLogout(@UserId @Parameter(hidden = true) final Long userId);

@Operation(
summary = "유저 정보 불러오기")
@Operation(summary = "유저 정보 불러오기")
ResponseEntity<BaseResponse<?>> orderGetUserInfo(@UserId @Parameter(hidden = true) final Long userId);

@Operation(summary = "회원 탈퇴")
public ResponseEntity<BaseResponse<?>> orderGetUserPoint(@UserId final Long userId);

@Operation(
summary = "회원 탈퇴")
ResponseEntity<BaseResponse<?>> orderWithdraw(@UserId @Parameter(hidden = true) final Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public ResponseEntity<BaseResponse<?>> orderGetUserInfo(@UserId final Long userI
.body(BaseResponse.success(UserSuccess.GET_USER_INFO_SUCCESS, userService.getUserInfo(userId)));
}

@GetMapping("/point")
@Override
public ResponseEntity<BaseResponse<?>> orderGetUserPoint(@UserId final Long userId) {
return ResponseEntity
.status(UserSuccess.GET_USER_POINT_SUCCESS.getHttpStatus())
.body(BaseResponse.success(UserSuccess.GET_USER_POINT_SUCCESS, userService.getUserPoint(userId)));
}

@DeleteMapping
@Override
public ResponseEntity<BaseResponse<?>> orderWithdraw(@UserId final Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum UserSuccess implements SuccessBase {
REISSUE_SUCCESS(HttpStatus.OK, "토큰 재발급에 성공했습니다."),
LOGOUT_SUCCESS(HttpStatus.OK, "로그아웃에 성공했습니다."),
GET_USER_INFO_SUCCESS(HttpStatus.OK, "유저의 정보를 불러오는데에 성공했습니다."),
GET_USER_POINT_SUCCESS(HttpStatus.OK, "유저의 포인트 정보를 불러오는데에 성공했습니다."),
WITHDRAW_SUCCESS(HttpStatus.OK, "회원 탈퇴를 성공하였습니다."),

// 201 CREATED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package sopt.org.hmh.domain.user.dto.response;

import sopt.org.hmh.domain.user.domain.User;

public record UserPointResponse(
Integer point
) {
public static UserPointResponse of(User user) {
return new UserPointResponse(
user.getPoint()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sopt.org.hmh.domain.user.dto.response.LoginResponse;
import sopt.org.hmh.domain.user.dto.response.ReissueResponse;
import sopt.org.hmh.domain.user.dto.response.UserInfoResponse;
import sopt.org.hmh.domain.user.dto.response.UserPointResponse;
import sopt.org.hmh.domain.user.repository.OnboardingInfoRepository;
import sopt.org.hmh.domain.user.repository.ProblemRepository;
import sopt.org.hmh.domain.user.repository.UserRepository;
Expand Down Expand Up @@ -100,6 +101,10 @@ public UserInfoResponse getUserInfo(Long userId) {
return UserInfoResponse.of(userRepository.findByIdOrThrowException(userId));
}

public UserPointResponse getUserPoint(Long userId) {
return UserPointResponse.of(userRepository.findByIdOrThrowException(userId));
}

private void validateUserId(Long userId) {
if (!userRepository.existsById(userId)) {
throw new UserException(UserError.NOT_FOUND_USER);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sopt/org/hmh/global/auth/jwt/JwtGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class JwtGenerator {
@Value("${jwt.secret}")
private String JWT_SECRET;
@Value("${jwt.access-token-expiration-time}")
private Integer ACCESS_TOKEN_EXPIRATION_TIME;
private Long ACCESS_TOKEN_EXPIRATION_TIME;
@Value("${jwt.refresh-token-expiration-time}")
private Integer REFRESH_TOKEN_EXPIRATION_TIME;
private Long REFRESH_TOKEN_EXPIRATION_TIME;
private final TokenRepository tokenRepository;

public String generateToken(Long userId, boolean isRefreshToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public class RefreshToken {
private String token;

@TimeToLive
private Integer expiration;
private Long expiration;
}

0 comments on commit 56a29c0

Please sign in to comment.