Skip to content

Commit

Permalink
Merge pull request #43 from team-nabi/NABI-253--beommo-hotfix-category
Browse files Browse the repository at this point in the history
NABI-253-- beommo hotfix category
  • Loading branch information
BeommoKoo-dev authored Nov 17, 2023
2 parents 2208207 + f3b4911 commit 9d1a985
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,9 +12,6 @@
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "categories")
@Getter
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -85,6 +83,7 @@ public TokenResponseDTO createTokenDTO(Long userPk, String role) {
() -> refreshTokenRepository.save(refreshTokenEntity)
);


return TokenResponseDTO.builder()
.grantType("Bearer")
.accessToken(accessToken)
Expand Down
18 changes: 9 additions & 9 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 9d1a985

Please sign in to comment.