From f3b4911a74149b5f9009439113bee5a5263dee44 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:09:44 +0900 Subject: [PATCH] =?UTF-8?q?NABI-253--hotfix=20:=20category=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20insert=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/category/entity/Category.java | 8 +-- .../security/jwt/provider/JwtProvider.java | 55 +++++++++---------- src/main/resources/data.sql | 18 +++--- 3 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/category/entity/Category.java b/src/main/java/org/prgrms/nabimarketbe/domain/category/entity/Category.java index 909cb867..8a761068 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/category/entity/Category.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/category/entity/Category.java @@ -1,5 +1,8 @@ package org.prgrms.nabimarketbe.domain.category.entity; +import lombok.Getter; +import lombok.NoArgsConstructor; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -9,9 +12,6 @@ import javax.persistence.Id; import javax.persistence.Table; -import lombok.Getter; -import lombok.NoArgsConstructor; - @Entity @Table(name = "categories") @Getter @@ -23,7 +23,7 @@ public class Category { private Long categoryId; @Enumerated(EnumType.STRING) - @Column(name = "category_name", nullable = false) + @Column(name = "category_name", nullable = false, unique = true) private CategoryEnum categoryName; public Category(CategoryEnum categoryName) { diff --git a/src/main/java/org/prgrms/nabimarketbe/global/security/jwt/provider/JwtProvider.java b/src/main/java/org/prgrms/nabimarketbe/global/security/jwt/provider/JwtProvider.java index eda7227c..6c94972b 100644 --- a/src/main/java/org/prgrms/nabimarketbe/global/security/jwt/provider/JwtProvider.java +++ b/src/main/java/org/prgrms/nabimarketbe/global/security/jwt/provider/JwtProvider.java @@ -1,22 +1,5 @@ package org.prgrms.nabimarketbe.global.security.jwt.provider; -import java.nio.charset.StandardCharsets; -import java.util.Date; -import java.util.Optional; - -import javax.annotation.PostConstruct; -import javax.servlet.http.HttpServletRequest; - -import org.prgrms.nabimarketbe.global.security.entity.RefreshToken; -import org.prgrms.nabimarketbe.global.security.jwt.dto.TokenResponseDTO; -import org.prgrms.nabimarketbe.global.security.jwt.repository.RefreshTokenRepository; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.stereotype.Component; - import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.Header; @@ -27,7 +10,22 @@ import io.jsonwebtoken.impl.Base64UrlCodec; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.transaction.annotation.Transactional; +import org.prgrms.nabimarketbe.global.security.entity.RefreshToken; +import org.prgrms.nabimarketbe.global.security.jwt.dto.TokenResponseDTO; +import org.prgrms.nabimarketbe.global.security.jwt.repository.RefreshTokenRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.servlet.http.HttpServletRequest; +import javax.transaction.Transactional; +import java.nio.charset.StandardCharsets; +import java.util.Date; +import java.util.Optional; @Slf4j @RequiredArgsConstructor @@ -63,18 +61,18 @@ public TokenResponseDTO createTokenDTO(Long userPk, String role) { Date now = new Date(); String accessToken = Jwts.builder() - .setHeaderParam(Header.TYPE, Header.JWT_TYPE) - .setClaims(claims) - .setIssuedAt(now) - .setExpiration(new Date(now.getTime() + accessTokenValidMillisecond)) - .signWith(SignatureAlgorithm.HS256, secretKey) - .compact(); + .setHeaderParam(Header.TYPE, Header.JWT_TYPE) + .setClaims(claims) + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + accessTokenValidMillisecond)) + .signWith(SignatureAlgorithm.HS256, secretKey) + .compact(); String refreshToken = Jwts.builder() - .setHeaderParam(Header.TYPE, Header.JWT_TYPE) - .setExpiration(new Date(now.getTime() + refreshTokenValidMillisecond)) - .signWith(SignatureAlgorithm.HS256, secretKey) - .compact(); + .setHeaderParam(Header.TYPE, Header.JWT_TYPE) + .setExpiration(new Date(now.getTime() + refreshTokenValidMillisecond)) + .signWith(SignatureAlgorithm.HS256, secretKey) + .compact(); RefreshToken refreshTokenEntity = new RefreshToken(userPk, refreshToken); @@ -85,6 +83,7 @@ public TokenResponseDTO createTokenDTO(Long userPk, String role) { () -> refreshTokenRepository.save(refreshTokenEntity) ); + return TokenResponseDTO.builder() .grantType("Bearer") .accessToken(accessToken) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index d61d969b..545f0b5c 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,9 +1,9 @@ -insert into categories(category_name) values ('MALE_CLOTHES'); -insert into categories(category_name) values ('FEMALE_CLOTHES'); -insert into categories(category_name) values ('GOODS_ACCESSORY'); -insert into categories(category_name) values ('SHOES'); -insert into categories(category_name) values ('SPORTS'); -insert into categories(category_name) values ('BOOKS'); -insert into categories(category_name) values ('ELECTRONICS'); -insert into categories(category_name) values ('FURNITURE_INTERIOR'); -insert into categories(category_name) values ('HOME_ELECTRONICS'); +insert ignore into categories(category_name) values ('MALE_CLOTHES'); +insert ignore into categories(category_name) values ('FEMALE_CLOTHES'); +insert ignore into categories(category_name) values ('GOODS_ACCESSORY'); +insert ignore into categories(category_name) values ('SHOES'); +insert ignore into categories(category_name) values ('SPORTS'); +insert ignore into categories(category_name) values ('BOOKS'); +insert ignore into categories(category_name) values ('ELECTRONICS'); +insert ignore into categories(category_name) values ('FURNITURE_INTERIOR'); +insert ignore into categories(category_name) values ('HOME_ELECTRONICS');