Skip to content

Commit

Permalink
Merge pull request #78 from ghdcksgml1/dev
Browse files Browse the repository at this point in the history
Merge dev Branch
  • Loading branch information
ghdcksgml1 authored Oct 18, 2023
2 parents 7d03ccc + 0bbeae2 commit dc48925
Show file tree
Hide file tree
Showing 74 changed files with 1,992 additions and 188 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/CI_dev_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- name: resources 폴더 생성
run: |
mkdir -p ./heachi-core/auth-api/src/main/resources
mkdir -p ./heachi-core/housework-api/src/main/resources
mkdir -p ./heachi-domain-mongo/src/main/resources
mkdir -p ./heachi-domain-mysql/src/main/resources
mkdir -p ./heachi-domain-redis/src/main/resources
Expand All @@ -32,6 +33,7 @@ jobs:
- name: yml 파일 생성
run: |
echo "${{ secrets.HEACHICORE_AUTHAPI_APPLICATION }}" > ./heachi-core/auth-api/src/main/resources/application.yml
echo "${{ secrets.HEACHICORE_HOUSEWORKAPI_APPLICATION }}" > ./heachi-core/housework-api/src/main/resources/application.yml
echo "${{ secrets.HEACHIDOMAINMONGO_APPLICATION }}" > ./heachi-domain-mongo/src/main/resources/application.yml
echo "${{ secrets.HEACHIDOMAINMYSQL_DATABASE }}" > ./heachi-domain-mysql/src/main/resources/database.yml
echo "${{ secrets.HEACHIDOMAINREDIS_DATABASE }}" > ./heachi-domain-redis/src/main/resources/redis.yml
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/CI_main_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- name: resources 폴더 생성
run: |
mkdir -p ./heachi-core/auth-api/src/main/resources
mkdir -p ./heachi-core/housework-api/src/main/resources
mkdir -p ./heachi-domain-mongo/src/main/resources
mkdir -p ./heachi-domain-mysql/src/main/resources
mkdir -p ./heachi-domain-redis/src/main/resources
Expand All @@ -33,6 +34,7 @@ jobs:
- name: yml 파일 생성
run: |
echo "${{ secrets.HEACHICORE_AUTHAPI_APPLICATION }}" > ./heachi-core/auth-api/src/main/resources/application.yml
echo "${{ secrets.HEACHICORE_HOUSEWORKAPI_APPLICATION }}" > ./heachi-core/housework-api/src/main/resources/application.yml
echo "${{ secrets.HEACHIDOMAINMONGO_APPLICATION }}" > ./heachi-domain-mongo/src/main/resources/application.yml
echo "${{ secrets.HEACHIDOMAINMYSQL_DATABASE }}" > ./heachi-domain-mysql/src/main/resources/database.yml
echo "${{ secrets.HEACHIDOMAINREDIS_DATABASE }}" > ./heachi-domain-redis/src/main/resources/redis.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.heachi.admin.common.exception.ExceptionMessage;
import com.heachi.admin.common.exception.state.LoginStateException;
import com.heachi.redis.define.state.LoginState;
import com.heachi.redis.define.state.LoginStateRepository;
import com.heachi.redis.define.state.repository.LoginStateRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public class SwaggerConfig {
@Bean
public OpenAPI openAPI(@Value("${heachiCoreAuthUrls}") String[] serverList) {
Info info = new Info()
.title("Heachi-Auth Server")
.title("N빵 집안일 사용자 인증 API Document")
.version("0.1")
.description("N빵 집안일 인증서버 API 문서입니다.")
.description("N빵 집안일 인증서버 API 문서입니다.\n" +
"해당 문서를 이용해 N빵 집안일 REST API를 테스트해볼 수 있습니다.")
.contact(new Contact()
.name("📍 N-bbang-housework Backend GitHub Link")
.url("https://github.com/ghdcksgml1/N-bbang-housework"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ void loginTokenValidClaims() {
User user2 = User.builder()
.name("김민목")
.email("abc2")
.role(UserRole.CHEMIST)
.role(UserRole.USER)
.build();
User user3 = User.builder()
.name("김민금")
.email("abc3")
.role(UserRole.CENTER)
.role(UserRole.USER)
.build();
userRepository.saveAll(List.of(user1, user2, user3));

Expand Down Expand Up @@ -151,11 +151,11 @@ void loginTokenValidClaims() {
() -> assertThat(claims1.get("name")).isEqualTo("김민수"),
() -> assertThat(claims1.get("profileImageUrl")).isEqualTo("google.com"),
// 김민목
() -> assertThat(claims2.get("role")).isEqualTo("CHEMIST"),
() -> assertThat(claims2.get("role")).isEqualTo("USER"),
() -> assertThat(claims2.get("name")).isEqualTo("김민목"),
() -> assertThat(claims2.get("profileImageUrl")).isEqualTo("google.com"),
// 김민금
() -> assertThat(claims3.get("role")).isEqualTo("CENTER"),
() -> assertThat(claims3.get("role")).isEqualTo("USER"),
() -> assertThat(claims3.get("name")).isEqualTo("김민금"),
() -> assertThat(claims3.get("profileImageUrl")).isEqualTo("google.com")
);
Expand Down Expand Up @@ -219,7 +219,7 @@ public void registerUnauthUserSuccessTest() {

// 회원가입 요청 생성 (CENTER)
AuthServiceRegisterRequest request = AuthServiceRegisterRequest.builder()
.role(UserRole.CENTER)
.role(UserRole.USER)
.phoneNumber(phoneNumber)
.email(email)
.build();
Expand All @@ -232,7 +232,7 @@ public void registerUnauthUserSuccessTest() {


// then
assertEquals(UserRole.CENTER, response.getRole());
assertEquals(UserRole.USER, response.getRole());
assertThat(tokenValid).isTrue();
}

Expand All @@ -249,7 +249,7 @@ public void registerUnauthUserFailTest() {
User user = User.builder()
.platformId(platformId)
.platformType(platformType)
.role(UserRole.CENTER)
.role(UserRole.USER)
.email(email)
.name(name)
.profileImageUrl(profileImageUrl)
Expand All @@ -259,7 +259,7 @@ public void registerUnauthUserFailTest() {

// 회원가입 요청 생성 (CENTER)
AuthServiceRegisterRequest request = AuthServiceRegisterRequest.builder()
.role(UserRole.CENTER)
.role(UserRole.USER)
.phoneNumber(phoneNumber)
.email(email)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.heachi.admin.common.exception.state.LoginStateException;
import com.heachi.auth.TestConfig;
import com.heachi.redis.define.state.LoginState;
import com.heachi.redis.define.state.LoginStateRepository;
import com.heachi.redis.define.state.repository.LoginStateRepository;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
70 changes: 70 additions & 0 deletions heachi-core/housework-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
plugins {
id 'com.google.cloud.tools.jib' version '3.3.2'
}

bootJar {
// 빌드된 Jar 파일명 지정
archiveFileName = "heachi-housework-" + buildVersion + ".jar"
}

dependencies {
// 내부 모듈
implementation project(':heachi-support:common')
implementation project(':heachi-support:logging')
implementation project(':heachi-support:external-clients')
implementation project(':heachi-domain-mysql')
implementation project(':heachi-domain-redis')

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

// Swagger
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0")

testCompileOnly project(':heachi-support:common')
testCompileOnly project(':heachi-support:logging')
testCompileOnly project(':heachi-domain-mysql')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

jib {
from {
image = 'eclipse-temurin:17-jre' // https://github.com/GoogleContainerTools/jib/issues/3483
platforms {
platform {
architecture = "arm64"
os = "linux"
}
}
}
to {
image = 'ghdcksgml1/heachi-housework'
tags = [buildVersion, "latest"]
auth {
username = dockerUsername
password = dockerPassword
}
}
container {

entrypoint = ['java', '-Dspring.profiles.active=prod', '-jar', 'heachi-housework-' + buildVersion + '.jar']
jvmFlags = ['-Xms2048m', '-Xmx2048m', '-Xdebug', '-XshowSettings:vm', '-XX:+UnlockExperimentalVMOptions', '-XX:+UseContainerSupport']
ports = ['8000']
environment = [SPRING_OUTPUT_ANSI_ENABLED: "ALWAYS"]

creationTime = 'USE_CURRENT_TIMESTAMP'
format = 'Docker'
}

// 어디 폴더로 부터 가져올지
extraDirectories {
paths {
path {
from = file('build/libs')
}
}
}
}

bootJar.enabled = true
jar.enabled = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.heachi.housework;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;

@SpringBootApplication(scanBasePackages = "com.heachi", exclude = SecurityAutoConfiguration.class)
public class HeachiHouseworkApplication {

public static void main(String[] args) {
SpringApplication.run(HeachiHouseworkApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.heachi.housework.api.controller.housework.todo;

import com.heachi.admin.common.response.JsonResult;
import com.heachi.external.clients.auth.response.UserInfoResponse;
import com.heachi.housework.api.service.auth.AuthExternalService;
import com.heachi.housework.api.service.housework.todo.TodoService;
import com.heachi.housework.api.service.housework.todo.request.TodoSelectRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/housework/todo")
public class TodoController {

private final AuthExternalService authExternalService;
private final TodoService todoService;

// Todo List 가져오기
@GetMapping("/{groupId}")
public JsonResult<?> selectTodo(@RequestHeader(name = "Authorization") String authorization,
@PathVariable(name = "groupId") Long groupId,
@RequestParam(value = "date") LocalDate date) {
UserInfoResponse userInfo = authExternalService.userAuthenticateAndGroupMatch(authorization, groupId);

return JsonResult.successOf(todoService.cachedSelectTodo(
TodoSelectRequest.builder().groupId(groupId).date(date).build()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.heachi.housework.api.service.auth;

import com.heachi.admin.common.exception.ExceptionMessage;
import com.heachi.admin.common.exception.auth.AuthException;
import com.heachi.admin.common.exception.group.member.GroupMemberException;
import com.heachi.admin.common.response.JsonResult;
import com.heachi.external.clients.auth.AuthClients;
import com.heachi.external.clients.auth.response.UserInfoResponse;
import com.heachi.mysql.define.group.member.repository.GroupMemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class AuthExternalService {

private final AuthClients authClients;
private final GroupMemberRepository groupMemberRepository;

// Auth 서버에 인증 요청을 보낸다.
public UserInfoResponse userAuthenticate(String authorization) {
JsonResult<UserInfoResponse> jsonResult = authClients.getUserInfo(authorization).block(); // Mono 객체이므로 Block

if (jsonResult.getResCode() != 200) {
log.warn(">>>> 유저 인증에 실패했습니다.");

throw new AuthException(ExceptionMessage.AUTH_SERVER_NOT_RESPOND);
}

return jsonResult.getResObj();
}

// Auth 서버에 인증 요청을 보낸 후 가져온 정보로 해당 그룹원인지 판별한다.
public UserInfoResponse userAuthenticateAndGroupMatch(String authorization, Long groupId) {
JsonResult<UserInfoResponse> jsonResult = authClients.getUserInfo(authorization).block(); // Mono 객체이므로 Block

if (jsonResult.getResCode() != 200) {
log.warn(">>>> 유저 인증에 실패했습니다.");

throw new AuthException(ExceptionMessage.AUTH_SERVER_NOT_RESPOND);
}

if (!groupMemberRepository.existsGroupMemberByUserEmailAndGroupInfoId(
jsonResult.getResObj().getEmail(), groupId)) {
log.warn(">>>> 해당 유저[{}]는 해당 그룹[{}]의 소속이 아닙니다.", jsonResult.getResObj().getEmail(), groupId);

throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_NOT_FOUND);
}

return jsonResult.getResObj();
}
}
Loading

0 comments on commit dc48925

Please sign in to comment.