diff --git a/src/main/java/gible/config/SecurityConfig.java b/src/main/java/gible/config/SecurityConfig.java index 73bc026..a51ad0e 100644 --- a/src/main/java/gible/config/SecurityConfig.java +++ b/src/main/java/gible/config/SecurityConfig.java @@ -21,7 +21,7 @@ protected SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exce httpSecurity.csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests.requestMatchers( - "/auth/kakao", + "/auth/kakaologin", "/auth/token",//라우팅 아직 설정x "/swagger-resources/**", "/swagger-ui/**", diff --git a/src/main/java/gible/domain/auth/controller/AuthController.java b/src/main/java/gible/domain/auth/controller/AuthController.java index c63178f..a4b97f6 100644 --- a/src/main/java/gible/domain/auth/controller/AuthController.java +++ b/src/main/java/gible/domain/auth/controller/AuthController.java @@ -4,23 +4,51 @@ import gible.domain.auth.dto.SignInReq; import gible.domain.auth.dto.SignInRes; import gible.domain.auth.service.AuthService; +import gible.domain.auth.util.CookieUtil; +import gible.domain.security.common.SecurityUserDetails; +import gible.global.util.api.SuccessRes; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; 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.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.Map; @RestController @RequiredArgsConstructor @RequestMapping("/auth") public class AuthController { private final AuthService authService; + private final CookieUtil cookieUtil; @PostMapping("/kakaologin") - public ResponseEntity login(@Valid @RequestBody SignInReq signInReq) { - return ResponseEntity.ok().body(authService.login(signInReq)); + public ResponseEntity login(@Valid @RequestBody SignInReq signInReq) { + SignInRes signInRes = authService.login(signInReq); + + Map responseBody = new HashMap<>(); + responseBody.put("accessToken", signInRes.accessToken()); + + return ResponseEntity.ok().header("Set-Cookie", + cookieUtil.addRtkCookie("refreshToken", signInRes.refreshToken()).toString()) + .body(responseBody); + } + + @PostMapping("logout") + public ResponseEntity logout(@AuthenticationPrincipal SecurityUserDetails userDetails){ + authService.logout(userDetails.getId()); + return ResponseEntity.ok(SuccessRes.from("로그아웃 성공")); + } + + @PostMapping("/token") + public ResponseEntity reissueToken(@CookieValue("refreshToken") String refreshToken){ + return ResponseEntity.ok().body(authService.reissueToken(refreshToken)); } + @PostMapping("/withdraw") + public ResponseEntity withdraw(@AuthenticationPrincipal SecurityUserDetails userDetails) { + authService.withdraw(userDetails.getId()); + return ResponseEntity.ok(SuccessRes.from("유저삭제 성공")); + } } diff --git a/src/main/java/gible/domain/auth/dto/RenewTokenReq.java b/src/main/java/gible/domain/auth/dto/RenewTokenReq.java new file mode 100644 index 0000000..cddfcf7 --- /dev/null +++ b/src/main/java/gible/domain/auth/dto/RenewTokenReq.java @@ -0,0 +1,9 @@ +package gible.domain.auth.dto; + +import jakarta.validation.constraints.NotBlank; + +public record RenewTokenReq ( + @NotBlank(message = "리프레시 토큰은 필수 작성 항목입니다.") + String RefreshToken +){ +} diff --git a/src/main/java/gible/domain/auth/service/AuthService.java b/src/main/java/gible/domain/auth/service/AuthService.java index 06bf5e4..6af19f0 100644 --- a/src/main/java/gible/domain/auth/service/AuthService.java +++ b/src/main/java/gible/domain/auth/service/AuthService.java @@ -9,8 +9,12 @@ import gible.domain.user.service.UserService; import gible.exception.CustomException; import gible.exception.error.ErrorType; +import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; @Service @RequiredArgsConstructor @@ -18,20 +22,47 @@ public class AuthService { private final UserService userService; private final KakaoService kakaoService; private final JwtTokenProvider jwtTokenProvider; + + @Transactional(readOnly = true) public SignInRes login(SignInReq signInReq) { KakaoUserInfo kakaoUserInfo = getUserInfo(signInReq); User user = userService.findByEmail(kakaoUserInfo.email()); if(user == null) { throw new CustomException(ErrorType.NEED_SIGNUP); } - String accessToken = jwtTokenProvider.generateAccessToken(user); - String refreshToken = jwtTokenProvider.generateRefreshToken(user); + return generateSignInRes(user.getEmail(), user.getId(), user.getRole().toString()); + } - return SignInRes.of(accessToken, refreshToken); + @Transactional(readOnly = true) + public SignInRes reissueToken(String refreshToken){ + Claims claims = jwtTokenProvider.parseClaims(refreshToken); + return generateSignInRes( + claims.getSubject(), + UUID.fromString(claims.get("userId", String.class)), + claims.get("role", String.class) + ); + } + + public void logout(UUID userId) { + //레디스 리프레시토큰 삭제 로직 + } + + @Transactional + public void withdraw(UUID userId) { + userService.deleteById(userId); + //파이어베이스 연동시 사진 삭제 로직 필요 } private KakaoUserInfo getUserInfo(SignInReq signInReq) { String accessToken = kakaoService.getAccessToken(signInReq); return kakaoService.getUserInfo(accessToken); } + + private SignInRes generateSignInRes(String email, UUID userId, String role){ + String accessToken = jwtTokenProvider.generateAccessToken(email, userId, role); + String refreshToken = jwtTokenProvider.generateRefreshToken(email, userId, role); + + return SignInRes.of(accessToken, refreshToken); + } + } diff --git a/src/main/java/gible/domain/auth/util/CookieUtil.java b/src/main/java/gible/domain/auth/util/CookieUtil.java new file mode 100644 index 0000000..5f6f009 --- /dev/null +++ b/src/main/java/gible/domain/auth/util/CookieUtil.java @@ -0,0 +1,21 @@ +package gible.domain.auth.util; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseCookie; +import org.springframework.stereotype.Component; + +@Component +public class CookieUtil { + @Value("${cookie.refresh-expiration}") + private int REFRESH_EXPIRATION; + + public ResponseCookie addRtkCookie(String key, String value) { + return ResponseCookie.from(key, value) + .maxAge(REFRESH_EXPIRATION) + .secure(true) + .httpOnly(true) + .path("/") + .sameSite("None") + .build(); + } +} diff --git a/src/main/java/gible/domain/donation/controller/DonationController.java b/src/main/java/gible/domain/donation/controller/DonationController.java index ef5af0e..55908bb 100644 --- a/src/main/java/gible/domain/donation/controller/DonationController.java +++ b/src/main/java/gible/domain/donation/controller/DonationController.java @@ -4,8 +4,8 @@ import gible.domain.donation.dto.DonationReq; import gible.domain.donation.dto.DonationSenderInfoRes; import gible.domain.donation.service.DonationService; +import gible.global.util.api.SuccessRes; import gible.domain.security.common.SecurityUserDetails; -import gible.global.util.api.ApiUtil; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -28,7 +28,7 @@ public ResponseEntity donate(@Valid @RequestBody DonationReq donationReq, @AuthenticationPrincipal SecurityUserDetails userDetails) { donationService.donate(donationReq, userDetails.getId(), postId); - return ResponseEntity.ok(ApiUtil.from("기부 성공.")); + return ResponseEntity.ok(SuccessRes.from("기부 성공.")); } /* 게시글에 대한 기부자 목록 불러오기 */ diff --git a/src/main/java/gible/domain/event/controller/EventController.java b/src/main/java/gible/domain/event/controller/EventController.java index 932ec34..b152e53 100644 --- a/src/main/java/gible/domain/event/controller/EventController.java +++ b/src/main/java/gible/domain/event/controller/EventController.java @@ -4,7 +4,7 @@ import gible.domain.event.dto.EventReq; import gible.domain.event.dto.EventSummaryRes; import gible.domain.event.service.EventService; -import gible.global.util.api.ApiUtil; +import gible.global.util.api.SuccessRes; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -19,7 +19,8 @@ @RequiredArgsConstructor @RequestMapping("/event") @RestController -public class EventController { +public class +EventController { private final EventService eventService; @@ -28,7 +29,7 @@ public class EventController { public ResponseEntity saveEvent(@Valid @RequestBody EventReq eventReq) { eventService.saveEvent(eventReq); - return ResponseEntity.created(null).body(ApiUtil.from("이벤트 작성 성공.")); + return ResponseEntity.created(null).body(SuccessRes.from("이벤트 작성 성공.")); } /* 이벤트 목록 조회 */ @@ -52,7 +53,7 @@ public ResponseEntity updateEvent(@Valid @RequestBody EventReq updateEventReq @PathVariable UUID eventId) { eventService.updateEvent(updateEventReq, eventId); - return ResponseEntity.ok(ApiUtil.from("이벤트 수정 성공.")); + return ResponseEntity.ok(SuccessRes.from("이벤트 수정 성공.")); } /* 이벤트 삭제 */ @@ -60,6 +61,6 @@ public ResponseEntity updateEvent(@Valid @RequestBody EventReq updateEventReq public ResponseEntity deleteEvent(@PathVariable UUID eventId) { eventService.deleteEvent(eventId); - return ResponseEntity.ok(ApiUtil.from("이벤트 삭제 성공.")); + return ResponseEntity.ok(SuccessRes.from("이벤트 삭제 성공.")); } } diff --git a/src/main/java/gible/domain/participate/controller/ParticipateController.java b/src/main/java/gible/domain/participate/controller/ParticipateController.java index f1f2590..ce9d2e3 100644 --- a/src/main/java/gible/domain/participate/controller/ParticipateController.java +++ b/src/main/java/gible/domain/participate/controller/ParticipateController.java @@ -3,7 +3,7 @@ import gible.domain.participate.dto.ParticipationEventRes; import gible.domain.participate.service.ParticipateService; import gible.domain.security.common.SecurityUserDetails; -import gible.global.util.api.ApiUtil; +import gible.global.util.api.SuccessRes; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -27,7 +27,7 @@ public ResponseEntity participationEvent(@AuthenticationPrincipal SecurityUse @PathVariable UUID eventId) { participateService.participationEvent(userDetails.getId(), eventId); - return ResponseEntity.ok(ApiUtil.from("참여 완료.")); + return ResponseEntity.ok(SuccessRes.from("참여 완료.")); } /* 사용자가 참여한 이벤트 목록 조회하기 */ diff --git a/src/main/java/gible/domain/post/controller/PostController.java b/src/main/java/gible/domain/post/controller/PostController.java index b9f8c20..881785e 100644 --- a/src/main/java/gible/domain/post/controller/PostController.java +++ b/src/main/java/gible/domain/post/controller/PostController.java @@ -4,8 +4,8 @@ import gible.domain.post.dto.PostReq; import gible.domain.post.dto.PostSummaryRes; import gible.domain.post.service.PostService; +import gible.global.util.api.SuccessRes; import gible.domain.security.common.SecurityUserDetails; -import gible.global.util.api.ApiUtil; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -31,7 +31,7 @@ public ResponseEntity savePost(@Valid @RequestBody PostReq postReq, @AuthenticationPrincipal SecurityUserDetails userDetails) { postService.savePost(postReq, userDetails.getId()); - return ResponseEntity.created(null).body(ApiUtil.from("게시글 업로드 완료.")); + return ResponseEntity.created(null).body(SuccessRes.from("게시글 업로드 완료.")); } /* 게시글 목록 조회 + 검색 조회 */ @@ -59,7 +59,7 @@ public ResponseEntity updatePost(@Valid @RequestBody PostReq postReq, @PathVariable UUID postId) { postService.updatePost(postReq, postId); - return ResponseEntity.ok(ApiUtil.from("게시글 수정 완료.")); + return ResponseEntity.ok(SuccessRes.from("게시글 수정 완료.")); } /* 게시글 삭제 */ @@ -67,7 +67,7 @@ public ResponseEntity updatePost(@Valid @RequestBody PostReq postReq, public ResponseEntity deletePost(@PathVariable UUID postId) { postService.deletePost(postId); - return ResponseEntity.ok(ApiUtil.from("게시글 삭제 완료.")); + return ResponseEntity.ok(SuccessRes.from("게시글 삭제 완료.")); } } diff --git a/src/main/java/gible/domain/security/jwt/JwtTokenProvider.java b/src/main/java/gible/domain/security/jwt/JwtTokenProvider.java index cdb331d..41999fb 100644 --- a/src/main/java/gible/domain/security/jwt/JwtTokenProvider.java +++ b/src/main/java/gible/domain/security/jwt/JwtTokenProvider.java @@ -2,8 +2,6 @@ import gible.config.JwtConfig; -import gible.domain.user.entity.User; -import gible.domain.user.service.UserService; import gible.exception.CustomException; import gible.exception.error.ErrorType; import io.jsonwebtoken.Claims; @@ -19,29 +17,27 @@ @RequiredArgsConstructor public class JwtTokenProvider { private final JwtConfig jwtConfig; - private final UserService userService; public boolean validateToken(String token) { Claims claims = parseClaims(token); - if(userService.findById(claims.get("auth", UUID.class)) == null){ - throw new CustomException(ErrorType.USER_NOT_FOUND); + if(claims == null){ + throw new CustomException(ErrorType.INVALID_TOKEN); + } + if(claims.getExpiration().before(new Date())){ + throw new CustomException(ErrorType.TOKEN_EXPIRED); } return !claims.getExpiration().before(new Date()); } - public String generateAccessToken(User user) { - Map claims = new HashMap<>(); - claims.put("userId", user.getId()); - claims.put("role", user.getRole()); - return createToken(user.getEmail(), claims, jwtConfig.getAccessExpiration()); + public String generateAccessToken(String email, UUID userId, String role) { + Map claims = createClaims(userId, role); + return createToken(email, claims, jwtConfig.getAccessExpiration()); } - public String generateRefreshToken(User user) { - Map claims = new HashMap<>(); - claims.put("userId", user.getId()); - claims.put("role", user.getRole()); - return createToken(user.getEmail(), claims, jwtConfig.getRefreshExpiration()); + public String generateRefreshToken(String email, UUID userId, String role) { + Map claims = createClaims(userId, role); + return createToken(email, claims, jwtConfig.getRefreshExpiration()); } public String createToken(String email, Map claims, Long expiration) { @@ -54,11 +50,18 @@ public String createToken(String email, Map claims, Long expirat .compact(); } - protected Claims parseClaims(String accessToken){ + public Claims parseClaims(String token){ return Jwts.parser() .verifyWith(jwtConfig.getSecretKey()) .build() - .parseSignedClaims(accessToken) + .parseSignedClaims(token) .getPayload(); } + + private static Map createClaims(UUID userId, String role) { + Map claims = new HashMap<>(); + claims.put("userId", userId); + claims.put("role", role); + return claims; + } } diff --git a/src/main/java/gible/domain/user/controller/README.md b/src/main/java/gible/domain/user/controller/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/gible/domain/user/controller/UserController.java b/src/main/java/gible/domain/user/controller/UserController.java new file mode 100644 index 0000000..11c1d94 --- /dev/null +++ b/src/main/java/gible/domain/user/controller/UserController.java @@ -0,0 +1,38 @@ +package gible.domain.user.controller; + +import gible.domain.security.common.SecurityUserDetails; +import gible.domain.user.dto.MyPageRes; +import gible.domain.user.dto.SignUpReq; +import gible.domain.user.service.UserService; +import gible.global.util.api.SuccessRes; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/user") +public class UserController { + private final UserService userService; + + @PostMapping("/signUp") + public ResponseEntity SignUp(@Valid @RequestBody SignUpReq signUpReq){ + userService.signUp(signUpReq); + return ResponseEntity.ok().body(SuccessRes.from("회원가입 성공")); + } + @GetMapping("") + public ResponseEntity getMyPage( + @AuthenticationPrincipal SecurityUserDetails userDetails + ){ + return ResponseEntity.ok().body(userService.getMyPage(userDetails.getId())); + } + +// @GetMapping("/participation-event") +// public ResponseEntity> getParticipationEvent( +// @AuthenticationPrincipal SecurityUserDetails userDetails +// ){ +// return ResponseEntity.ok().body(userService.getParticipationEvents(userDetails.getId())); +// } +} diff --git a/src/main/java/gible/domain/user/dto/MyPageRes.java b/src/main/java/gible/domain/user/dto/MyPageRes.java new file mode 100644 index 0000000..e774004 --- /dev/null +++ b/src/main/java/gible/domain/user/dto/MyPageRes.java @@ -0,0 +1,11 @@ +package gible.domain.user.dto; + +public record MyPageRes( + String email, + String nickname, + int point +) { + public static MyPageRes of(final String email, final String nickname, final int point) { + return new MyPageRes(email, nickname, point); + } +} diff --git a/src/main/java/gible/domain/user/dto/SignUpReq.java b/src/main/java/gible/domain/user/dto/SignUpReq.java index 3e6eb6d..bccc906 100644 --- a/src/main/java/gible/domain/user/dto/SignUpReq.java +++ b/src/main/java/gible/domain/user/dto/SignUpReq.java @@ -2,16 +2,20 @@ import gible.domain.user.entity.Role; import gible.domain.user.entity.User; +import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; public record SignUpReq( - @NotBlank + @NotBlank(message = "닉네임 입력은 필수입니다.") String nickname, - @NotBlank + @NotBlank(message = "이메일 입력은 필수입니다.") + @Email(message = "올바른 이메일 형식이 아닙니다.") String email, - @NotBlank + @NotBlank(message = "이름 입력은 필수입니다.") String name, - @NotBlank + @NotBlank(message = "전화번호 입력은 필수입니다.") + @Pattern(regexp = "^010-\\d{4}-\\d{4}$", message = "전화번호 형식은 010-xxxx-xxxx이어야 합니다.") String phoneNumber, String role ) { diff --git a/src/main/java/gible/domain/user/repository/UserRepository.java b/src/main/java/gible/domain/user/repository/UserRepository.java index 6ca42cc..ebb9d73 100644 --- a/src/main/java/gible/domain/user/repository/UserRepository.java +++ b/src/main/java/gible/domain/user/repository/UserRepository.java @@ -8,4 +8,6 @@ public interface UserRepository extends JpaRepository { Optional findByEmail(String email); + + boolean existsByEmail(String email); } diff --git a/src/main/java/gible/domain/user/service/UserService.java b/src/main/java/gible/domain/user/service/UserService.java index 514bc7a..8bfe489 100644 --- a/src/main/java/gible/domain/user/service/UserService.java +++ b/src/main/java/gible/domain/user/service/UserService.java @@ -1,11 +1,14 @@ package gible.domain.user.service; +import gible.domain.user.dto.MyPageRes; +import gible.domain.user.dto.SignUpReq; import gible.domain.user.entity.User; import gible.domain.user.repository.UserRepository; import gible.exception.CustomException; import gible.exception.error.ErrorType; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.UUID; @@ -14,11 +17,38 @@ public class UserService { private final UserRepository userRepository; - public User findById(UUID userId){ - return userRepository.findById(userId).orElseThrow(()-> new CustomException(ErrorType.USER_NOT_FOUND)); + @Transactional(readOnly = true) + public User findById(UUID userId) { + return userRepository.findById(userId).orElseThrow(() -> new CustomException(ErrorType.USER_NOT_FOUND)); } - public User findByEmail(String email){ + @Transactional(readOnly = true) + public User findByEmail(String email) { return userRepository.findByEmail(email).orElse(null); } + + @Transactional(readOnly = true) + public MyPageRes getMyPage(UUID userId) { + User user = findById(userId); + return MyPageRes.of(user.getEmail(), user.getNickname(), user.getPoint()); + } + +// @Transactional(readOnly = true) +// public List getParticipationEvents(UUID userId) { +// return participateRepository.findByUser_Id(userId) +// .stream().map(Participate::getEvent).toList() +// .stream().map(EventSummaryRes::fromEntity).toList(); +// } + + @Transactional + public void deleteById(UUID userId) { + userRepository.deleteById(userId); + } + + @Transactional + public void signUp(SignUpReq signUpReq) { + if(userRepository.existsByEmail(signUpReq.email())) + throw new CustomException(ErrorType.ALREADY_EXISTS_USER); + userRepository.save(SignUpReq.toEntity(signUpReq)); + } } diff --git a/src/main/java/gible/exception/GlobalExceptionHandler.java b/src/main/java/gible/exception/GlobalExceptionHandler.java index 9f70cba..baa6c61 100644 --- a/src/main/java/gible/exception/GlobalExceptionHandler.java +++ b/src/main/java/gible/exception/GlobalExceptionHandler.java @@ -1,7 +1,7 @@ package gible.exception; -import gible.exception.dto.ErrorDto; +import gible.exception.dto.ErrorRes; import gible.exception.error.ErrorType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,15 +24,15 @@ public class GlobalExceptionHandler { @ExceptionHandler(CustomException.class) public ResponseEntity handle(CustomException ex){ ErrorType errortype = ex.getErrortype(); - log.warn("Error occurred : [errorCode={}, message={}]", errortype.getStatus(), errortype.getMessage()); - return ResponseEntity.status(errortype.getStatus()).body(ErrorDto.of(errortype.getStatus(), errortype.getMessage())); + log.error("Error occurred : [errorCode={}, message={}]", errortype.getStatus(), errortype.getMessage()); + return ResponseEntity.status(errortype.getStatus()).body(ErrorRes.of(errortype.getStatus(), errortype.getMessage())); } /* 일반 예외 처리 */ @ExceptionHandler protected ResponseEntity customServerException(Exception ex) { - ErrorDto error = new ErrorDto(INTERNAL_SERVER_ERROR.getStatus(), INTERNAL_SERVER_ERROR.getMessage()); - log.warn("Error occurred : [errorCode={}, message={}]", error.status(), error.message()); + ErrorRes error = new ErrorRes(INTERNAL_SERVER_ERROR.getStatus(), INTERNAL_SERVER_ERROR.getMessage()); + log.error("Error occurred : [errorCode={}, message={}]", error.status(), error.message()); return ResponseEntity.status(error.status()).body(error); } diff --git a/src/main/java/gible/exception/dto/ErrorDto.java b/src/main/java/gible/exception/dto/ErrorDto.java deleted file mode 100644 index b81f3c3..0000000 --- a/src/main/java/gible/exception/dto/ErrorDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package gible.exception.dto; - -public record ErrorDto( - - int status, - String message -) { - public static ErrorDto of(int status, String message) { - return new ErrorDto(status, message); - } -} diff --git a/src/main/java/gible/exception/dto/ErrorRes.java b/src/main/java/gible/exception/dto/ErrorRes.java new file mode 100644 index 0000000..70ab871 --- /dev/null +++ b/src/main/java/gible/exception/dto/ErrorRes.java @@ -0,0 +1,11 @@ +package gible.exception.dto; + +public record ErrorRes( + + int status, + String message +) { + public static ErrorRes of(int status, String message) { + return new ErrorRes(status, message); + } +} diff --git a/src/main/java/gible/exception/error/ErrorType.java b/src/main/java/gible/exception/error/ErrorType.java index d1b81b1..df93e28 100644 --- a/src/main/java/gible/exception/error/ErrorType.java +++ b/src/main/java/gible/exception/error/ErrorType.java @@ -9,8 +9,8 @@ public enum ErrorType { // 인증이 되어 있지 않을 때. UNAUTHORIZED(401, "접근 권한이 없습니다."), - ACCESS_TOKEN_EXPIRED(401, "Access Token이 만료되었습니다."), - INVALID_ACCESS_TOKEN(401, "Access Token이 잘못되었습니다."), + TOKEN_EXPIRED(401, "Token이 만료되었습니다."), + INVALID_TOKEN(401, "Token이 손실되었습니다."), SOCIAL_LOGIN_FAILED(401, "소셜로그인 오류"), NEED_SIGNUP(510, "닉네임 입력이 필요합니다."), // AccessToken 관련 오류 @@ -30,6 +30,7 @@ public enum ErrorType { // 이미 존재하는 값을 보냈을 때. ALREADY_PARTICIPATE_POST(409, "이미 해당 이벤트에 참여하였습니다."), + ALREADY_EXISTS_USER(409, "이미 존재하는 유저입니다."), // 서버 에러 INTERNAL_SERVER_ERROR(500, "서버 에러입니다. 서버 팀에 연락주세요."); diff --git a/src/main/java/gible/global/util/api/ApiUtil.java b/src/main/java/gible/global/util/api/SuccessRes.java similarity index 59% rename from src/main/java/gible/global/util/api/ApiUtil.java rename to src/main/java/gible/global/util/api/SuccessRes.java index df67931..1f1dd94 100644 --- a/src/main/java/gible/global/util/api/ApiUtil.java +++ b/src/main/java/gible/global/util/api/SuccessRes.java @@ -4,17 +4,17 @@ import lombok.Getter; @Getter -public class ApiUtil { +public class SuccessRes { private T response; @Builder - private ApiUtil(T response) { + private SuccessRes(T response) { this.response = response; } - public static ApiUtil from(T response) { - return ApiUtil.builder() + public static SuccessRes from(T response) { + return SuccessRes.builder() .response(response) .build(); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 28e0bd4..e5fb786 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,6 +20,8 @@ jwt: access-expiration: ${JWT_ACCESS_EXPIRATION} refresh-expiration: ${JWT_REFRESH_EXPIRATION} issuer: ${JWT_ISSUER} +cookie: + refresh-expiration: ${COOKIE_REFRESH_EXPIRATION} oauth2: kakao: tokenUri: https://kauth.kakao.com/oauth/token