Skip to content

Commit

Permalink
rename: 계층형 패키지 구조 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
SJ70 committed Jun 30, 2024
1 parent 0a2d118 commit b371347
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 36 deletions.

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/com/j9/bestmoments/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.j9.bestmoments.config;

import com.j9.bestmoments.auth.jwt.JwtAuthenticationFilter;
import com.j9.bestmoments.auth.jwt.JwtTokenProvider;
import com.j9.bestmoments.jwt.JwtAuthenticationFilter;
import com.j9.bestmoments.jwt.JwtTokenProvider;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.j9.bestmoments.auth;
package com.j9.bestmoments.controller;

import com.j9.bestmoments.auth.jwt.JwtToken;
import com.j9.bestmoments.auth.jwt.JwtTokenProvider;
import com.j9.bestmoments.auth.oauth.dto.request.OAuthUserInfoDto;
import com.j9.bestmoments.auth.oauth.service.GoogleAuthService;
import com.j9.bestmoments.auth.oauth.service.OAuthService;
import com.j9.bestmoments.member.Member;
import com.j9.bestmoments.member.MemberService;
import com.j9.bestmoments.dto.response.JwtTokenDto;
import com.j9.bestmoments.jwt.JwtTokenProvider;
import com.j9.bestmoments.dto.response.OAuthUserInfoDto;
import com.j9.bestmoments.service.GoogleAuthService;
import com.j9.bestmoments.service.OAuthService;
import com.j9.bestmoments.domain.Member;
import com.j9.bestmoments.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -30,15 +30,15 @@ public class AuthController {

@GetMapping("/login/{oAuthProvider}")
@Operation(summary = "OAuth 인증코드로 로그인/회원가입", description = "oAuthProvider: google")
public ResponseEntity<JwtToken> login(@PathVariable String oAuthProvider, @RequestParam String code) {
public ResponseEntity<JwtTokenDto> login(@PathVariable String oAuthProvider, @RequestParam String code) {
OAuthService oAuthService = switch (oAuthProvider) {
case "google" -> googleAuthService;
default -> throw new OAuth2AuthenticationException("존재하지 않는 OAuth 인증 방식입니다.");
};
OAuthUserInfoDto oAuthUserInfo = oAuthService.getUserInfo(code);
Member member = memberService.findOrSaveByOAuthInfo(oAuthUserInfo);

JwtToken jwtToken = jwtTokenProvider.generateToken(member);
JwtTokenDto jwtToken = jwtTokenProvider.generateToken(member);
return ResponseEntity.ok(jwtToken);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.j9.bestmoments.member;
package com.j9.bestmoments.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.j9.bestmoments.member;
package com.j9.bestmoments.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.j9.bestmoments.auth.jwt;
package com.j9.bestmoments.dto.response;

public record JwtToken(
public record JwtTokenDto(
String grantType,
String accessToken,
String refreshToken
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.j9.bestmoments.auth.oauth.dto.request;
package com.j9.bestmoments.dto.response;

import lombok.Builder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.j9.bestmoments.auth.jwt;
package com.j9.bestmoments.jwt;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.j9.bestmoments.auth.jwt;
package com.j9.bestmoments.jwt;

import com.j9.bestmoments.member.Member;
import com.j9.bestmoments.dto.response.JwtTokenDto;
import com.j9.bestmoments.domain.Member;
import com.sun.security.auth.UserPrincipal;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
Expand Down Expand Up @@ -38,7 +39,7 @@ public JwtTokenProvider(@Value("${jwt.secret}") String secretKey) {
this.key = Keys.hmacShaKeyFor(keyBytes);
}

public JwtToken generateToken(Member member) {
public JwtTokenDto generateToken(Member member) {

Date now = new Date();
Date accessTokenExpiresIn = new Date(now.getTime() + accessTokenExpirationMs);
Expand All @@ -61,7 +62,7 @@ public JwtToken generateToken(Member member) {
.signWith(key, SignatureAlgorithm.HS256)
.compact();

return new JwtToken("Bearer", accessToken, refreshToken);
return new JwtTokenDto("Bearer", accessToken, refreshToken);
}

// 토큰을 복호화하여 인증 정보 추출
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.j9.bestmoments.member;
package com.j9.bestmoments.repository;

import com.j9.bestmoments.domain.Member;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.j9.bestmoments.auth.oauth.service;
package com.j9.bestmoments.service;

import com.fasterxml.jackson.databind.JsonNode;
import com.j9.bestmoments.auth.oauth.dto.request.OAuthUserInfoDto;
import com.j9.bestmoments.dto.response.OAuthUserInfoDto;
import java.util.Collections;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.j9.bestmoments.member;
package com.j9.bestmoments.service;

import com.j9.bestmoments.auth.oauth.dto.request.OAuthUserInfoDto;
import com.j9.bestmoments.dto.response.OAuthUserInfoDto;
import com.j9.bestmoments.domain.MemberRole;
import com.j9.bestmoments.domain.Member;
import com.j9.bestmoments.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/j9/bestmoments/service/OAuthService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.j9.bestmoments.service;

import com.j9.bestmoments.dto.response.OAuthUserInfoDto;

public interface OAuthService {

OAuthUserInfoDto getUserInfo(String code);

}

0 comments on commit b371347

Please sign in to comment.