From 77df5478b6b61a0d318ad89325fa53bcf411c32f Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 11:52:41 +0900 Subject: [PATCH 01/24] chore: update yml --- DDANZI_Server_yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DDANZI_Server_yml b/DDANZI_Server_yml index 08df0935..5e1da6f7 160000 --- a/DDANZI_Server_yml +++ b/DDANZI_Server_yml @@ -1 +1 @@ -Subproject commit 08df093502327ec7bf86f1dfc54945093d2a3cb4 +Subproject commit 5e1da6f7c2902ee36cced0cf73445120b1fcc4f6 From ca9480051b4aeee3be08b0974f6ac483c2246567 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 20:31:12 +0900 Subject: [PATCH 02/24] feat: add security, jwt dependency --- build.gradle | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index e3d789d7..38b23179 100644 --- a/build.gradle +++ b/build.gradle @@ -23,17 +23,21 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' + //lombok + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' //jpa implementation 'org.springframework.boot:spring-boot-starter-data-jpa' // mysql implementation 'mysql:mysql-connector-java:8.0.32' //redis implementation 'org.springframework.boot:spring-boot-starter-data-redis' - - //lombok - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' - + // security + implementation 'org.springframework.boot:spring-boot-starter-security' + //jwt + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' + implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' testImplementation 'org.springframework.boot:spring-boot-starter-test' } From 3498f05f1a78f8e367a4f4e4ecd2e34e237f4bf2 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 20:31:26 +0900 Subject: [PATCH 03/24] feat: create security config --- .../config/security/SecurityConfig.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java diff --git a/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java b/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java new file mode 100644 index 00000000..7ba64dec --- /dev/null +++ b/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java @@ -0,0 +1,38 @@ +package co.orange.ddanzi.global.config.security; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Configurable; +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer; +import org.springframework.security.web.SecurityFilterChain; + +@Configurable +@EnableWebSecurity +@RequiredArgsConstructor +public class SecurityConfig { + + private String[] permitList = { + "/api/v1/auth/**", + "/api/v1/home/**", + "/api/v1/search/**", + }; + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .httpBasic(HttpBasicConfigurer::disable) + .csrf(AbstractHttpConfigurer::disable) + .formLogin(AbstractHttpConfigurer::disable) + .sessionManagement(AbstractHttpConfigurer::disable) + .authorizeHttpRequests((authorizeRequests) -> { + authorizeRequests + .requestMatchers(permitList).permitAll() + .anyRequest().authenticated(); + }) + .addFilterBefore(); + return http.build(); + } +} From 8a261e617bd6071d708fd8c866693d4b745f1a05 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 20:40:21 +0900 Subject: [PATCH 04/24] refactor: rename folder --- src/main/java/co/orange/ddanzi/controller/ItemController.java | 2 +- .../ddanzi/global/common/{exception => error}/Error.java | 2 +- .../global/common/{exception => error}/ErrorResponse.java | 2 +- .../co/orange/ddanzi/global/common/response/ApiResponse.java | 2 +- .../ddanzi/global/config/handler/GlobalExceptionHandler.java | 4 ++-- src/main/java/co/orange/ddanzi/service/HomeService.java | 2 +- src/main/java/co/orange/ddanzi/service/InterestService.java | 3 +-- src/main/java/co/orange/ddanzi/service/ItemService.java | 2 +- src/main/java/co/orange/ddanzi/service/ProductService.java | 2 +- src/main/java/co/orange/ddanzi/service/SettingService.java | 2 +- 10 files changed, 11 insertions(+), 12 deletions(-) rename src/main/java/co/orange/ddanzi/global/common/{exception => error}/Error.java (97%) rename src/main/java/co/orange/ddanzi/global/common/{exception => error}/ErrorResponse.java (97%) diff --git a/src/main/java/co/orange/ddanzi/controller/ItemController.java b/src/main/java/co/orange/ddanzi/controller/ItemController.java index f11aac42..9c60ca79 100644 --- a/src/main/java/co/orange/ddanzi/controller/ItemController.java +++ b/src/main/java/co/orange/ddanzi/controller/ItemController.java @@ -3,7 +3,7 @@ import co.orange.ddanzi.domain.user.User; import co.orange.ddanzi.dto.item.ConfirmProductRequestDto; import co.orange.ddanzi.dto.item.SaveItemRequestDto; -import co.orange.ddanzi.global.common.exception.Error; +import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.repository.AddressRepository; import co.orange.ddanzi.repository.UserRepository; diff --git a/src/main/java/co/orange/ddanzi/global/common/exception/Error.java b/src/main/java/co/orange/ddanzi/global/common/error/Error.java similarity index 97% rename from src/main/java/co/orange/ddanzi/global/common/exception/Error.java rename to src/main/java/co/orange/ddanzi/global/common/error/Error.java index a935cce4..e001b89d 100644 --- a/src/main/java/co/orange/ddanzi/global/common/exception/Error.java +++ b/src/main/java/co/orange/ddanzi/global/common/error/Error.java @@ -1,4 +1,4 @@ -package co.orange.ddanzi.global.common.exception; +package co.orange.ddanzi.global.common.error; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/co/orange/ddanzi/global/common/exception/ErrorResponse.java b/src/main/java/co/orange/ddanzi/global/common/error/ErrorResponse.java similarity index 97% rename from src/main/java/co/orange/ddanzi/global/common/exception/ErrorResponse.java rename to src/main/java/co/orange/ddanzi/global/common/error/ErrorResponse.java index 489c84a8..cfa70871 100644 --- a/src/main/java/co/orange/ddanzi/global/common/exception/ErrorResponse.java +++ b/src/main/java/co/orange/ddanzi/global/common/error/ErrorResponse.java @@ -1,4 +1,4 @@ -package co.orange.ddanzi.global.common.exception; +package co.orange.ddanzi.global.common.error; import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.servlet.http.HttpServletRequest; diff --git a/src/main/java/co/orange/ddanzi/global/common/response/ApiResponse.java b/src/main/java/co/orange/ddanzi/global/common/response/ApiResponse.java index afa70069..0da8b88c 100644 --- a/src/main/java/co/orange/ddanzi/global/common/response/ApiResponse.java +++ b/src/main/java/co/orange/ddanzi/global/common/response/ApiResponse.java @@ -1,6 +1,6 @@ package co.orange.ddanzi.global.common.response; -import co.orange.ddanzi.global.common.exception.Error; +import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.config.handler.GlobalControllerHandler; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/co/orange/ddanzi/global/config/handler/GlobalExceptionHandler.java b/src/main/java/co/orange/ddanzi/global/config/handler/GlobalExceptionHandler.java index e64155b5..62e6247e 100644 --- a/src/main/java/co/orange/ddanzi/global/config/handler/GlobalExceptionHandler.java +++ b/src/main/java/co/orange/ddanzi/global/config/handler/GlobalExceptionHandler.java @@ -1,7 +1,7 @@ package co.orange.ddanzi.global.config.handler; -import co.orange.ddanzi.global.common.exception.Error; -import co.orange.ddanzi.global.common.exception.ErrorResponse; +import co.orange.ddanzi.global.common.error.Error; +import co.orange.ddanzi.global.common.error.ErrorResponse; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/co/orange/ddanzi/service/HomeService.java b/src/main/java/co/orange/ddanzi/service/HomeService.java index 112b0908..e98b5b16 100644 --- a/src/main/java/co/orange/ddanzi/service/HomeService.java +++ b/src/main/java/co/orange/ddanzi/service/HomeService.java @@ -4,7 +4,7 @@ import co.orange.ddanzi.domain.product.*; import co.orange.ddanzi.dto.ProductInfo; import co.orange.ddanzi.dto.home.*; -import co.orange.ddanzi.global.common.exception.Error; +import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; import co.orange.ddanzi.global.redis.RedisRepository; diff --git a/src/main/java/co/orange/ddanzi/service/InterestService.java b/src/main/java/co/orange/ddanzi/service/InterestService.java index 396d9cca..4e158525 100644 --- a/src/main/java/co/orange/ddanzi/service/InterestService.java +++ b/src/main/java/co/orange/ddanzi/service/InterestService.java @@ -3,9 +3,8 @@ import co.orange.ddanzi.domain.product.Product; import co.orange.ddanzi.domain.user.InterestProduct; import co.orange.ddanzi.domain.user.User; -import co.orange.ddanzi.domain.user.pk.InterestProductId; import co.orange.ddanzi.dto.interest.InterestResponseDto; -import co.orange.ddanzi.global.common.exception.Error; +import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; import co.orange.ddanzi.repository.InterestProductRepository; diff --git a/src/main/java/co/orange/ddanzi/service/ItemService.java b/src/main/java/co/orange/ddanzi/service/ItemService.java index 1fc8d318..41ee49f9 100644 --- a/src/main/java/co/orange/ddanzi/service/ItemService.java +++ b/src/main/java/co/orange/ddanzi/service/ItemService.java @@ -5,7 +5,7 @@ import co.orange.ddanzi.domain.user.User; import co.orange.ddanzi.dto.item.SaveItemRequestDto; import co.orange.ddanzi.dto.item.SaveItemResponseDto; -import co.orange.ddanzi.global.common.exception.Error; +import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; import co.orange.ddanzi.repository.*; diff --git a/src/main/java/co/orange/ddanzi/service/ProductService.java b/src/main/java/co/orange/ddanzi/service/ProductService.java index 9421e20c..a8f65583 100644 --- a/src/main/java/co/orange/ddanzi/service/ProductService.java +++ b/src/main/java/co/orange/ddanzi/service/ProductService.java @@ -9,7 +9,7 @@ import co.orange.ddanzi.dto.item.ConfirmProductRequestDto; import co.orange.ddanzi.dto.item.ConfirmProductResponseDto; import co.orange.ddanzi.dto.order.CheckProductResponseDto; -import co.orange.ddanzi.global.common.exception.Error; +import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; import co.orange.ddanzi.repository.*; diff --git a/src/main/java/co/orange/ddanzi/service/SettingService.java b/src/main/java/co/orange/ddanzi/service/SettingService.java index 145e0fe2..6489bfa8 100644 --- a/src/main/java/co/orange/ddanzi/service/SettingService.java +++ b/src/main/java/co/orange/ddanzi/service/SettingService.java @@ -2,7 +2,7 @@ import co.orange.ddanzi.domain.user.*; import co.orange.ddanzi.dto.setting.*; -import co.orange.ddanzi.global.common.exception.Error; +import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; import co.orange.ddanzi.repository.AccountRepository; From 40ab18fc41e461dd1b3c90df9772962dab416ea8 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 20:58:35 +0900 Subject: [PATCH 05/24] feat: add jwt setting --- DDANZI_Server_yml | 2 +- src/main/resources/application.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DDANZI_Server_yml b/DDANZI_Server_yml index 5e1da6f7..8912613f 160000 --- a/DDANZI_Server_yml +++ b/DDANZI_Server_yml @@ -1 +1 @@ -Subproject commit 5e1da6f7c2902ee36cced0cf73445120b1fcc4f6 +Subproject commit 8912613fdfde0c13ecf1d5bf62cf28571f1a3f57 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cacc530a..eb86b49f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: - active: db + active: db, product From af11415d32ae92a878fb2b8baa1243eba49c1846 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 20:58:55 +0900 Subject: [PATCH 06/24] feat: create api exception --- .../ddanzi/global/common/error/Error.java | 5 ++++- .../global/common/exception/ApiException.java | 18 ++++++++++++++++++ .../exception/UnauthorizedException.java | 9 +++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/main/java/co/orange/ddanzi/global/common/exception/ApiException.java create mode 100644 src/main/java/co/orange/ddanzi/global/common/exception/UnauthorizedException.java diff --git a/src/main/java/co/orange/ddanzi/global/common/error/Error.java b/src/main/java/co/orange/ddanzi/global/common/error/Error.java index e001b89d..484a8a64 100644 --- a/src/main/java/co/orange/ddanzi/global/common/error/Error.java +++ b/src/main/java/co/orange/ddanzi/global/common/error/Error.java @@ -16,7 +16,10 @@ public enum Error { DUE_DATE_IS_INCORRECT(HttpStatus.BAD_REQUEST, "The due date is incorrect."), // 401 UNAUTHORIZED - + INVALID_JWT_EXCEPTION(HttpStatus.UNAUTHORIZED, "Invalid JWT"), + LOG_OUT_JWT_TOKEN(HttpStatus.UNAUTHORIZED,"Logged out user"), + JWT_EXPIRED(HttpStatus.UNAUTHORIZED,"JWT expired"), + JWT_TOKEN_NOT_EXISTS(HttpStatus.UNAUTHORIZED,"JWT value does not exist in header"), // 403 Forbidden diff --git a/src/main/java/co/orange/ddanzi/global/common/exception/ApiException.java b/src/main/java/co/orange/ddanzi/global/common/exception/ApiException.java new file mode 100644 index 00000000..6ee07f01 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/global/common/exception/ApiException.java @@ -0,0 +1,18 @@ +package co.orange.ddanzi.global.common.exception; + +import co.orange.ddanzi.global.common.error.Error; +import lombok.Getter; + +@Getter +public class ApiException extends RuntimeException { + private final Error error; + + public ApiException(Error error){ + super(error.getMessage()); + this.error = error; + } + + public int getHttpStatus(){ + return error.getHttpStatusCode(); + } +} \ No newline at end of file diff --git a/src/main/java/co/orange/ddanzi/global/common/exception/UnauthorizedException.java b/src/main/java/co/orange/ddanzi/global/common/exception/UnauthorizedException.java new file mode 100644 index 00000000..b1043e0a --- /dev/null +++ b/src/main/java/co/orange/ddanzi/global/common/exception/UnauthorizedException.java @@ -0,0 +1,9 @@ +package co.orange.ddanzi.global.common.exception; + +import co.orange.ddanzi.global.common.error.Error; + +public class UnauthorizedException extends ApiException{ + public UnauthorizedException(Error error) { + super(error); + } +} \ No newline at end of file From 0980e9ffc99497e61b32190f7f34c45a1764e936 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 20:59:16 +0900 Subject: [PATCH 07/24] feat: create jwt utils --- .../ddanzi/global/config/jwt/JwtUtils.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java diff --git a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java new file mode 100644 index 00000000..d287dfa8 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java @@ -0,0 +1,109 @@ +package co.orange.ddanzi.global.config.jwt; + +import co.orange.ddanzi.global.common.error.Error; +import co.orange.ddanzi.global.common.exception.UnauthorizedException; +import io.jsonwebtoken.*; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; + +import java.util.Collections; +import java.util.Date; + + +@Slf4j +@RequiredArgsConstructor +@Component +public class JwtUtils { + + @Value("${secret.time.access}") + private long accessTokenTime; + @Value("${secret.time.refresh}") + private long refreshTokenTime; + @Value("${secret.key}") + private String jwtSecretKey; + private final StringRedisTemplate stringRedisTemplate; + + public String createAccessToken(String idToken) { + Claims claims = Jwts.claims(); + claims.put("idToken", idToken); + long validTime = accessTokenTime; + Date now = new Date(); + return Jwts.builder() + .setClaims(claims) + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + validTime)) + .signWith(SignatureAlgorithm.HS256, jwtSecretKey) + .compact(); + } + + public String resolveJWT(HttpServletRequest request) { + String bearerToken = request.getHeader("Authorization"); + if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) { + return bearerToken.substring(7); + } else { + return null; + } + } + + public Authentication getAuthentication(String token) { + // 토큰 복호화 + Claims claims = getClaims(token); + + if (claims.get("idToken") == null) { + throw new UnauthorizedException(Error.INVALID_JWT_EXCEPTION); + } + + // UserDetails 객체를 생성하여 Authentication 반환 + UserDetails principal = new User(getIdTokenFromToken(token), "", Collections.emptyList()); + return new UsernamePasswordAuthenticationToken(principal, "", Collections.emptyList()); + } + + + public boolean validateToken(String token) { + if (!StringUtils.hasText(token)) { + throw new UnauthorizedException(Error.JWT_TOKEN_NOT_EXISTS); + } + if(isLogout(token)){ + throw new UnauthorizedException(Error.LOG_OUT_JWT_TOKEN); + } + try { + Claims claims = Jwts.parser().setSigningKey(jwtSecretKey).parseClaimsJws(token).getBody(); + log.info("token \"role\" : " + claims.get("role")); + log.info("token \"name\" : " + claims.get("name")); + return true; + } catch (MalformedJwtException e) { + throw new UnauthorizedException(Error.INVALID_JWT_EXCEPTION); + } catch (ExpiredJwtException e) { + throw new UnauthorizedException(Error.JWT_EXPIRED); + } catch (UnauthorizedException e) { + return false; + } + } + + public String getIdTokenFromToken(String token) { + return getClaims(token).get("idToken").toString(); + } + + + public Claims getClaims(String token) { + return Jwts.parser().setSigningKey(jwtSecretKey).parseClaimsJws(token).getBody(); + } + + public boolean isLogout(String accessToken) { + return !ObjectUtils.isEmpty(stringRedisTemplate.opsForValue().get(accessToken)); + } + + + +} From 11c896fb540d38421432072abc0994c13af142d5 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 20:59:21 +0900 Subject: [PATCH 08/24] feat: create jwt filter --- .../ddanzi/global/config/jwt/JwtFilter.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java diff --git a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java new file mode 100644 index 00000000..59d7814e --- /dev/null +++ b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java @@ -0,0 +1,37 @@ +package co.orange.ddanzi.global.config.jwt; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; + +@Slf4j +@RequiredArgsConstructor +@Component +public class JwtFilter extends OncePerRequestFilter { + private final JwtUtils jwtUtils; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + + String token = jwtUtils.resolveJWT(request); + log.info("Request to {}: token={}", request.getRequestURI(), token); + + if (jwtUtils.validateToken(token)) { + // 2-1. 토큰이 유효할 경우 토큰에서 Authentication 객체를 가지고 와서 SecurityContext에 저장 + Authentication authentication = jwtUtils.getAuthentication(token); + SecurityContextHolder.getContext().setAuthentication(authentication); + } + + filterChain.doFilter(request, response); + } + +} From 1295a28a0b65868676c855672b4510c0a3c8cb81 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 22 Jul 2024 20:59:31 +0900 Subject: [PATCH 09/24] feat: set jwtfilter --- .../ddanzi/global/config/security/SecurityConfig.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java b/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java index 7ba64dec..0c9bb88a 100644 --- a/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java +++ b/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java @@ -1,5 +1,7 @@ package co.orange.ddanzi.global.config.security; +import co.orange.ddanzi.global.config.jwt.JwtFilter; +import co.orange.ddanzi.global.config.jwt.JwtUtils; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Configurable; import org.springframework.context.annotation.Bean; @@ -8,12 +10,15 @@ import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; @Configurable @EnableWebSecurity @RequiredArgsConstructor public class SecurityConfig { + private final JwtUtils jwtUtils; + private String[] permitList = { "/api/v1/auth/**", "/api/v1/home/**", @@ -32,7 +37,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers(permitList).permitAll() .anyRequest().authenticated(); }) - .addFilterBefore(); + .addFilterBefore(new JwtFilter(jwtUtils), UsernamePasswordAuthenticationFilter.class); return http.build(); } } From 2825a0bf714c65d49b2f06cec71c16c8fda1cdce Mon Sep 17 00:00:00 2001 From: kang Date: Thu, 8 Aug 2024 01:00:55 +0900 Subject: [PATCH 10/24] feat: add notFilter method --- .../co/orange/ddanzi/global/config/jwt/JwtFilter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java index 59d7814e..04dfa113 100644 --- a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java +++ b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java @@ -26,7 +26,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse log.info("Request to {}: token={}", request.getRequestURI(), token); if (jwtUtils.validateToken(token)) { - // 2-1. 토큰이 유효할 경우 토큰에서 Authentication 객체를 가지고 와서 SecurityContext에 저장 Authentication authentication = jwtUtils.getAuthentication(token); SecurityContextHolder.getContext().setAuthentication(authentication); } @@ -34,4 +33,12 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse filterChain.doFilter(request, response); } + @Override + protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { + String path = request.getRequestURI(); + return path.startsWith("/api/v1/auth") + || path.equals("/api/v1/home") + || path.equals("/api/v1/search") + ; + } } From 4b01c6a1be4dbd8b23e6d202e8d650723ec86656 Mon Sep 17 00:00:00 2001 From: kang Date: Thu, 8 Aug 2024 01:01:30 +0900 Subject: [PATCH 11/24] chore: add debug option --- .../config/security/SecurityConfig.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java b/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java index 0c9bb88a..dcca0387 100644 --- a/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java +++ b/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java @@ -3,40 +3,40 @@ import co.orange.ddanzi.global.config.jwt.JwtFilter; import co.orange.ddanzi.global.config.jwt.JwtUtils; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Configurable; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; -import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -@Configurable -@EnableWebSecurity +@Configuration @RequiredArgsConstructor +@EnableWebSecurity(debug = true) public class SecurityConfig { private final JwtUtils jwtUtils; private String[] permitList = { "/api/v1/auth/**", + "/api/v1/auth/signin/test", "/api/v1/home/**", - "/api/v1/search/**", + "/api/v1/search/**" }; @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http - .httpBasic(HttpBasicConfigurer::disable) + .httpBasic(AbstractHttpConfigurer::disable) .csrf(AbstractHttpConfigurer::disable) .formLogin(AbstractHttpConfigurer::disable) .sessionManagement(AbstractHttpConfigurer::disable) - .authorizeHttpRequests((authorizeRequests) -> { - authorizeRequests - .requestMatchers(permitList).permitAll() - .anyRequest().authenticated(); - }) + .authorizeHttpRequests((authorizeRequests) -> + authorizeRequests + .requestMatchers(permitList).permitAll() + .anyRequest().authenticated() + ) .addFilterBefore(new JwtFilter(jwtUtils), UsernamePasswordAuthenticationFilter.class); return http.build(); } From 465032de2a9506406d0dfbb0a29eee81635ab5e1 Mon Sep 17 00:00:00 2001 From: kang Date: Thu, 8 Aug 2024 01:03:05 +0900 Subject: [PATCH 12/24] chore: delete unused part --- .../orange/ddanzi/global/config/jwt/JwtUtils.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java index d287dfa8..fc5462cb 100644 --- a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java +++ b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java @@ -28,8 +28,10 @@ public class JwtUtils { @Value("${secret.time.access}") private long accessTokenTime; + @Value("${secret.time.refresh}") private long refreshTokenTime; + @Value("${secret.key}") private String jwtSecretKey; private final StringRedisTemplate stringRedisTemplate; @@ -47,6 +49,8 @@ public String createAccessToken(String idToken) { .compact(); } + + public String resolveJWT(HttpServletRequest request) { String bearerToken = request.getHeader("Authorization"); if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) { @@ -70,16 +74,17 @@ public Authentication getAuthentication(String token) { } + public boolean validateToken(String token) { if (!StringUtils.hasText(token)) { throw new UnauthorizedException(Error.JWT_TOKEN_NOT_EXISTS); } - if(isLogout(token)){ - throw new UnauthorizedException(Error.LOG_OUT_JWT_TOKEN); - } +// if(isLogout(token)){ +// throw new UnauthorizedException(Error.LOG_OUT_JWT_TOKEN); +// } try { Claims claims = Jwts.parser().setSigningKey(jwtSecretKey).parseClaimsJws(token).getBody(); - log.info("token \"role\" : " + claims.get("role")); + log.info("token \"id token\" : " + claims.get("role")); log.info("token \"name\" : " + claims.get("name")); return true; } catch (MalformedJwtException e) { From 307ab021513e58dfe54298f73d9326cc3e553599 Mon Sep 17 00:00:00 2001 From: kang Date: Thu, 8 Aug 2024 02:36:10 +0900 Subject: [PATCH 13/24] chore: modify comment --- .../java/co/orange/ddanzi/global/config/jwt/JwtUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java index fc5462cb..224b8248 100644 --- a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java +++ b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtUtils.java @@ -8,7 +8,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; -import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.beans.factory.annotation.Value; @@ -34,13 +33,16 @@ public class JwtUtils { @Value("${secret.key}") private String jwtSecretKey; + private final StringRedisTemplate stringRedisTemplate; public String createAccessToken(String idToken) { Claims claims = Jwts.claims(); claims.put("idToken", idToken); + long validTime = accessTokenTime; Date now = new Date(); + return Jwts.builder() .setClaims(claims) .setIssuedAt(now) @@ -63,7 +65,6 @@ public String resolveJWT(HttpServletRequest request) { public Authentication getAuthentication(String token) { // 토큰 복호화 Claims claims = getClaims(token); - if (claims.get("idToken") == null) { throw new UnauthorizedException(Error.INVALID_JWT_EXCEPTION); } @@ -84,8 +85,7 @@ public boolean validateToken(String token) { // } try { Claims claims = Jwts.parser().setSigningKey(jwtSecretKey).parseClaimsJws(token).getBody(); - log.info("token \"id token\" : " + claims.get("role")); - log.info("token \"name\" : " + claims.get("name")); + log.info("token \"id token\" : " + claims.get("idToken")); return true; } catch (MalformedJwtException e) { throw new UnauthorizedException(Error.INVALID_JWT_EXCEPTION); From 20fa50bc44b15fd500a3f4a3b86389f2bd4e6006 Mon Sep 17 00:00:00 2001 From: kang Date: Thu, 8 Aug 2024 02:36:27 +0900 Subject: [PATCH 14/24] feat: create AuthUtils --- .../ddanzi/global/config/jwt/AuthUtils.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.java diff --git a/src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.java b/src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.java new file mode 100644 index 00000000..4bad3e20 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.java @@ -0,0 +1,44 @@ +package co.orange.ddanzi.global.config.jwt; + +import co.orange.ddanzi.domain.user.User; +import co.orange.ddanzi.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Component; + +@Slf4j +@RequiredArgsConstructor +@Component +public class AuthUtils { + private final UserRepository userRepository; + + public User getUser() { + return userRepository.findByLoginId(getCurrentUserNickname()).get(); + } + + public Authentication getAuthentication() { + // SecurityContext에서 인증 정보 가져오기 + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + return authentication; + } + + public Object getPrincipal() { + // 현재 사용자의 principal 가져오기 + return getAuthentication().getPrincipal(); + + } + + public String getCurrentUserNickname() { + Object principalObject = getPrincipal(); + + if (principalObject instanceof UserDetails) { + UserDetails userDetails = (UserDetails) principalObject; + log.info("id token -> {}", userDetails.getUsername()); + return userDetails.getUsername(); + } + return null; + } +} From 6e92d1aa6b61407e679493d5bd3f1ddbbd39f29a Mon Sep 17 00:00:00 2001 From: kang Date: Thu, 8 Aug 2024 02:37:10 +0900 Subject: [PATCH 15/24] feat: test signin api --- .../ddanzi/controller/AuthController.java | 22 ++++++++++ .../ddanzi/dto/auth/AuthResponseDto.java | 11 +++++ .../co/orange/ddanzi/dto/auth/LoginDto.java | 11 +++++ .../co/orange/ddanzi/service/AuthService.java | 42 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/controller/AuthController.java create mode 100644 src/main/java/co/orange/ddanzi/dto/auth/AuthResponseDto.java create mode 100644 src/main/java/co/orange/ddanzi/dto/auth/LoginDto.java create mode 100644 src/main/java/co/orange/ddanzi/service/AuthService.java diff --git a/src/main/java/co/orange/ddanzi/controller/AuthController.java b/src/main/java/co/orange/ddanzi/controller/AuthController.java new file mode 100644 index 00000000..f1813314 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/controller/AuthController.java @@ -0,0 +1,22 @@ +package co.orange.ddanzi.controller; + +import co.orange.ddanzi.dto.auth.LoginDto; +import co.orange.ddanzi.global.common.response.ApiResponse; +import co.orange.ddanzi.service.AuthService; +import lombok.RequiredArgsConstructor; +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; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/v1/auth") +public class AuthController { + private final AuthService authService; + + @PostMapping("/signin/test") + ApiResponse signin(@RequestBody LoginDto requestDto){ + return authService.testSignin(requestDto.getIdToken()); + } +} diff --git a/src/main/java/co/orange/ddanzi/dto/auth/AuthResponseDto.java b/src/main/java/co/orange/ddanzi/dto/auth/AuthResponseDto.java new file mode 100644 index 00000000..a40ad46a --- /dev/null +++ b/src/main/java/co/orange/ddanzi/dto/auth/AuthResponseDto.java @@ -0,0 +1,11 @@ +package co.orange.ddanzi.dto.auth; + +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +public class AuthResponseDto { + private String accesstoken; + private String nickname; +} diff --git a/src/main/java/co/orange/ddanzi/dto/auth/LoginDto.java b/src/main/java/co/orange/ddanzi/dto/auth/LoginDto.java new file mode 100644 index 00000000..08d6a44c --- /dev/null +++ b/src/main/java/co/orange/ddanzi/dto/auth/LoginDto.java @@ -0,0 +1,11 @@ +package co.orange.ddanzi.dto.auth; + +import co.orange.ddanzi.domain.user.enums.LoginType; +import lombok.Getter; + +@Getter +public class LoginDto { + private String idToken; + private LoginType type; + +} diff --git a/src/main/java/co/orange/ddanzi/service/AuthService.java b/src/main/java/co/orange/ddanzi/service/AuthService.java new file mode 100644 index 00000000..3c3da45d --- /dev/null +++ b/src/main/java/co/orange/ddanzi/service/AuthService.java @@ -0,0 +1,42 @@ +package co.orange.ddanzi.service; + +import co.orange.ddanzi.domain.user.User; +import co.orange.ddanzi.dto.auth.AuthResponseDto; +import co.orange.ddanzi.global.common.error.Error; +import co.orange.ddanzi.global.common.response.ApiResponse; +import co.orange.ddanzi.global.common.response.Success; +import co.orange.ddanzi.global.config.jwt.JwtUtils; +import co.orange.ddanzi.repository.UserRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.Optional; + + +@Slf4j +@RequiredArgsConstructor +@Service +public class AuthService { + private final UserRepository userRepository; + private final JwtUtils jwtUtils; + + @Transactional + public ApiResponse testSignin(String idToken){ + + Optional optionalUser = userRepository.findByLoginId(idToken); + if(optionalUser.isEmpty()){ + return ApiResponse.onFailure(Error.ERROR, null); + } + User user = optionalUser.get(); + + AuthResponseDto responseDto = AuthResponseDto.builder() + .accesstoken(jwtUtils.createAccessToken(user.getLoginId())) + .nickname(user.getNickname()) + .build(); + return ApiResponse.onSuccess(Success.SUCCESS, responseDto); + } +} + + From 8a93eb859383be898b09cd3e384b95648025b782 Mon Sep 17 00:00:00 2001 From: kang Date: Thu, 8 Aug 2024 02:37:23 +0900 Subject: [PATCH 16/24] feat: create user repository --- src/main/java/co/orange/ddanzi/repository/UserRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/co/orange/ddanzi/repository/UserRepository.java b/src/main/java/co/orange/ddanzi/repository/UserRepository.java index c343075c..a9e4861e 100644 --- a/src/main/java/co/orange/ddanzi/repository/UserRepository.java +++ b/src/main/java/co/orange/ddanzi/repository/UserRepository.java @@ -3,5 +3,8 @@ import co.orange.ddanzi.domain.user.User; import org.springframework.data.repository.CrudRepository; +import java.util.Optional; + public interface UserRepository extends CrudRepository { + Optional findByLoginId(String loginId); } From 1e2c815c41134cf800207056fce205feebf097ce Mon Sep 17 00:00:00 2001 From: kang Date: Thu, 8 Aug 2024 02:48:48 +0900 Subject: [PATCH 17/24] feat: get user from authUtils --- .../ddanzi/service/InterestService.java | 9 ++++----- .../orange/ddanzi/service/MyPageService.java | 8 ++++---- .../orange/ddanzi/service/SettingService.java | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/service/InterestService.java b/src/main/java/co/orange/ddanzi/service/InterestService.java index 4e158525..814b507b 100644 --- a/src/main/java/co/orange/ddanzi/service/InterestService.java +++ b/src/main/java/co/orange/ddanzi/service/InterestService.java @@ -7,6 +7,7 @@ import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; +import co.orange.ddanzi.global.config.jwt.AuthUtils; import co.orange.ddanzi.repository.InterestProductRepository; import co.orange.ddanzi.repository.ProductRepository; import co.orange.ddanzi.repository.UserRepository; @@ -19,14 +20,13 @@ @RequiredArgsConstructor @Service public class InterestService { - private final UserRepository userRepository; + private final AuthUtils authUtils; private final ProductRepository productRepository; private final InterestProductRepository interestProductRepository; @Transactional public ApiResponse addInterest(String productId) { - log.info("사용자 조회", productId); - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); log.info("상품 조회 -> product_id: {}", productId); Product product = productRepository.findById(productId).orElse(null); @@ -48,8 +48,7 @@ public ApiResponse addInterest(String productId) { @Transactional public ApiResponse deleteInterest(String productId) { - log.info("사용자 조회", productId); - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); log.info("상품 조회 -> product_id: {}", productId); Product product = productRepository.findById(productId).orElse(null); diff --git a/src/main/java/co/orange/ddanzi/service/MyPageService.java b/src/main/java/co/orange/ddanzi/service/MyPageService.java index f88fb042..86da389e 100644 --- a/src/main/java/co/orange/ddanzi/service/MyPageService.java +++ b/src/main/java/co/orange/ddanzi/service/MyPageService.java @@ -6,6 +6,7 @@ import co.orange.ddanzi.dto.mypage.MyPageInterestResponseDto; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; +import co.orange.ddanzi.global.config.jwt.AuthUtils; import co.orange.ddanzi.repository.InterestProductRepository; import co.orange.ddanzi.repository.ProductRepository; import co.orange.ddanzi.repository.UserRepository; @@ -22,14 +23,13 @@ @RequiredArgsConstructor @Service public class MyPageService { + private final AuthUtils authUtils; private final HomeService homeService; - private final UserRepository userRepository; private final InterestProductRepository interestProductRepository; - private final ProductRepository productRepository; @Transactional public ApiResponse getMyPage(){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); String nickname = user.getNickname(); Map response = new HashMap<>(); response.put("nickname", nickname); @@ -38,7 +38,7 @@ public ApiResponse getMyPage(){ @Transactional public ApiResponse getInterest(){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); log.info("찜한 상품 찾기"); List productList = interestProductRepository.findProductsByUserId(user.getId()); log.info("찜한 상품의 정보 입력하기"); diff --git a/src/main/java/co/orange/ddanzi/service/SettingService.java b/src/main/java/co/orange/ddanzi/service/SettingService.java index 6489bfa8..f2404620 100644 --- a/src/main/java/co/orange/ddanzi/service/SettingService.java +++ b/src/main/java/co/orange/ddanzi/service/SettingService.java @@ -5,6 +5,7 @@ import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; +import co.orange.ddanzi.global.config.jwt.AuthUtils; import co.orange.ddanzi.repository.AccountRepository; import co.orange.ddanzi.repository.AddressRepository; import co.orange.ddanzi.repository.PushAlarmRepository; @@ -18,14 +19,14 @@ @RequiredArgsConstructor @Service public class SettingService { - private final UserRepository userRepository; + private final AuthUtils authUtils; private final AddressRepository addressRepository; private final AccountRepository accountRepository; private final PushAlarmRepository pushAlarmRepository; @Transactional public ApiResponse getSetting(){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); Authentication authentication = user.getAuthentication(); String name = null; String phone = null; if(authentication != null){ @@ -44,7 +45,7 @@ public ApiResponse getSetting(){ @Transactional public ApiResponse getAddress(){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); Address address = addressRepository.findByUser(user); AddressResponseDto responseDto = setAddressDto(address, user.getAuthentication()); return ApiResponse.onSuccess(Success.GET_SETTING_ADDRESS_SUCCESS, responseDto); @@ -52,7 +53,7 @@ public ApiResponse getAddress(){ @Transactional public ApiResponse addAddress(AddressRequestDto requestDto){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); Address newAddress = requestDto.toEntity(user); newAddress = addressRepository.save(newAddress); AddressResponseDto responseDto = setAddressDto(newAddress, user.getAuthentication()); @@ -61,7 +62,7 @@ public ApiResponse addAddress(AddressRequestDto requestDto){ @Transactional public ApiResponse updateAddress(Long addressId, AddressRequestDto requestDto){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); Address updatedAddress = addressRepository.findById(addressId).orElse(null); if(updatedAddress == null){ return ApiResponse.onFailure(Error.ADDRESS_NOT_FOUND, null); @@ -83,7 +84,7 @@ public ApiResponse deleteAddress(Long addressId){ @Transactional public ApiResponse getAccount(){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); Account account = accountRepository.findByUserId(user); AccountResponseDto responseDto = setAccountDto(account, user.getAuthentication()); return ApiResponse.onSuccess(Success.GET_SETTING_ACCOUNT_SUCCESS, responseDto); @@ -91,7 +92,7 @@ public ApiResponse getAccount(){ @Transactional public ApiResponse addAccount(AccountRequestDto requestDto){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); Authentication authentication = user.getAuthentication(); log.info("본인인증 여부 확인"); @@ -117,7 +118,7 @@ public ApiResponse addAccount(AccountRequestDto requestDto){ @Transactional public ApiResponse updateAccount(Long accountId, AccountRequestDto requestDto){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); Account updatedAccount = accountRepository.findById(accountId).orElse(null); if(updatedAccount == null){ return ApiResponse.onFailure(Error.ACCOUNT_NOT_FOUND, null); @@ -139,7 +140,7 @@ public ApiResponse deleteAccount(Long accountId){ @Transactional public ApiResponse updatePushAlarm(PushAlarmRequestDto requestDto){ - User user = userRepository.findById(1L).orElse(null); + User user = authUtils.getUser(); PushAlarm pushAlarm = pushAlarmRepository.findByUser(user); if(pushAlarm == null){ return ApiResponse.onFailure(Error.PUSH_ALARM_NOT_FOUND, null); From 64c226fc6ef91baa08f84bb0ec08f3db53021fca Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 10 Aug 2024 18:43:18 +0900 Subject: [PATCH 18/24] chore: add user not found exception --- .../java/co/orange/ddanzi/global/common/error/Error.java | 1 + .../global/common/exception/UserNotFoundException.java | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/global/common/exception/UserNotFoundException.java diff --git a/src/main/java/co/orange/ddanzi/global/common/error/Error.java b/src/main/java/co/orange/ddanzi/global/common/error/Error.java index 484a8a64..2686c2da 100644 --- a/src/main/java/co/orange/ddanzi/global/common/error/Error.java +++ b/src/main/java/co/orange/ddanzi/global/common/error/Error.java @@ -26,6 +26,7 @@ public enum Error { // 404 NOT FOUND AUTHENTICATION_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "The Authentication of user does not exist."), + USER_NOT_FOUND(HttpStatus.NOT_FOUND, "User does not exist."), PRODUCT_NOT_FOUND(HttpStatus.NOT_FOUND, "The product does not exist."), CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "The category of the product does not exist."), DISCOUNT_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "The discount info of the category does not exist."), diff --git a/src/main/java/co/orange/ddanzi/global/common/exception/UserNotFoundException.java b/src/main/java/co/orange/ddanzi/global/common/exception/UserNotFoundException.java new file mode 100644 index 00000000..0f002fc3 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/global/common/exception/UserNotFoundException.java @@ -0,0 +1,9 @@ +package co.orange.ddanzi.global.common.exception; + +import co.orange.ddanzi.global.common.error.Error; + +public class UserNotFoundException extends ApiException{ + public UserNotFoundException() { + super(Error.USER_NOT_FOUND); + } +} \ No newline at end of file From 9ab061e6454bcd0aae60774e41caa2a3c5c7370f Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 10 Aug 2024 18:43:51 +0900 Subject: [PATCH 19/24] feat: setting bearer token for home api --- .../co/orange/ddanzi/global/config/jwt/AuthUtils.java | 10 +++++++++- .../co/orange/ddanzi/global/config/jwt/JwtFilter.java | 6 ++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.java b/src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.java index 4bad3e20..665c7100 100644 --- a/src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.java +++ b/src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.java @@ -1,6 +1,7 @@ package co.orange.ddanzi.global.config.jwt; import co.orange.ddanzi.domain.user.User; +import co.orange.ddanzi.global.common.exception.UserNotFoundException; import co.orange.ddanzi.repository.UserRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -9,6 +10,7 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; + @Slf4j @RequiredArgsConstructor @Component @@ -16,7 +18,13 @@ public class AuthUtils { private final UserRepository userRepository; public User getUser() { - return userRepository.findByLoginId(getCurrentUserNickname()).get(); + String currentUserNickname = getCurrentUserNickname(); + if (currentUserNickname == null) { + return null; + } + return userRepository.findByLoginId(currentUserNickname) + .orElseThrow(() -> new UserNotFoundException()); + } public Authentication getAuthentication() { diff --git a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java index 04dfa113..e8110dd5 100644 --- a/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java +++ b/src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.java @@ -25,10 +25,13 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse String token = jwtUtils.resolveJWT(request); log.info("Request to {}: token={}", request.getRequestURI(), token); - if (jwtUtils.validateToken(token)) { + if (token != null && jwtUtils.validateToken(token)) { Authentication authentication = jwtUtils.getAuthentication(token); SecurityContextHolder.getContext().setAuthentication(authentication); } + else { + log.info("No valid token found, proceeding without authentication"); + } filterChain.doFilter(request, response); } @@ -37,7 +40,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { String path = request.getRequestURI(); return path.startsWith("/api/v1/auth") - || path.equals("/api/v1/home") || path.equals("/api/v1/search") ; } From 62b781f58bec26d8da4b886644564e62acf8760b Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 10 Aug 2024 18:55:56 +0900 Subject: [PATCH 20/24] feat: add isInterested field in productInfo dto --- src/main/java/co/orange/ddanzi/dto/ProductInfo.java | 1 + .../ddanzi/repository/InterestProductRepository.java | 2 ++ src/main/java/co/orange/ddanzi/service/HomeService.java | 9 +++++++-- .../java/co/orange/ddanzi/service/MyPageService.java | 2 +- .../java/co/orange/ddanzi/service/SearchService.java | 9 +++++++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/dto/ProductInfo.java b/src/main/java/co/orange/ddanzi/dto/ProductInfo.java index e7cf2381..f1533574 100644 --- a/src/main/java/co/orange/ddanzi/dto/ProductInfo.java +++ b/src/main/java/co/orange/ddanzi/dto/ProductInfo.java @@ -13,4 +13,5 @@ public class ProductInfo { private Integer originPrice; private Integer salePrice; private Integer interestCount; + private Boolean isInterested; } diff --git a/src/main/java/co/orange/ddanzi/repository/InterestProductRepository.java b/src/main/java/co/orange/ddanzi/repository/InterestProductRepository.java index a72cf80f..f8ab4fd0 100644 --- a/src/main/java/co/orange/ddanzi/repository/InterestProductRepository.java +++ b/src/main/java/co/orange/ddanzi/repository/InterestProductRepository.java @@ -13,6 +13,8 @@ public interface InterestProductRepository extends JpaRepository { + boolean existsByIdUserAndIdProduct(User user, Product product); + @Query("SELECT CASE WHEN COUNT(ip) > 1000 THEN 999 ELSE COUNT(ip) END FROM InterestProduct ip " + "WHERE ip.id.product.id = :productId") Integer countByProductIdWithLimit(@Param("productId") String productId); diff --git a/src/main/java/co/orange/ddanzi/service/HomeService.java b/src/main/java/co/orange/ddanzi/service/HomeService.java index e98b5b16..d813a069 100644 --- a/src/main/java/co/orange/ddanzi/service/HomeService.java +++ b/src/main/java/co/orange/ddanzi/service/HomeService.java @@ -2,11 +2,13 @@ import co.orange.ddanzi.domain.Banner; import co.orange.ddanzi.domain.product.*; +import co.orange.ddanzi.domain.user.User; import co.orange.ddanzi.dto.ProductInfo; import co.orange.ddanzi.dto.home.*; import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; +import co.orange.ddanzi.global.config.jwt.AuthUtils; import co.orange.ddanzi.global.redis.RedisRepository; import co.orange.ddanzi.repository.*; import jakarta.transaction.Transactional; @@ -22,6 +24,7 @@ @RequiredArgsConstructor @Service public class HomeService { + private final AuthUtils authUtils; private final ProductRepository productRepository; private final BannerRepository bannerRepository; private final DiscountRepository discountRepository; @@ -32,10 +35,11 @@ public class HomeService { @Transactional public ApiResponse getProductList(){ + User user = authUtils.getUser(); Banner banner = bannerRepository.findByIsSelected(Boolean.TRUE); List productList = productRepository.findAllByStock(0); - List productInfoList = setProductList(productList, interestProductRepository); + List productInfoList = setProductList(user, productList, interestProductRepository); HomeResponseDto responseDto = HomeResponseDto.builder() .homeImgUrl(banner.getImgUrl()) .productList(productInfoList).build(); @@ -94,7 +98,7 @@ public ApiResponse getProductDetail(String devicetoken, String productId){ return ApiResponse.onSuccess(Success.GET_PRODUCT_DETAIL_SUCCESS,responseDto); } - public List setProductList(List productList, InterestProductRepository interestProductRepository){ + public List setProductList(User user, List productList, InterestProductRepository interestProductRepository){ List productInfoList = new ArrayList<>(); for(Product product : productList){ Discount discount = discountRepository.findById(product.getId()).orElse(null); @@ -106,6 +110,7 @@ public List setProductList(List productList, InterestProdu .salePrice(product.getOriginPrice() - discount.getDiscountPrice()) .imgUrl(product.getImgUrl()) .interestCount(interestProductRepository.countByProductIdWithLimit(product.getId())) + .isInterested(interestProductRepository.existsByIdUserAndIdProduct(user, product)) .build()); } return productInfoList; diff --git a/src/main/java/co/orange/ddanzi/service/MyPageService.java b/src/main/java/co/orange/ddanzi/service/MyPageService.java index 86da389e..a515b362 100644 --- a/src/main/java/co/orange/ddanzi/service/MyPageService.java +++ b/src/main/java/co/orange/ddanzi/service/MyPageService.java @@ -42,7 +42,7 @@ public ApiResponse getInterest(){ log.info("찜한 상품 찾기"); List productList = interestProductRepository.findProductsByUserId(user.getId()); log.info("찜한 상품의 정보 입력하기"); - List productInfoList = homeService.setProductList(productList,interestProductRepository); + List productInfoList = homeService.setProductList(user, productList,interestProductRepository); MyPageInterestResponseDto responseDto = MyPageInterestResponseDto.builder() .totalCount(productList.size()) .productList(productInfoList) diff --git a/src/main/java/co/orange/ddanzi/service/SearchService.java b/src/main/java/co/orange/ddanzi/service/SearchService.java index a81b68d8..f57080f9 100644 --- a/src/main/java/co/orange/ddanzi/service/SearchService.java +++ b/src/main/java/co/orange/ddanzi/service/SearchService.java @@ -1,11 +1,13 @@ package co.orange.ddanzi.service; import co.orange.ddanzi.domain.product.Product; +import co.orange.ddanzi.domain.user.User; import co.orange.ddanzi.dto.ProductInfo; import co.orange.ddanzi.dto.search.SearchPageResponseDto; import co.orange.ddanzi.dto.search.SearchResultResponseDto; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; +import co.orange.ddanzi.global.config.jwt.AuthUtils; import co.orange.ddanzi.global.redis.RedisRepository; import co.orange.ddanzi.repository.InterestProductRepository; import co.orange.ddanzi.repository.ProductRepository; @@ -21,6 +23,7 @@ @RequiredArgsConstructor @Service public class SearchService { + private final AuthUtils authUtils; private final HomeService homeService; private final ProductRepository productRepository; private final InterestProductRepository interestProductRepository; @@ -28,11 +31,12 @@ public class SearchService { @Transactional public ApiResponse searchPage(String devicetoken) { + User user = authUtils.getUser(); List topSearchedList = List.of("예시1", "예시2", "예시3"); log.info("Searching page for devicetoken: {}", devicetoken); Set recentViewedProductIds = redisRepository.getRecentProducts(devicetoken); List productList = productRepository.findByIdIn(recentViewedProductIds); - List productInfoList = homeService.setProductList(productList, interestProductRepository); + List productInfoList = homeService.setProductList(user, productList, interestProductRepository); return ApiResponse.onSuccess(Success.GET_SEARCH_SCREEN_SUCCESS, SearchPageResponseDto.builder() .topSearchedList(topSearchedList) .recentlyViewedList(productInfoList) @@ -41,10 +45,11 @@ public ApiResponse searchPage(String devicetoken) { @Transactional public ApiResponse searchKeyword(String keyword) { + User user = authUtils.getUser(); List topSearchedList = List.of("예시1", "예시2", "예시3"); log.info("Search for keyword: {}", keyword); List productList = productRepository.findAllByName(keyword); - List productInfoList = homeService.setProductList(productList, interestProductRepository); + List productInfoList = homeService.setProductList(user, productList, interestProductRepository); return ApiResponse.onSuccess(Success.GET_SEARCH_RESULTS_SUCCESS, SearchResultResponseDto.builder() .topSearchedList(topSearchedList) .searchedProductList(productInfoList) From 73d1c56bd5b20c0424692d5d02d1fc7a8dcf40db Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 10 Aug 2024 18:58:26 +0900 Subject: [PATCH 21/24] chore: delete debug option --- .../co/orange/ddanzi/global/config/security/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java b/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java index dcca0387..5061cf56 100644 --- a/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java +++ b/src/main/java/co/orange/ddanzi/global/config/security/SecurityConfig.java @@ -13,7 +13,7 @@ @Configuration @RequiredArgsConstructor -@EnableWebSecurity(debug = true) +@EnableWebSecurity public class SecurityConfig { private final JwtUtils jwtUtils; From 6d02a494cad7d9f1f50eab4d1f11d503a495015a Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 10 Aug 2024 20:50:31 +0900 Subject: [PATCH 22/24] feat: create enter address api --- .../orange/ddanzi/controller/SettingController.java | 5 +++++ .../ddanzi/dto/setting/EnterAddressResponseDto.java | 11 +++++++++++ .../java/co/orange/ddanzi/service/SettingService.java | 11 +++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/dto/setting/EnterAddressResponseDto.java diff --git a/src/main/java/co/orange/ddanzi/controller/SettingController.java b/src/main/java/co/orange/ddanzi/controller/SettingController.java index 3936097f..15e340de 100644 --- a/src/main/java/co/orange/ddanzi/controller/SettingController.java +++ b/src/main/java/co/orange/ddanzi/controller/SettingController.java @@ -19,6 +19,11 @@ ApiResponse getSetting(){ return settingService.getSetting(); } + @GetMapping("/address/enter") + ApiResponse enterAddress(){ + return settingService.enterAddress(); + } + @GetMapping("/address") ApiResponse getAddress(){ return settingService.getAddress(); diff --git a/src/main/java/co/orange/ddanzi/dto/setting/EnterAddressResponseDto.java b/src/main/java/co/orange/ddanzi/dto/setting/EnterAddressResponseDto.java new file mode 100644 index 00000000..d907b793 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/dto/setting/EnterAddressResponseDto.java @@ -0,0 +1,11 @@ +package co.orange.ddanzi.dto.setting; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class EnterAddressResponseDto { + private String name; + private String phone; +} diff --git a/src/main/java/co/orange/ddanzi/service/SettingService.java b/src/main/java/co/orange/ddanzi/service/SettingService.java index f2404620..f96aab32 100644 --- a/src/main/java/co/orange/ddanzi/service/SettingService.java +++ b/src/main/java/co/orange/ddanzi/service/SettingService.java @@ -24,6 +24,7 @@ public class SettingService { private final AccountRepository accountRepository; private final PushAlarmRepository pushAlarmRepository; + @Transactional public ApiResponse getSetting(){ User user = authUtils.getUser(); @@ -43,6 +44,16 @@ public ApiResponse getSetting(){ return ApiResponse.onSuccess(Success.GET_SETTING_SCREEN_SUCCESS, responseDto); } + @Transactional + public ApiResponse enterAddress(){ + User user = authUtils.getUser(); + return ApiResponse.onSuccess(Success.GET_SETTING_ADDRESS_SUCCESS, EnterAddressResponseDto.builder() + .name(user.getAuthentication().getName()) + .phone(user.getAuthentication().getPhone()) + .build()); + } + + @Transactional public ApiResponse getAddress(){ User user = authUtils.getUser(); From 819297f22d8bb2a200a16e29eaa045788a1178d1 Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 10 Aug 2024 21:12:01 +0900 Subject: [PATCH 23/24] feat: add fields related recipient --- .../java/co/orange/ddanzi/domain/user/Address.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/co/orange/ddanzi/domain/user/Address.java b/src/main/java/co/orange/ddanzi/domain/user/Address.java index bc98a86a..5f99537a 100644 --- a/src/main/java/co/orange/ddanzi/domain/user/Address.java +++ b/src/main/java/co/orange/ddanzi/domain/user/Address.java @@ -18,6 +18,12 @@ public class Address { @Column(name = "address_id") private Long id; //주소 고유 ID + @Column(name = "recipient") + private String recipient; + + @Column(name = "recipient_phone") + private String recipientPhone; + @Column(name = "zip_code", nullable = false, length = 5) private String zipCode; //우편번호 @@ -36,8 +42,10 @@ public class Address { private User user; //회원:주소=1:N @Builder - public Address(String zipCode, AddressType type, String address, String detailAddress, User user) { + public Address(String zipCode, String recipient, String recipientPhone, AddressType type, String address, String detailAddress, User user) { this.zipCode = zipCode; + this.recipient = recipient; + this.recipientPhone = recipientPhone; this.type = type; this.address = address; this.detailAddress = detailAddress; @@ -46,6 +54,8 @@ public Address(String zipCode, AddressType type, String address, String detailAd public void update(AddressRequestDto requestDto){ this.zipCode = requestDto.getZipCode(); + this.recipient = requestDto.getRecipient(); + this.recipientPhone = requestDto.getRecipientPhone(); this.type = requestDto.getType(); this.address = requestDto.getAddress(); this.detailAddress = requestDto.getDetailAddress(); From 3e299e82cdf4401d244dcf922c3824396bd6ef16 Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 10 Aug 2024 21:12:17 +0900 Subject: [PATCH 24/24] feat: add fields related recipient --- .../ddanzi/dto/setting/AddressRequestDto.java | 4 ++++ .../ddanzi/dto/setting/AddressResponseDto.java | 4 ++-- .../orange/ddanzi/service/SettingService.java | 17 +++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/dto/setting/AddressRequestDto.java b/src/main/java/co/orange/ddanzi/dto/setting/AddressRequestDto.java index 9e729828..b19944c3 100644 --- a/src/main/java/co/orange/ddanzi/dto/setting/AddressRequestDto.java +++ b/src/main/java/co/orange/ddanzi/dto/setting/AddressRequestDto.java @@ -7,6 +7,8 @@ @Getter public class AddressRequestDto { + private String recipient; + private String recipientPhone; private String zipCode; private AddressType type; private String address; @@ -15,6 +17,8 @@ public class AddressRequestDto { public Address toEntity(User user){ return Address.builder() .user(user) + .recipient(recipient) + .recipientPhone(recipientPhone) .zipCode(zipCode) .type(type) .address(address) diff --git a/src/main/java/co/orange/ddanzi/dto/setting/AddressResponseDto.java b/src/main/java/co/orange/ddanzi/dto/setting/AddressResponseDto.java index e5ae7f60..d3a5b122 100644 --- a/src/main/java/co/orange/ddanzi/dto/setting/AddressResponseDto.java +++ b/src/main/java/co/orange/ddanzi/dto/setting/AddressResponseDto.java @@ -8,10 +8,10 @@ @Builder public class AddressResponseDto { private Long addressId; - private String name; + private String recipient; private String zipCode; private AddressType type; private String address; private String detailAddress; - private String phone; + private String recipientPhone; } diff --git a/src/main/java/co/orange/ddanzi/service/SettingService.java b/src/main/java/co/orange/ddanzi/service/SettingService.java index f96aab32..382cf2ea 100644 --- a/src/main/java/co/orange/ddanzi/service/SettingService.java +++ b/src/main/java/co/orange/ddanzi/service/SettingService.java @@ -44,6 +44,8 @@ public ApiResponse getSetting(){ return ApiResponse.onSuccess(Success.GET_SETTING_SCREEN_SUCCESS, responseDto); } + + @Transactional public ApiResponse enterAddress(){ User user = authUtils.getUser(); @@ -53,12 +55,11 @@ public ApiResponse enterAddress(){ .build()); } - @Transactional public ApiResponse getAddress(){ User user = authUtils.getUser(); Address address = addressRepository.findByUser(user); - AddressResponseDto responseDto = setAddressDto(address, user.getAuthentication()); + AddressResponseDto responseDto = setAddressDto(address); return ApiResponse.onSuccess(Success.GET_SETTING_ADDRESS_SUCCESS, responseDto); } @@ -67,7 +68,7 @@ public ApiResponse addAddress(AddressRequestDto requestDto){ User user = authUtils.getUser(); Address newAddress = requestDto.toEntity(user); newAddress = addressRepository.save(newAddress); - AddressResponseDto responseDto = setAddressDto(newAddress, user.getAuthentication()); + AddressResponseDto responseDto = setAddressDto(newAddress); return ApiResponse.onSuccess(Success.CREATE_ADDRESS_SUCCESS, responseDto); } @@ -79,7 +80,7 @@ public ApiResponse updateAddress(Long addressId, AddressRequestDto requestDto return ApiResponse.onFailure(Error.ADDRESS_NOT_FOUND, null); } updatedAddress.update(requestDto); - AddressResponseDto responseDto = setAddressDto(updatedAddress, user.getAuthentication()); + AddressResponseDto responseDto = setAddressDto(updatedAddress); return ApiResponse.onSuccess(Success.PUT_ADDRESS_SUCCESS, responseDto); } @@ -90,7 +91,7 @@ public ApiResponse deleteAddress(Long addressId){ return ApiResponse.onFailure(Error.ADDRESS_NOT_FOUND, null); } addressRepository.delete(deletedAddress); - return ApiResponse.onSuccess(Success.DELETE_ADDRESS_SUCCESS, null); + return ApiResponse.onSuccess(Success.DELETE_ADDRESS_SUCCESS, true); } @Transactional @@ -159,15 +160,15 @@ public ApiResponse updatePushAlarm(PushAlarmRequestDto requestDto){ pushAlarm.update(requestDto); return ApiResponse.onSuccess(Success.PUT_PUSH_ALARM_SUCCESS, null); } - private AddressResponseDto setAddressDto(Address address, Authentication authentication){ + private AddressResponseDto setAddressDto(Address address){ return AddressResponseDto.builder() .addressId(address != null ? address.getId() : null) - .name(authentication != null ? authentication.getName() : null) + .recipient(address != null ? address.getRecipient() : null) .zipCode(address != null ? address.getZipCode() : null) .type(address != null ? address.getType() : null) .address(address != null ? address.getAddress() : null) .detailAddress(address != null ? address.getDetailAddress() : null) - .phone(authentication != null ? authentication.getPhone() : null) + .recipientPhone(address != null ? address.getRecipientPhone() : null) .build(); }