Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

경북대 BE_김영인 6주차 과제(3단계) #324

Open
wants to merge 44 commits into
base: youngini
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
199525a
feat: setup the project
Youngini Jul 29, 2024
cd6fec9
feat : merge the project
Youngini Jul 29, 2024
6748dfc
docs(README.md) : API 명세서 수정 사항 점검 리스트
Youngini Jul 31, 2024
62b5448
feat(Member) : 일반 회원가입 로직 확인
Youngini Jul 31, 2024
0096f76
feat(Member) : 일반 로그인 로직 확인
Youngini Jul 31, 2024
c3fb376
feat(Product) : 제품 옵션 조회
Youngini Jul 31, 2024
597895b
feat(Product) : 특정 제품의 옵션 조회
Youngini Jul 31, 2024
6363d39
feat(Product) : 특정 카테고리별 상품 목록 조회
Youngini Jul 31, 2024
2e76903
feat(Category) : 모든 카테고리 조회
Youngini Jul 31, 2024
5d6dbed
feat(wish) : 위시 리스트에 추가
Youngini Jul 31, 2024
0ef82ad
feat(wish) : 위시 리스트에서 삭제
Youngini Jul 31, 2024
f5152fb
feat(wish) : 위시 리스트 목록 반환
Youngini Jul 31, 2024
5825161
feat(Order) : 주문 생성
Youngini Jul 31, 2024
2e270c5
refactor : 실행 시 발생하는 오류 수정
Youngini Jul 31, 2024
974ee7a
feat(WebConfig) : Swagger 사용 시 발생하는 HttpMediaTypeNotAcceptableExcepti…
Youngini Jul 31, 2024
55fa3ac
refactor(JoinResponse) : 회원가입 시, 응답 용어 수정
Youngini Jul 31, 2024
f835073
refactor(Order) : 주문생성시, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
5fd2840
refactor(Category) :카테고리 목록의, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
71432fd
refactor(Product) : Product API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
38e745e
refactor(Order) : Order API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
51f5d20
refactor(wish) : wish API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
3d71aa0
refactor(Member) : 생성자 만듦
Youngini Jul 31, 2024
471460d
refactor(Member) : Json 인식 못하는 문제 해결
Youngini Jul 31, 2024
bff484a
refactor(JwtConfig) : token 생성 오류 해결
Youngini Jul 31, 2024
e61f013
fwat(JwtConfig) : token으로 email 추출
Youngini Jul 31, 2024
3dea571
feat(Entity) : 생성자 만듦
Youngini Jul 31, 2024
f2d5530
build(application.properties) : 디비 실행되도 생성이아니라 업데이트가 되도록 수정
Youngini Jul 31, 2024
ca67821
refactor(Controller) : Pageable 객체 인수를 size, page로 변경
Youngini Jul 31, 2024
3678425
build(application) : RDS 연결
Youngini Aug 1, 2024
85aeccb
build : RDS 연결
Youngini Aug 1, 2024
ab006ac
refactor : option 예약어로 변경
Youngini Aug 1, 2024
237d0b5
feat(webConfig) : cors 에러 해결
Youngini Aug 1, 2024
cf881ae
build(appliaction) : DB를 실행될때 생성이 아닌, 업데이트 되도록 수정
Youngini Aug 1, 2024
851b190
docs(README.md) : 2단계 구현할 목록 작성 완료
Youngini Aug 1, 2024
ddf2bab
refactore(productController) : endPoint 오류 수정
Youngini Aug 1, 2024
148fca7
refactore(JwtConfig) : Bearer로 인한 토큰 인식 에러 해결
Youngini Aug 2, 2024
cc39ef0
docs(README.md) : 3단계 구현할 기능 정리
Youngini Aug 2, 2024
3dd5e61
feat(member) : point 변수 추가
Youngini Aug 2, 2024
c21364b
refactor(member) : point 변수 수정
Youngini Aug 2, 2024
5e5ed90
feat(memberController) : 특정 회원의 point를 가져오는 api 구현
Youngini Aug 2, 2024
2270f4e
refactor(wishService): option에서 발생하는 오류 수정
Youngini Aug 2, 2024
48f7534
refactor(Order): 다른 entity와 mapping 관계 변경
Youngini Aug 3, 2024
fc247d2
feat(PointController) : 관리자에서 Point 추가하는 기능 완성
Youngini Aug 3, 2024
d3bcaa4
docs(README.md) : 구현한 기능 목록 정리
Youngini Aug 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ out/

### Mac OS ###
.DS_Store

### secret-key 설정
src/main/resources/application-secret.properties
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
# spring-gift-point
# spring-gift-point

# 0단계

## API 명세서
https://impossible-repair-22e.notion.site/57ec013f9424421eb2317b11a2b9a29c?v=f3fe7340ebae425bbfa70db78123a663

# 1단계

## 구현할 기능 목록
- [ ] 작성한 API 문서를 기반으로 팀 내에서 지금까지 만든 API를 검토하고 통일하여 변경 사항을 반영
- [x] 일반 회원가입
- [x] 일반 로그인
- [x] 모든 상품 조회
- [x] 특정 제품의 옵션 조회
- [x] 특정 카테고리별 상품 목록조회
- [x] 모든 카테고리 조회
- [x] 위시리스트에 추가
- [x] 위시리스트에서 삭제
- [x] 로그인한 회원의 위시리스트 조회
- [x] 주문 생성

# 2단계

## 구현할 기능 목록
- [ ] API 오류 확인
- [ ] wish
- [x] product 카테고리별 상품 불러오는 api endpoint 경로 오류 수정
- [ ] 배포 자동화
- [ ] 배포 스크립트 작성
- [ ] 웹을 서버에 배포하기 위한 셀 스크립트 작성
- [ ] 스크립트는 현재 실행 중인 JAR 파일을 종료하고, 새로운 JAR 파일을 복사하여 실행하는 기능을 포함

- [ ] 보안 문제
- [ ] JWT를 사용한 인증에 문제가 없는지 프론트와 연결하면서 테스트

- [x] cors 에러 해결
- [x] 전역 CORS 설정 : WebConfig에서 cors에러 해결
- [ ] ~~특정 controller에서 CORS 설정~~
- [ ] ~~Spring Security에서 CORS 설정~~
- [ ] ~~application에서 CORS 설정 사용~~

- [ ] CORS 테스트 구현

- [ ] 문서화
- [ ] 배포 및 연동 문서 작성하기
- [ ] 배포 프로세스 문서 작성
- [ ] API 연동 방법에 대한 문서 작성

# 3단계
- [x] member entity에 point 추가
- [x] 특정 회원의 point 조회
- [x] 특정 회원에 point 추가
Comment on lines +50 to +53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

포인트를 만들었는데 사용할 방안은 FE 분들과 싱크 완료되었을까요?

21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,28 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2'
//runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.7.3'

// JWT 관련 의존성
compileOnly 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2'

// JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

// 보안 관련 의존성
//implementation 'org.springframework.boot:spring-boot-starter-security'
//implementation 'org.springframework.security:spring-security-test'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'

// Json
implementation group: 'org.json', name: 'json', version: '20090211'
}

tasks.named('test') {
Expand Down
Binary file added data/test.mv.db
Binary file not shown.
152 changes: 152 additions & 0 deletions data/test.trace.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
2024-08-01 04:48:27.040702+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "IMAGEURL" not found; SQL statement:
-- Product 테이블에 더미 데이터 삽입
INSERT INTO product (name, price, imageUrl, category_id) VALUES
('Smartphone', 699, 'http://example.com/smartphone.jpg', 1),
('Laptop', 999, 'http://example.com/laptop.jpg', 1),
('T-Shirt', 19, 'http://example.com/tshirt.jpg', 2),
('Coffee Maker', 49, 'http://example.com/coffeemaker.jpg', 3) [42122-224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
at org.h2.message.DbException.get(DbException.java:223)
at org.h2.message.DbException.get(DbException.java:199)
at org.h2.table.Table.getColumn(Table.java:759)
at org.h2.command.Parser.parseColumn(Parser.java:1190)
at org.h2.command.Parser.parseColumnList(Parser.java:1175)
at org.h2.command.Parser.parseInsert(Parser.java:1549)
at org.h2.command.Parser.parsePrepared(Parser.java:719)
at org.h2.command.Parser.parse(Parser.java:592)
at org.h2.command.Parser.parse(Parser.java:564)
at org.h2.command.Parser.prepareCommand(Parser.java:483)
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:639)
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:559)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1166)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:245)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:231)
at org.h2.server.web.WebApp.getResult(WebApp.java:1345)
at org.h2.server.web.WebApp.query(WebApp.java:1143)
at org.h2.server.web.WebApp.query(WebApp.java:1119)
at org.h2.server.web.WebApp.process(WebApp.java:245)
at org.h2.server.web.WebApp.processRequest(WebApp.java:177)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:389)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:904)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1583)
2024-08-01 04:49:22.693481+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "IMAGEURL" not found; SQL statement:
-- Product 테이블에 더미 데이터 삽입
INSERT INTO product (name, price, imageUrl, category_id) VALUES
('Smartphone', 699, 'http://example.com/smartphone.jpg', 1),
('Laptop', 999, 'http://example.com/laptop.jpg', 1),
('T-Shirt', 19, 'http://example.com/tshirt.jpg', 2),
('Coffee Maker', 49, 'http://example.com/coffeemaker.jpg', 3) [42122-224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
at org.h2.message.DbException.get(DbException.java:223)
at org.h2.message.DbException.get(DbException.java:199)
at org.h2.table.Table.getColumn(Table.java:759)
at org.h2.command.Parser.parseColumn(Parser.java:1190)
at org.h2.command.Parser.parseColumnList(Parser.java:1175)
at org.h2.command.Parser.parseInsert(Parser.java:1549)
at org.h2.command.Parser.parsePrepared(Parser.java:719)
at org.h2.command.Parser.parse(Parser.java:592)
at org.h2.command.Parser.parse(Parser.java:564)
at org.h2.command.Parser.prepareCommand(Parser.java:483)
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:639)
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:559)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1166)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:245)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:231)
at org.h2.server.web.WebApp.getResult(WebApp.java:1345)
at org.h2.server.web.WebApp.query(WebApp.java:1143)
at org.h2.server.web.WebApp.query(WebApp.java:1119)
at org.h2.server.web.WebApp.process(WebApp.java:245)
at org.h2.server.web.WebApp.processRequest(WebApp.java:177)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:389)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:904)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1583)
2024-08-01 04:49:58.801112+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "OPTIONS" not found; SQL statement:
-- Option 테이블에 더미 데이터 삽입
INSERT INTO options (name, quantity, id) VALUES
('64GB Storage', 100, 1), -- Smartphone
('128GB Storage', 50, 1), -- Smartphone
('16GB RAM', 20, 2), -- Laptop
('32GB RAM', 15, 2), -- Laptop
('Size M', 200, 3), -- T-Shirt
('Size L', 150, 3), -- T-Shirt
('Black', 75, 4), -- Coffee Maker
('White', 50, 4) [42102-224]
2024-08-01 04:49:58.805468+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "OPTIONS" not found; SQL statement:
select * from options [42102-224]
2024-08-01 04:50:16.036865+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "OPTIONS" not found; SQL statement:
select * from options [42102-224]
6 changes: 4 additions & 2 deletions src/main/java/gift/Application.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package gift;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
new SpringApplicationBuilder(Application.class)
.properties("spring.config.location=classpath:/application.properties,classpath:/application-secret.properties")
.run(args);
}
}
54 changes: 54 additions & 0 deletions src/main/java/gift/config/JwtConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package gift.config;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.security.Keys;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;
import gift.constant.Constants;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class JwtConfig {

public String generateToken(String email) {
// Create a claims map
Map<String, Object> claims = new HashMap<>();
claims.put("email", email);

// Generate the JWT token
return Jwts.builder()
.setClaims(claims)
.setSubject(email)
.setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() + Constants.ONE_DAY_MILLIS))
.signWith(Keys.hmacShaKeyFor(Constants.SECRET_KEY.getBytes()), SignatureAlgorithm.HS256)
.compact();
}

public String extractEmail(String token) {
if (token.startsWith("Bearer ")) {
token = token.substring(7);
}
return extractAllClaims(token).getSubject();
}

public Claims extractAllClaims(String token) {
return Jwts.parser()
.setSigningKey(Keys.hmacShaKeyFor(Constants.SECRET_KEY.getBytes()))
.parseClaimsJws(token)
.getBody();
}

public boolean validateToken(String token, String email) {
final String extractedEmail = extractEmail(token);
return extractedEmail.equals(email) && !isTokenExpired(token);
}

private boolean isTokenExpired(String token) {
return extractAllClaims(token).getExpiration().before(new Date());
}
}
64 changes: 64 additions & 0 deletions src/main/java/gift/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package gift.config;

import gift.resolver.LoginMemberArgumentResolver;
import gift.service.MemberService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
private final MemberService memberService;

public WebConfig(MemberService memberService) {
this.memberService = memberService;
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(new LoginMemberArgumentResolver(memberService));
}

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false)
.favorParameter(true)
.parameterName("mediaType")
.ignoreAcceptHeader(false)
.useRegisteredExtensionsOnly(false)
.defaultContentType(MediaType.APPLICATION_JSON)
.mediaType("json", MediaType.APPLICATION_JSON)
.mediaType("xml", MediaType.APPLICATION_XML);
}

@Bean
public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
return filter;
}

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter());
}

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true);
}
}
8 changes: 8 additions & 0 deletions src/main/java/gift/constant/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gift.constant;

public class Constants {
public static final String SECRET_KEY = "Yn2kjibddFAWtnPJ2AFlL8WXmohJMCvigQggaEypa5E=";
public static final long ONE_DAY_MILLIS = 86400000;
public static final String AUTHENTICATE_HEADER = "Authenticate";
public static final String BEARER = "Bearer";
}
Loading