From 82afea1a1781f7cba89f9f6f3f83c11de24f9280 Mon Sep 17 00:00:00 2001 From: sooyoung Date: Fri, 1 Mar 2024 16:01:34 +0900 Subject: [PATCH 1/6] =?UTF-8?q?chore:=20=EC=84=A4=EB=AA=85=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hyundai/app/member/controller/AuthController.java | 6 +++++- .../com/hyundai/app/member/controller/MemberController.java | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hyundai/app/member/controller/AuthController.java b/src/main/java/com/hyundai/app/member/controller/AuthController.java index 74a5170..4c0d2b0 100644 --- a/src/main/java/com/hyundai/app/member/controller/AuthController.java +++ b/src/main/java/com/hyundai/app/member/controller/AuthController.java @@ -5,7 +5,6 @@ import com.hyundai.app.member.service.MemberService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -28,6 +27,11 @@ public class AuthController { @Qualifier("memberServiceImpl") private MemberService memberService; + /** + * @author 황수영 + * @since 2024/02/12 + * 회원가입/로그인(OAuth 로그인) API + */ @PostMapping("/login") @ApiOperation("회원가입/로그인 API") public ResponseEntity login(@RequestBody LoginReqDto loginReqDto) { diff --git a/src/main/java/com/hyundai/app/member/controller/MemberController.java b/src/main/java/com/hyundai/app/member/controller/MemberController.java index 998e0bc..eaf3e13 100644 --- a/src/main/java/com/hyundai/app/member/controller/MemberController.java +++ b/src/main/java/com/hyundai/app/member/controller/MemberController.java @@ -31,6 +31,12 @@ public class MemberController { @Qualifier("memberServiceImpl") private MemberService memberService; + + /** + * @author 황수영 + * @since 2024/02/14 + * 회원 조회 API + */ @GetMapping @ApiOperation("회원 정보 조회 API") public ResponseEntity login(@ApiIgnore @MemberId String memberId) { From 7df05dccd95d7ffaeabe9ae88e008157894202ec Mon Sep 17 00:00:00 2001 From: sooyoung Date: Fri, 1 Mar 2024 16:02:10 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20@ExceptionHandler=EB=A1=9C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=9D=91=EB=8B=B5=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hyundai/app/exception/ErrorResponse.java | 20 ++++++ .../exception/ExceptionResponseHandler.java | 69 +++++++++++++++++++ .../hyundai/app/guide/GuideController.java | 6 ++ .../member/controller/MemberController.java | 1 - .../app/store/service/StoreServiceImpl.java | 1 + 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hyundai/app/exception/ErrorResponse.java create mode 100644 src/main/java/com/hyundai/app/exception/ExceptionResponseHandler.java diff --git a/src/main/java/com/hyundai/app/exception/ErrorResponse.java b/src/main/java/com/hyundai/app/exception/ErrorResponse.java new file mode 100644 index 0000000..a751696 --- /dev/null +++ b/src/main/java/com/hyundai/app/exception/ErrorResponse.java @@ -0,0 +1,20 @@ +package com.hyundai.app.exception; + +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +/** + * @author 황수영 + * @since 2024/02/28 + * 예외 응답 형식 + */ +@Getter +@Builder +@RequiredArgsConstructor +public class ErrorResponse { + private final String errorMessage; + private final String errorType; + private final HttpStatus httpStatus; +} \ No newline at end of file diff --git a/src/main/java/com/hyundai/app/exception/ExceptionResponseHandler.java b/src/main/java/com/hyundai/app/exception/ExceptionResponseHandler.java new file mode 100644 index 0000000..0444e23 --- /dev/null +++ b/src/main/java/com/hyundai/app/exception/ExceptionResponseHandler.java @@ -0,0 +1,69 @@ +package com.hyundai.app.exception; + +import lombok.extern.log4j.Log4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; + +/** + * @author 황수영 + * @since 2024/02/28 + * 예외 응답 반환하는 핸들러 + */ +@Log4j +@RestControllerAdvice +public class ExceptionResponseHandler extends ResponseEntityExceptionHandler { + + /** + * @author 황수영 + * @since 2024/02/28 + * 자체 예외 응답 처리 + */ + @ExceptionHandler(AdventureOfHeendyException.class) + public ResponseEntity handleCustomException(AdventureOfHeendyException e) { + return handleExceptionInternal(e); + } + + /** + * @author 황수영 + * @since 2024/02/28 + * 자체 예외 이외의 모든 예외 처리 + */ + @ExceptionHandler(Exception.class) + public ResponseEntity handleAllException(Exception e) { + return handleExceptionAll(e); + } + + /** + * @author 황수영 + * @since 2024/02/28 + * 자체 예외 ResponseEntity 생성 + */ + private ResponseEntity handleExceptionInternal(AdventureOfHeendyException e) { + log.error("자체 예외 발생 : " + e); + + return ResponseEntity.status(e.getErrorCode().getHttpStatus()) + .body(ErrorResponse.builder() + .errorMessage(e.getErrorCode().getMessage()) + .errorType(String.valueOf(e.getErrorCode())) + .httpStatus(e.getErrorCode().getHttpStatus()) + .build()); + } + + /** + * @author 황수영 + * @since 2024/02/28 + * 자체 예외 이외의 모든 ResponseEntity 생성 + */ + private ResponseEntity handleExceptionAll(Exception e) { + log.error("예외 발생 : " + e); + + return ResponseEntity.status(ErrorCode.SERVER_UNAVAILABLE.getHttpStatus()) + .body(ErrorResponse.builder() + .errorMessage(e.getMessage()) + .errorType(e.toString()) + .httpStatus(ErrorCode.SERVER_UNAVAILABLE.getHttpStatus()) + .build()); + } +} \ No newline at end of file diff --git a/src/main/java/com/hyundai/app/guide/GuideController.java b/src/main/java/com/hyundai/app/guide/GuideController.java index eb8de67..fc165e2 100644 --- a/src/main/java/com/hyundai/app/guide/GuideController.java +++ b/src/main/java/com/hyundai/app/guide/GuideController.java @@ -1,5 +1,7 @@ package com.hyundai.app.guide; +import com.hyundai.app.exception.AdventureOfHeendyException; +import com.hyundai.app.exception.ErrorCode; import com.hyundai.app.guide.dto.GuideTypeResDto; import com.hyundai.app.guide.dto.HashtagListResDto; import com.hyundai.app.store.dto.StoreResDto; @@ -51,6 +53,10 @@ public ResponseEntity> getGuideByCategory(@PathVariable( public ResponseEntity> findStoresByHashtags(@RequestParam("hashtagId")int hashtagId) { log.debug("해시 태그 선택 시, 관련 식당들 조회 => 해시 태그 : " + hashtagId); List stores = hashtagService.findStoresByMostSavedHashtags(hashtagId); + if (stores.isEmpty()) { + log.error("해당 해시 태그의 식당들이 존재하지 않습니다. => 해시 태그 : " + hashtagId); + throw new AdventureOfHeendyException(ErrorCode.STORE_NOT_EXIST); + } return new ResponseEntity<>(stores, HttpStatus.ACCEPTED); } } \ No newline at end of file diff --git a/src/main/java/com/hyundai/app/member/controller/MemberController.java b/src/main/java/com/hyundai/app/member/controller/MemberController.java index eaf3e13..e00c7e0 100644 --- a/src/main/java/com/hyundai/app/member/controller/MemberController.java +++ b/src/main/java/com/hyundai/app/member/controller/MemberController.java @@ -31,7 +31,6 @@ public class MemberController { @Qualifier("memberServiceImpl") private MemberService memberService; - /** * @author 황수영 * @since 2024/02/14 diff --git a/src/main/java/com/hyundai/app/store/service/StoreServiceImpl.java b/src/main/java/com/hyundai/app/store/service/StoreServiceImpl.java index 1e7e50f..5d6ae86 100644 --- a/src/main/java/com/hyundai/app/store/service/StoreServiceImpl.java +++ b/src/main/java/com/hyundai/app/store/service/StoreServiceImpl.java @@ -43,6 +43,7 @@ public class StoreServiceImpl implements StoreService { public StoreResDto getStoreDetail(int storeId) { Store store = storeMapper.getStoreDetail(storeId); if (store == null) { + log.error("해당하는 매장 번호가 존재하지 않습니다. storeId : " + storeId); throw new AdventureOfHeendyException(STORE_NOT_EXIST); } log.debug("매장 번호 :" + storeId + " 정보 조회 : " + store); From f71bd08b36d1de3ed42459b19f82f7caed8bbbe9 Mon Sep 17 00:00:00 2001 From: sooyoung Date: Fri, 1 Mar 2024 16:12:21 +0900 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EB=B3=84=20=EC=84=A4=EB=AA=85=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/oauth/kakao/KakaoOauthClient.java | 7 ++- .../app/member/service/MemberServiceImpl.java | 45 ++++++++++++++----- .../app/security/AuthDetailsService.java | 2 +- .../app/security/jwt/JwtTokenGenerator.java | 33 +++++++++----- 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/hyundai/app/member/oauth/kakao/KakaoOauthClient.java b/src/main/java/com/hyundai/app/member/oauth/kakao/KakaoOauthClient.java index 7de4d35..303c2f9 100644 --- a/src/main/java/com/hyundai/app/member/oauth/kakao/KakaoOauthClient.java +++ b/src/main/java/com/hyundai/app/member/oauth/kakao/KakaoOauthClient.java @@ -54,7 +54,12 @@ private KakaoResDto getMemberInfoByLoginToken(String accessToken) { HttpEntity> request = new HttpEntity<>(headers); return getMemberInfoFromOAuth(request); } - + + /** + * @author 황수영 + * @since 2024/02/12 + * Kakao에서 받아온 사용자 정보에서 email 추출 + */ private KakaoResDto getMemberInfoFromOAuth(HttpEntity> request) { KakaoResDto kakaoResDto = null; try { diff --git a/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java b/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java index 3a54755..9fcb263 100644 --- a/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java +++ b/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java @@ -22,7 +22,7 @@ /** * @author 황수영 * @since 2024/02/13 - * (설명) + * 회원 관련 서비스단 */ @Log4j @Service @@ -31,18 +31,17 @@ public class MemberServiceImpl implements MemberService { @Value("${jwt.access-validity}") private long accessValidity; - private final MemberMapper memberMapper; private final KakaoOauthClient oAuthClient; private final JwtTokenGenerator authTokenGenerator; private final AwsS3Config awsS3Config; private final MemberQrService memberQrService; - public MemberResDto getMemberInfo(String id) { - Member member = memberMapper.findById(id); - return MemberResDto.of(member); - } - + /** + * @author 황수영 + * @since 2024/02/13 + * 회원가입/로그인 기능 + */ public LoginResDto login(LoginReqDto loginReqDto) { String email = oAuthClient.getEmail(loginReqDto); OauthType oauthType = OauthType.valueOf(loginReqDto.getOauthType().toUpperCase()); @@ -56,11 +55,21 @@ public LoginResDto login(LoginReqDto loginReqDto) { return joinByOauthId(email, oauthType); } + /** + * @author 황수영 + * @since 2024/02/13 + * access token 재발급 + */ private String updateAccessToken(Member member) { String memberId = String.valueOf(member.getId()); return authTokenGenerator.createJwtToken(memberId, accessValidity); } + /** + * @author 황수영 + * @since 2024/02/13 + * token 갱신 + */ private LoginResDto getUpdatedToken(Member member) { String newAccessToken = updateAccessToken(member); String refreshToken = member.getRefreshToken(); @@ -71,6 +80,11 @@ private LoginResDto getUpdatedToken(Member member) { .build(); } + /** + * @author 황수영 + * @since 2024/02/13 + * oauth id값으로 회원가입 + */ public LoginResDto joinByOauthId(String email, OauthType oauthType) { String oauthId = oauthType.createOauthIdWithEmail(email); LoginResDto loginResDto = authTokenGenerator.createLoginResDto(oauthId); @@ -88,13 +102,20 @@ public LoginResDto joinByOauthId(String email, OauthType oauthType) { .build(); log.debug("joinByEmail member" + member.toString()); memberMapper.saveMember(member); - - Member savedMember = memberMapper.findByOauthId(oauthId); - log.debug("joinByEmail savedMember" + savedMember); - return loginResDto; } - + + /** + * @author 황수영 + * @since 2024/02/13 + * 회원 정보 조회 + */ + public MemberResDto getMemberInfo(String id) { + log.debug("회원 정보 조회 : " + id); + Member member = memberMapper.findById(id); + return MemberResDto.of(member); + } + /** * @author 엄상은 * @since 2024/02/26 diff --git a/src/main/java/com/hyundai/app/security/AuthDetailsService.java b/src/main/java/com/hyundai/app/security/AuthDetailsService.java index 1308fad..45fcf33 100644 --- a/src/main/java/com/hyundai/app/security/AuthDetailsService.java +++ b/src/main/java/com/hyundai/app/security/AuthDetailsService.java @@ -23,7 +23,7 @@ public class AuthDetailsService implements UserDetailsService { @Override public AuthUserDetails loadUserByUsername(String id) throws UsernameNotFoundException { Member member = memberMapper.findById(id); - log.debug("loadUserByUsername() => member : " + member); + log.debug("loadUserByUsername() => member : " + id); return new AuthUserDetails(member); } } \ No newline at end of file diff --git a/src/main/java/com/hyundai/app/security/jwt/JwtTokenGenerator.java b/src/main/java/com/hyundai/app/security/jwt/JwtTokenGenerator.java index 05f5fac..a4da35c 100644 --- a/src/main/java/com/hyundai/app/security/jwt/JwtTokenGenerator.java +++ b/src/main/java/com/hyundai/app/security/jwt/JwtTokenGenerator.java @@ -41,16 +41,12 @@ public class JwtTokenGenerator implements InitializingBean { public void afterPropertiesSet() { jwtSecret = Base64.getEncoder().encodeToString(jwtSecret.getBytes()); } - - public Authentication getAuthentication(String accessToken) { - Claims claims = getClaims(accessToken); - AuthUserDetails userDetails = authDetailsService.loadUserByUsername(claims.getSubject()); - log.debug("AuthTokenGenerator getAuthentication() userDetails : " + userDetails); - - return new UsernamePasswordAuthenticationToken( - userDetails, accessToken, userDetails.getAuthorities()); - } - + + /** + * @author 황수영 + * @since 2024/02/14 + * 로그인 Res Dto 생성 + */ public LoginResDto createLoginResDto(String id) { String accessToken = createJwtToken(id, accessValidity); String refreshToken = createJwtToken(id, refreshValidity); @@ -61,6 +57,11 @@ public LoginResDto createLoginResDto(String id) { .build(); } + /** + * @author 황수영 + * @since 2024/02/14 + * JWT 생성 + */ public String createJwtToken(String id, long validity) { Date now = new Date(); Claims claims = Jwts.claims() @@ -74,6 +75,11 @@ public String createJwtToken(String id, long validity) { .compact(); } + /** + * @author 황수영 + * @since 2024/02/14 + * JWT 파싱 + */ public Claims getClaims(String accessToken) { try { return Jwts.parser() @@ -84,7 +90,12 @@ public Claims getClaims(String accessToken) { return e.getClaims(); } } - + + /** + * @author 황수영 + * @since 2024/02/14 + * 토큰 유효성 검증 + */ public void isTokenValidate(String token) { try { Jwts.parser() From 8c6a9bc6d8db6d0c17c68416f2e78958161e2010 Mon Sep 17 00:00:00 2001 From: sooyoung Date: Fri, 1 Mar 2024 17:12:57 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20=EC=9E=90=EC=B2=B4=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hyundai/app/member/service/MemberServiceImpl.java | 6 ++++++ .../com/hyundai/app/security/AuthDetailsService.java | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java b/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java index 9fcb263..d8018c5 100644 --- a/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java +++ b/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java @@ -1,5 +1,7 @@ package com.hyundai.app.member.service; +import com.hyundai.app.exception.AdventureOfHeendyException; +import com.hyundai.app.exception.ErrorCode; import com.hyundai.app.member.domain.Member; import com.hyundai.app.member.dto.LoginReqDto; import com.hyundai.app.member.dto.LoginResDto; @@ -113,6 +115,10 @@ public LoginResDto joinByOauthId(String email, OauthType oauthType) { public MemberResDto getMemberInfo(String id) { log.debug("회원 정보 조회 : " + id); Member member = memberMapper.findById(id); + if (member == null) { + log.error("회원 id가 존재하지 않습니다. : " + id); + throw new AdventureOfHeendyException(ErrorCode.MEMBER_NOT_EXIST); + } return MemberResDto.of(member); } diff --git a/src/main/java/com/hyundai/app/security/AuthDetailsService.java b/src/main/java/com/hyundai/app/security/AuthDetailsService.java index 45fcf33..1cd76de 100644 --- a/src/main/java/com/hyundai/app/security/AuthDetailsService.java +++ b/src/main/java/com/hyundai/app/security/AuthDetailsService.java @@ -1,5 +1,7 @@ package com.hyundai.app.security; +import com.hyundai.app.exception.AdventureOfHeendyException; +import com.hyundai.app.exception.ErrorCode; import com.hyundai.app.member.mapper.MemberMapper; import com.hyundai.app.member.domain.Member; import lombok.RequiredArgsConstructor; @@ -22,8 +24,11 @@ public class AuthDetailsService implements UserDetailsService { @Override public AuthUserDetails loadUserByUsername(String id) throws UsernameNotFoundException { - Member member = memberMapper.findById(id); + Member findMember = memberMapper.findById(id); log.debug("loadUserByUsername() => member : " + id); - return new AuthUserDetails(member); + if (findMember == null) { + throw new AdventureOfHeendyException(ErrorCode.MEMBER_NOT_EXIST); + } + return new AuthUserDetails(findMember); } } \ No newline at end of file From a42f399e3423c27c9bcad092377e0a5b78e497b2 Mon Sep 17 00:00:00 2001 From: sooyoung Date: Fri, 1 Mar 2024 17:22:48 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20HTTP=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hyundai/app/event/enumType/EventType.java | 4 ++-- .../com/hyundai/app/exception/ErrorCode.java | 20 +++++++------------ .../app/store/service/StoreServiceImpl.java | 5 ++++- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/hyundai/app/event/enumType/EventType.java b/src/main/java/com/hyundai/app/event/enumType/EventType.java index cb0726f..6f74be5 100644 --- a/src/main/java/com/hyundai/app/event/enumType/EventType.java +++ b/src/main/java/com/hyundai/app/event/enumType/EventType.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.Random; -import static com.hyundai.app.exception.ErrorCode.EVENT_TYPE_NOT_EXIST; +import static com.hyundai.app.exception.ErrorCode.EVENT_TYPE_INVALID; /** * @author 엄상은 @@ -50,7 +50,7 @@ public static EventType of(String eventType) { .filter(e -> e.equals(eventEnum)) .findFirst() .map(EventType::getRandomEventType) - .orElseThrow(() -> new AdventureOfHeendyException(EVENT_TYPE_NOT_EXIST)); + .orElseThrow(() -> new AdventureOfHeendyException(EVENT_TYPE_INVALID)); } } \ No newline at end of file diff --git a/src/main/java/com/hyundai/app/exception/ErrorCode.java b/src/main/java/com/hyundai/app/exception/ErrorCode.java index 5653869..1603240 100644 --- a/src/main/java/com/hyundai/app/exception/ErrorCode.java +++ b/src/main/java/com/hyundai/app/exception/ErrorCode.java @@ -26,23 +26,17 @@ public enum ErrorCode { // 인증 및 인가 UNAUTHORIZED_ACCESS(UNAUTHORIZED, "인증되지 않은 사용자입니다."), FORBIDDEN_ACCESS(FORBIDDEN, "인가되지 않은 접근입니다."), - - // 리뷰 - REVIEW_SCORE_INVALID(BAD_REQUEST, "별점은 1~5점까지의 정수이어야 합니다."), - REVIEW_CONTENT_INVALID(BAD_REQUEST, "리뷰 내용은 최소 5자 이상이어야합니다."), - - // 아이디값 - STORE_ID_INVALID(BAD_REQUEST, "해당하는 매장 id가 없습니다."), - HASHTAG_ID_INVALID(BAD_REQUEST, "해당하는 해시태그 id가 없습니다."), - MEMBER_ID_INVALID(BAD_REQUEST, "해당하는 회원 id가 없습니다."), - MEMBER_NOT_EXIST(BAD_REQUEST, "해당하는 회원 oauth id가 존재하지 않습니다."), + MEMBER_NOT_EXIST(NOT_FOUND, "해당하는 회원 oauth id가 존재하지 않습니다."), // 이벤트 - EVENT_NOT_EXIST(BAD_REQUEST, "해당하는 이벤트가 존재하지 않습니다."), - EVENT_TYPE_NOT_EXIST(BAD_REQUEST, "이벤트 타입은 RESTAURANT, CAFE, SHOPPING, RANDOM 중 하나이어야 합니다."), + EVENT_NOT_EXIST(NOT_FOUND, "해당하는 이벤트가 존재하지 않습니다."), + EVENT_TYPE_INVALID(BAD_REQUEST, "이벤트 타입은 RESTAURANT, CAFE, SHOPPING, RANDOM 중 하나이어야 합니다."), // 매장 - STORE_NOT_EXIST(BAD_REQUEST, "해당하는 매장 id가 존재하지 않습니다."), + STORE_NOT_EXIST(NOT_FOUND, "해당하는 매장 id가 존재하지 않습니다."), + REVIEW_SCORE_INVALID(BAD_REQUEST, "별점은 1~5점까지의 정수이어야 합니다."), + REVIEW_CONTENT_INVALID(BAD_REQUEST, "리뷰 내용은 최소 5자 이상이어야합니다."), + HASHTAG_NOT_EXIST(NOT_FOUND, "해당하는 해시태그 id가 없습니다."), // 500 에러 SERVER_UNAVAILABLE(SERVICE_UNAVAILABLE, "서버에 오류가 발생하였습니다."), diff --git a/src/main/java/com/hyundai/app/store/service/StoreServiceImpl.java b/src/main/java/com/hyundai/app/store/service/StoreServiceImpl.java index 5d6ae86..446162d 100644 --- a/src/main/java/com/hyundai/app/store/service/StoreServiceImpl.java +++ b/src/main/java/com/hyundai/app/store/service/StoreServiceImpl.java @@ -85,6 +85,9 @@ public void createReview(int storeId, String memberId, ReviewReqDto reviewReqDto */ private double calcAvgScore(int storeId, int newScore) { Store store = storeMapper.getStoreDetail(storeId); + if (store == null) { + throw new AdventureOfHeendyException(STORE_NOT_EXIST); + } int reviewCount = store.getReviewCount(); float avgScore = store.getAvgScore(); log.debug("별점 업데이트 => reviewCount : " + reviewCount + ", avgScore : " + avgScore); @@ -150,7 +153,7 @@ private void handleStoreHashtag(int storeId, int hashtagId) { private void validateIfHashtagIdExist(int hashtagId) { if (hashtagMapper.getHashtag(hashtagId) == null) { log.error("해시태그 id: " + hashtagId + "가 존재하지 않습니다."); - throw new AdventureOfHeendyException(HASHTAG_ID_INVALID); + throw new AdventureOfHeendyException(HASHTAG_NOT_EXIST); } } } From 75a81190537f8798ec1f33662060743627d79cd9 Mon Sep 17 00:00:00 2001 From: sooyoung Date: Fri, 1 Mar 2024 20:52:19 +0900 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20JWT=20=ED=86=A0=ED=81=B0=20=ED=82=A4?= =?UTF-8?q?=EA=B0=92=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hyundai/app/member/service/MemberServiceImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java b/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java index d8018c5..d05128d 100644 --- a/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java +++ b/src/main/java/com/hyundai/app/member/service/MemberServiceImpl.java @@ -88,9 +88,8 @@ private LoginResDto getUpdatedToken(Member member) { * oauth id값으로 회원가입 */ public LoginResDto joinByOauthId(String email, OauthType oauthType) { - String oauthId = oauthType.createOauthIdWithEmail(email); - LoginResDto loginResDto = authTokenGenerator.createLoginResDto(oauthId); String memberId = UUID.randomUUID().toString(); + LoginResDto loginResDto = authTokenGenerator.createLoginResDto(memberId); String qrUrl = generateQrCodeAndUploadToS3(memberId); Member member = Member.builder() @@ -98,7 +97,7 @@ public LoginResDto joinByOauthId(String email, OauthType oauthType) { .email(email) .nickname(Nickname.getRandomNickname()) .role(Role.ROLE_MEMBER) - .oauthId(oauthId) + .oauthId(oauthType.createOauthIdWithEmail(email)) .refreshToken(loginResDto.getRefreshToken()) .qrUrl(qrUrl) .build();