Skip to content

Commit

Permalink
refactor: core-api모듈 -> core-api & core-domain분리 및 redis모듈 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
parksey committed Apr 16, 2024
1 parent d1f608c commit 3ec0ca8
Show file tree
Hide file tree
Showing 124 changed files with 1,758 additions and 608 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,8 @@ gradle-app.setting
application-*.yml
!application.yml
!application-test.yml

smtp.yml
redis.yml
db-main.yml
logging.yml
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ subprojects {
}

tasks.getByName("jar") {
enabled = false
enabled = true
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ applicationVersion=0.0.1
javaVersion=17

# Project Configs
projectGroup=org.example
projectGroup=shop.jtoon


# Spring dependency versions
Expand Down
34 changes: 33 additions & 1 deletion jtoon-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,36 @@ Jtoon 서비스의 해결하고자하는 도메인에 대한 모듈
- Repository Layer : 상세 구현 로직이 다양한 자원에 접근할 수 있는 기능을 제공하는 레이어

## Include
- `core-api`: 전체 도메인 로직에 대한 모듈만 존재

### 초기
- `core-api`: 전체 도메인 로직에 대한 모듈만 존재

단점:
1. 모든 기능이 해당 모듈에 몰려있어서 많은 의존성을 가지고 있다.
2. 도메인은 문제를 해결하기 위한 영역이기 때문에 외부의 의존성을 가지는 것이 맞을까?
3. Batch서버를 따로 올린다고 했을 때, Runnable한 API가 2개가 생기게 되는데 이때 동일한 도메인 기능을 서로 다르게 관리하게 된다.

## 2번째 리팩토링

### Core API
Presentation 영역, 외부 의존성이 높다.

- Controller, Dto가 존재
- 확장되지 않는 서비스에 대한 로직 예를들어 Admin은 여기에 추가하고 추후에 변경

### Core domain
오직 Domain 서비스만 관리하는 모듈

- Domain서 서비스를 문제만 해결하기 위해 spring framework의 의존성을 없애는 것으로 한다.
- spring framework가 자체적으로 변경되든, framework를 변경할때 domain 로직이 변경되는 것이 옳지 않다고 생각
- 단 DB가 존재하기 때문에, JPA는 추가

#### 문제
- Bean등록을 어떻게 하면 좋을까?
- Transaction은 어떻게 해야할까


이렇게하면, 여러 개의 Runnable한 서비스가 가능하다

단점:
- 도메인이 DB에 의존적이다. 근데 DB를 변경하는 경우가 많을까? 에 대한 생각을 해볼 필요가 있다.
43 changes: 4 additions & 39 deletions jtoon-core/core-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,10 @@ tasks.getByName("jar") {
enabled = false
}

def generatedDir = "src/main/generated"

sourceSets {
main {
java {
srcDirs = ['src/main/java']
}

resources {
srcDir "${project.projectDir}/src/main/java"
}
}
}

clean {
delete file(generatedDir)
}

dependencies {

implementation project(":jtoon-system")
implementation project(":jtoon-core:core-domain")

implementation project(":jtoon-internal:core-web")
implementation project(":jtoon-internal:iamport-client")
implementation project(":jtoon-internal:s3-client")
Expand All @@ -36,27 +19,18 @@ dependencies {
implementation project(":jtoon-support:monitoring")

implementation project(":jtoon-system")
// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

implementation project(":jtoon-db:db-redis")

// Web
implementation 'org.springframework.boot:spring-boot-starter-web'

// Bean Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

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

// AOP
implementation 'org.springframework.boot:spring-boot-starter-aop'

// H2
implementation 'com.h2database:h2'

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
Expand All @@ -71,13 +45,4 @@ dependencies {

// RestDocs
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'

// MySQL
implementation 'com.mysql:mysql-connector-j:8.0.33'

// Querydsl
api 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta'
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'
annotationProcessor 'jakarta.persistence:jakarta.persistence-api'
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package shop.jtoon.member.application;

import org.springframework.stereotype.Service;

import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import shop.jtoon.login.service.LoginDomainService;
import shop.jtoon.member.domain.MyInfo;
import shop.jtoon.member.dto.OAuthSignUpDto;
import shop.jtoon.member.entity.Member;
import shop.jtoon.member.request.LocalSignUpReq;
import shop.jtoon.security.request.LoginReq;
import shop.jtoon.security.service.JwtService;
import shop.jtoon.security.service.RefreshTokenService;
import shop.jtoon.security.util.TokenCookie;
import shop.jtoon.util.SecurityConstant;

@Service
@RequiredArgsConstructor
public class LoginService {

private final JwtService jwtProvider;
private final RefreshTokenService refreshTokenServiceImpl;

private final LoginDomainService loginService;

public void signUp(LocalSignUpReq localSignUpReq) {
loginService.signUp(localSignUpReq.toLoginInfo(), localSignUpReq.toUserInfo());
}

public void loginMember(LoginReq loginReq, HttpServletResponse response) {
loginService.login(loginReq.toLoginInfo());

String accessToken = jwtProvider.generateAccessToken(loginReq.email());
String refreshToken = jwtProvider.generateRefreshToken();
refreshTokenServiceImpl.saveRefreshToken(refreshToken, loginReq.email());

response.addCookie(TokenCookie.of(SecurityConstant.ACCESS_TOKEN_HEADER, accessToken));
response.addCookie(TokenCookie.of(SecurityConstant.REFRESH_TOKEN_HEADER, refreshToken));
}

public Member generateOrGetSocialMember(OAuthSignUpDto oAuthSignUpDto) {
return loginService.generateOrGetSocialMember(oAuthSignUpDto.toLoginInfo(), oAuthSignUpDto.toUserInfo());
}

public MyInfo readMyInfo(String email) {
return loginService.findMemberDtoByEmail(email);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package shop.jtoon.member.dto;

import lombok.Builder;
import shop.jtoon.member.domain.MyInfo;
import shop.jtoon.member.entity.Gender;
import shop.jtoon.member.entity.Member;
import shop.jtoon.member.entity.Role;

@Builder
Expand All @@ -15,15 +15,15 @@ public record MemberDto(
Role role,
String phone
) {
public static MemberDto toDto(Member member) {
public static MemberDto toDto(MyInfo myInfo) {
return MemberDto.builder()
.id(member.getId())
.email(member.getEmail())
.name(member.getName())
.nickname(member.getNickname())
.gender(member.getGender())
.role(member.getRole())
.phone(member.getPhone())
.id(myInfo.id())
.email(myInfo.email())
.name(myInfo.name())
.nickname(myInfo.nickname())
.gender(myInfo.gender())
.role(myInfo.role())
.phone(myInfo.phone())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import lombok.Builder;

import shop.jtoon.login.domain.LoginInfo;
import shop.jtoon.login.domain.UserInfo;
import shop.jtoon.member.entity.Gender;
import shop.jtoon.member.entity.LoginType;
import shop.jtoon.member.entity.Member;
import shop.jtoon.member.entity.Role;

@Builder
public record OAuthSignUpDto(
Expand All @@ -17,16 +17,20 @@ public record OAuthSignUpDto(
String phone,
String loginType
) {
public Member toEntity(String encryptedPassword) {
return Member.builder()
public LoginInfo toLoginInfo() {
return LoginInfo.builder()
.email(email)
.password(encryptedPassword)
.password(password)
.loginType(LoginType.from(loginType))
.build();
}

public UserInfo toUserInfo() {
return UserInfo.builder()
.name(name)
.nickname(nickname)
.gender(Gender.from(gender))
.phone(phone)
.role(Role.USER)
.loginType(LoginType.from(loginType))
.build();
}
}
Loading

0 comments on commit 3ec0ca8

Please sign in to comment.