Skip to content

Commit fbc765a

Browse files
committed
Feat: 패키지 경로 수정 및 내부 모듈간 통신을 gRPC 통신으로 변경
1 parent e18d017 commit fbc765a

96 files changed

Lines changed: 644 additions & 1033 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AccountService/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
group = 'org.mybatis'
1+
group = 'org.mybatis.jpetstore.account'
22
version = '1.0.0'
33
archivesBaseName = 'jpetstore-account'
44

55
dependencies {
66
implementation project(':CommonLibrary')
7+
compileOnly 'org.projectlombok:lombok:1.18.30'
8+
annotationProcessor 'org.projectlombok:lombok:1.18.30'
79
}

AccountService/src/main/java/org/mybatis/jpetstore/AccountServiceApplication.java renamed to AccountService/src/main/java/org/mybatis/jpetstore/account/AccountServiceApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.mybatis.jpetstore;
1+
package org.mybatis.jpetstore.account;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;

AccountService/src/main/java/org/mybatis/jpetstore/controller/AccountController.java renamed to AccountService/src/main/java/org/mybatis/jpetstore/account/controller/AccountController.java

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
package org.mybatis.jpetstore.controller;
1+
package org.mybatis.jpetstore.account.controller;
22

3+
import jakarta.servlet.http.HttpServletRequest;
4+
import jakarta.servlet.http.HttpSession;
5+
import lombok.RequiredArgsConstructor;
6+
import org.mybatis.jpetstore.common.domain.Account;
7+
import org.mybatis.jpetstore.common.grpc.CatalogGrpcClient;
8+
import org.mybatis.jpetstore.account.service.AccountService;
39
import org.springframework.beans.factory.annotation.Value;
4-
import org.mybatis.jpetstore.domain.Account;
5-
import org.mybatis.jpetstore.http.HttpFacade;
6-
import org.mybatis.jpetstore.service.AccountService;
7-
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.stereotype.Controller;
9-
import org.springframework.web.bind.annotation.*;
11+
import org.springframework.web.bind.annotation.GetMapping;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
import org.springframework.web.bind.annotation.RequestParam;
1014

11-
import jakarta.servlet.http.HttpServletRequest;
12-
import jakarta.servlet.http.HttpSession;
1315
import java.util.UUID;
1416

1517
@Controller
18+
@RequiredArgsConstructor
1619
public class AccountController {
1720

18-
@Autowired
19-
private AccountService accountService;
20-
@Autowired
21-
private HttpFacade httpFacade;
21+
private final AccountService accountService;
22+
private final CatalogGrpcClient catalogGrpcClient;
23+
2224
@Value("${gateway.base-url}")
2325
private String redirectBaseUrl;
2426

2527

2628
@GetMapping("/newAccountForm")
27-
public String newAccountForm(HttpServletRequest request, HttpSession session) {
28-
String REDIRECT_BASE_URL = httpFacade.getBaseUrl(request);
29+
public String newAccountForm(HttpSession session) {
2930
if (session.getAttribute("account") != null) {
3031
// 로그인이 되어 있으면 메인 페이지로 리다이렉트
3132
return "redirect:" + redirectBaseUrl + "/catalog";
@@ -34,8 +35,7 @@ public String newAccountForm(HttpServletRequest request, HttpSession session) {
3435
}
3536

3637
@PostMapping("/newAccount")
37-
public String newAccount(HttpServletRequest request, Account account, HttpSession session) {
38-
String REDIRECT_BASE_URL = httpFacade.getBaseUrl(request);
38+
public String newAccount(Account account, HttpSession session) {
3939
if (session.getAttribute("account") != null) {
4040
// 로그인이 되어 있으면 메인 페이지로 리다이렉트
4141
return "redirect:" + redirectBaseUrl + "/catalog";
@@ -45,7 +45,7 @@ public String newAccount(HttpServletRequest request, Account account, HttpSessio
4545
session.setAttribute("csrf_token", UUID.randomUUID().toString());
4646

4747
// 카탈로그 서비스 사용
48-
session.setAttribute("myList", httpFacade.getProductListByCategory(account.getFavouriteCategoryId()));
48+
session.setAttribute("myList", catalogGrpcClient.getProductListByCategory(account.getFavouriteCategoryId()));
4949
session.setAttribute("isAuthenticated", true);
5050
return "redirect:" + redirectBaseUrl + "/catalog";
5151
}
@@ -56,7 +56,7 @@ public String editAccountForm() {
5656
}
5757

5858
@PostMapping("/editAccount")
59-
public String editAccount(HttpServletRequest request, Account account, @RequestParam String csrf, HttpSession session, HttpServletRequest req) {
59+
public String editAccount(Account account, @RequestParam String csrf, HttpSession session, HttpServletRequest req) {
6060
if (csrf == null || session.getAttribute("account") == null || !csrf.equals(session.getAttribute("csrf_token"))) {
6161
// csrf가 null이거나 로그인이 안되어있거나 csrf가 일치하지 않으면 다시 돌아감
6262
String value = "This is not a valid request";
@@ -67,14 +67,12 @@ public String editAccount(HttpServletRequest request, Account account, @RequestP
6767
session.setAttribute("account", accountService.getAccount(account.getUsername()));
6868

6969
// 카탈로그 서비스 사용
70-
String REDIRECT_BASE_URL = httpFacade.getBaseUrl(request);
71-
session.setAttribute("myList", httpFacade.getProductListByCategory(account.getFavouriteCategoryId()));
70+
session.setAttribute("myList", catalogGrpcClient.getProductListByCategory(account.getFavouriteCategoryId()));
7271
return "redirect:" + redirectBaseUrl + "/catalog";
7372
}
7473

7574
@GetMapping("/signonForm")
76-
public String signonForm(HttpServletRequest request, @RequestParam(required = false) String msg, HttpServletRequest req, HttpSession session) {
77-
String REDIRECT_BASE_URL = httpFacade.getBaseUrl(request);
75+
public String signonForm(@RequestParam(required = false) String msg, HttpServletRequest req, HttpSession session) {
7876
if (session.getAttribute("account") != null) {
7977
// 로그인이 되어 있으면, 로그인 불가
8078
return "redirect:" + redirectBaseUrl + "/catalog";
@@ -85,8 +83,7 @@ public String signonForm(HttpServletRequest request, @RequestParam(required = fa
8583
}
8684

8785
@PostMapping("/signon")
88-
public String signon(HttpServletRequest request, Account account, HttpServletRequest req, HttpSession session) {
89-
String REDIRECT_BASE_URL = httpFacade.getBaseUrl(request);
86+
public String signon(Account account, HttpServletRequest req, HttpSession session) {
9087
Account existAccount = accountService.getAccount(account.getUsername(), account.getPassword());
9188

9289
if (existAccount == null) {
@@ -98,15 +95,14 @@ public String signon(HttpServletRequest request, Account account, HttpServletReq
9895
account.setPassword(null);
9996
session.setAttribute("csrf_token", UUID.randomUUID().toString());
10097
session.setAttribute("account", existAccount);
101-
session.setAttribute("myList", httpFacade.getProductListByCategory(req, existAccount.getFavouriteCategoryId()));
98+
session.setAttribute("myList", catalogGrpcClient.getProductListByCategory(existAccount.getFavouriteCategoryId()));
10299
session.setAttribute("isAuthenticated", true);
103100
return "redirect:" + redirectBaseUrl + "/catalog";
104101
}
105102
}
106103

107104
@GetMapping("/signoff")
108-
public String signoff(HttpServletRequest request, HttpSession session) {
109-
String REDIRECT_BASE_URL = httpFacade.getBaseUrl(request);
105+
public String signoff(HttpSession session) {
110106
session.invalidate();
111107
return "redirect:" + redirectBaseUrl + "/catalog";
112108
}

AccountService/src/main/java/org/mybatis/jpetstore/mapper/AccountMapper.java renamed to AccountService/src/main/java/org/mybatis/jpetstore/account/mapper/AccountMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.mybatis.jpetstore.mapper;
16+
package org.mybatis.jpetstore.account.mapper;
1717

1818
import org.apache.ibatis.annotations.Mapper;
19-
import org.mybatis.jpetstore.domain.Account;
19+
import org.mybatis.jpetstore.common.domain.Account;
2020

2121
/**
2222
* The Interface AccountMapper.

AccountService/src/main/java/org/mybatis/jpetstore/repository/AccountRepository.java renamed to AccountService/src/main/java/org/mybatis/jpetstore/account/repository/AccountRepository.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
package org.mybatis.jpetstore.repository;
1+
package org.mybatis.jpetstore.account.repository;
22

3-
import org.mybatis.jpetstore.domain.Account;
4-
import org.mybatis.jpetstore.mapper.AccountMapper;
5-
import org.springframework.beans.factory.annotation.Autowired;
3+
import lombok.RequiredArgsConstructor;
4+
import org.mybatis.jpetstore.common.domain.Account;
5+
import org.mybatis.jpetstore.account.mapper.AccountMapper;
66
import org.springframework.stereotype.Repository;
77
import java.util.Optional;
88

99
/**
1010
* {@link Account} 엔티티에 대한 데이터 접근을 담당합니다.
1111
*/
1212
@Repository
13+
@RequiredArgsConstructor
1314
public class AccountRepository {
1415

1516
private final AccountMapper mapper;
1617

17-
@Autowired
18-
public AccountRepository(AccountMapper mapper) {
19-
this.mapper = mapper;
20-
}
21-
2218
/**
2319
* 사용자 이름으로 계정을 조회합니다.
2420
*

AccountService/src/main/java/org/mybatis/jpetstore/service/AccountService.java renamed to AccountService/src/main/java/org/mybatis/jpetstore/account/service/AccountService.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.mybatis.jpetstore.service;
16+
package org.mybatis.jpetstore.account.service;
1717

18-
import org.mybatis.jpetstore.domain.Account;
19-
import org.mybatis.jpetstore.repository.AccountRepository;
20-
import org.springframework.beans.factory.annotation.Autowired;
18+
import lombok.RequiredArgsConstructor;
19+
import org.mybatis.jpetstore.common.domain.Account;
20+
import org.mybatis.jpetstore.account.repository.AccountRepository;
2121
import org.springframework.stereotype.Service;
2222
import org.springframework.transaction.annotation.Transactional;
2323

@@ -26,15 +26,11 @@
2626
* 계정 관련 비즈니스 로직을 담당합니다.
2727
*/
2828
@Service
29+
@RequiredArgsConstructor
2930
public class AccountService {
3031

3132
private final AccountRepository accountRepository;
3233

33-
@Autowired
34-
public AccountService(AccountRepository accountRepository) {
35-
this.accountRepository = accountRepository;
36-
}
37-
3834
/**
3935
* 사용자 이름으로 계정 정보를 조회합니다.
4036
*

AccountService/src/main/java/org/mybatis/jpetstore/http/HttpFacade.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

AccountService/src/main/java/org/mybatis/jpetstore/http/RestTemplateConfig.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

AccountService/src/main/resources/application.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ spring:
2525
repository-type: indexed
2626

2727
mybatis:
28-
type-aliases-package: org.mybatis.jpetstore.domain
28+
type-aliases-package: org.mybatis.jpetstore.*.domain
2929
mapper-locations: classpath:mapperXML/*.xml
3030

3131
gateway:
3232
base-url: ${GATEWAY_BASE_URL:http://localhost}
33-
kafka:
34-
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
33+
34+
grpc:
35+
client:
36+
catalog:
37+
address: ${CATALOG_GRPC_ADDRESS:static://localhost:9093} # gRPC 서버 주소
38+
enableKeepAlive: true
39+
keepAliveWithoutCalls: true
40+
negotiationType: plaintext # 암호화 되지 않는 설정. 운영 환경에서는 TLS를 사용하여 보안 통신을 설정해야 함

AccountService/src/main/resources/mapperXML/AccountMapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
2020
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2121

22-
<mapper namespace="org.mybatis.jpetstore.mapper.AccountMapper">
22+
<mapper namespace="org.mybatis.jpetstore.account.mapper.AccountMapper">
2323

2424
<cache />
2525

0 commit comments

Comments
 (0)