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

dev -> main #3

Merged
merged 56 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ae2bbd5
chore: 불필요한 파일 삭제
hyoguoo Feb 11, 2024
ec5fa87
chore: QueryDsl / Swagger / Validation 의존성 추가
hyoguoo Feb 11, 2024
095cae9
chore: 컨벤션으로 인한 패키지명 수정
hyoguoo Feb 11, 2024
023dd42
chore: JWT 의존성 추가
hyoguoo Feb 11, 2024
3d5471b
feat: QueryDsl Config 추가
hyoguoo Feb 11, 2024
f8894ce
feat: Swagger Config 추가
hyoguoo Feb 11, 2024
23d5691
feat: Security Config 추가
GiHoo Feb 11, 2024
f86f107
feat: AccessToken 생성/검증하는 JwtProvider 구현
GiHoo Feb 11, 2024
c8f0f49
feat: JwtAuthenticationFilter 구현
GiHoo Feb 11, 2024
a34ef82
refactor: sonarLint 적용
GiHoo Feb 11, 2024
8ad9ebd
feat: BaseEntity 추가
hyoguoo Feb 11, 2024
726cb30
feat: Email 검증 로직을 위한 Email VO 추가
hyoguoo Feb 11, 2024
0a880f2
feat: 필수 정보만 포함한 Member Entity 추가
hyoguoo Feb 11, 2024
6ae8ba9
feat: 회원가입/로그인 을 위한 Request DTO 추가
hyoguoo Feb 11, 2024
9c2cebf
feat: Password Encoder 사용을 위해 Bean 주입 Configuration 추가
hyoguoo Feb 11, 2024
03c6d8b
feat: Member 생성 시 패스워드 정책 검증 및 인코드를 위한 Util 클래스 추가
hyoguoo Feb 11, 2024
d86b44a
chore: 회원 가입 DTO 클래스명 변경
hyoguoo Feb 11, 2024
57a7e46
feat: Member Sign Up / Sign In 기능 개발
hyoguoo Feb 11, 2024
250c1c5
fix: UserDetailService 구현체 구현
hyoguoo Feb 13, 2024
fd5b024
fix: Member 조회 시 roles 정보도 가져오도록 수정
hyoguoo Feb 13, 2024
533dbd6
chore: reformat code
hyoguoo Feb 13, 2024
fb3d099
refactor: roles final 제거 및 생성 시 ROLE_USER 권한 추가
hyoguoo Feb 13, 2024
744eec8
feat: 권한 테스트 Controller 추가
hyoguoo Feb 13, 2024
d75000d
fix: requestMatchers 올바른 URL 로 변경
hyoguoo Feb 13, 2024
183d2c5
docs: Swagger Docs 작성을 위한 interface 추가
hyoguoo Feb 13, 2024
1d948a3
mod: 인증 관련 기능 Member* -> Auth* prefix 변경
hyoguoo Feb 13, 2024
02d81f5
feat: Entity 생성 시 createdAt / updatedAt 기본값으로 생성되도록 설정 및 updatedAt 시간…
hyoguoo Feb 13, 2024
b8828f0
feat: Error Response 클래스 추가
hyoguoo Feb 13, 2024
e6f6143
feat: 인증관련 Custom Exception 생성 및 적용
hyoguoo Feb 13, 2024
437603c
feat: 인증관련 Global Exception Handler 구현
hyoguoo Feb 13, 2024
792a99a
refactor: Auth 도메인 분리
hyoguoo Feb 13, 2024
4991d75
feat: getMemberByEmail / addMember 구현
hyoguoo Feb 13, 2024
e784234
refactor: AuthService에서 MemberService 의존하도록 변경
hyoguoo Feb 13, 2024
33608a0
refactor: Member / Auth Exception 분리
hyoguoo Feb 13, 2024
9b712db
feat: 로그인 response dto 추가
hyoguoo Feb 13, 2024
ac0ab2e
feat: 의도치 않은 에러를 잡는 Exception Handler 추가
hyoguoo Feb 13, 2024
5494877
feat: Success Message AOP 적용
hyoguoo Feb 13, 2024
70b4b09
refactor: 패키지명 명확하게 수정
hyoguoo Feb 13, 2024
2743f0a
refactor: Exception 패키지 명확하게 구분
hyoguoo Feb 13, 2024
f5d8f27
refactor: 메서드명 명확하게 수정
hyoguoo Feb 13, 2024
f2ef421
refactor: Reformat Code
hyoguoo Feb 13, 2024
e971294
refactor: google style guide 적용
hyoguoo Feb 13, 2024
0b07ded
docs: issue template 작성
GiHoo Feb 14, 2024
023352f
docs: bug, etc 이슈 템플릿 작성 및 feat 템플릿 수정
GiHoo Feb 14, 2024
93e6809
docs: Pull Request Template 생성
GiHoo Feb 14, 2024
2422513
fix: swagger json 데이터 예외 처리 추가
hyoguoo Feb 14, 2024
be6faeb
chore: 파일 마지막 줄 개행 추가
hyoguoo Feb 14, 2024
2cbf6c2
infra: CI 세팅 (#2)
GiHoo Feb 14, 2024
752da3e
chore: CI/CD를 위한 docker 추가
GiHoo Feb 15, 2024
b60a875
chore: CI Workflow 수정
GiHoo Feb 15, 2024
13bd18e
chore: CI를 위한 test application.properties 추가
hyoguoo Feb 15, 2024
660d240
test: DB Connection test 코드 추가
hyoguoo Feb 15, 2024
c785104
chore: flow 이름 명확하게 변경
hyoguoo Feb 15, 2024
777b990
test: DB Connection 테스트 DATA JPA 사용으로 변경
hyoguoo Feb 15, 2024
7ecf006
test: DB Connection 테스트 원복
hyoguoo Feb 15, 2024
9ec7ffa
chore: CD workflow 작성
hyoguoo Feb 15, 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
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/-etc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: "\betc"
about: 기타 이슈 템플릿
title: ''
labels: ''
assignees: ''

---

## 어떤 이슈인가요?

> 해당 이슈에 대해 간단히 서술해주세요

## 참고할만한 자료(선택)
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: bug
about: 버그 관련 이슈 템플릿
title: ''
labels: bug
assignees: ''

---

## 어떤 버그인가요?

> 어떤 버그인지 간결하게 설명해주세요

## 어떤 상황에서 발생한 버그인가요?

> (가능하면) Given-When-Then 형식으로 서술해주세요

## 예상 결과

> 예상했던 정상적인 결과가 어떤 것이었는지 설명해주세요

## 참고할만한 자료(선택)
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: feat
about: 기능 개발 이슈 템플릿
title: ''
labels: feat
assignees: ''

---

## 어떤 기능인가요?

> 추가하려는 기능에 대해 간결하게 설명해주세요

## 작업 상세 내용

- [ ] TODO

## 참고할만한 자료(선택)
18 changes: 18 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## 🧙 PR 타입
- [ ] 기능 추가
- [ ] 기능 삭제
- [ ] 버그 수정
- [ ] 의존성, 환경 변수, 빌드 관련 코드 업데이트

## #️⃣연관 이슈

> ex) #이슈번호

## 📝작업 내용

> 이번 PR에서 작업한 내용을 간략히 설명해주세요

## 💬리뷰 시 요구사항 (선택)

> 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요
>
65 changes: 65 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CD

on:
push:
branches:
- main

permissions: write-all

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# gradle 캐싱
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

# prod properties 설정
- name: Make application-prod.properties
run: |
cd ./src/main/resources
touch ./application-prod.properties
echo "${{ secrets.PROPERTIES_PROD }}" > ./application-prod.properties
shell: bash

# test를 제외한 프로젝트 빌드
- name: Build With Gradle
run: ./gradlew build -x test

# 도커 빌드 & 이미지 push
- name: Docker build & Push
run: |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}/algobaro-api .
docker push ${{ secrets.DOCKER_REPO }}/algobaro-api
# docker-compose 파일을 ec2 서버에 배포
- name: Deploy to Prod
uses: appleboy/ssh-action@master
id: deploy-prod
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
docker stop algobaro-api
docker rm algobaro-api
sudo docker pull ${{ secrets.DOCKER_REPO }}/algobaro-api
docker run -d --name algobaro-api -p 8080:8080 ${{ secrets.DOCKER_REPO }}/algobaro-api
docker rmi -f $(docker images -f "dangling=true" -q)
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
pull_request:
branches: [ "main" ]

# 테스트 결과 작성을 위해 쓰기권한 추가
permissions: write-all

# 해당 Workflow의 Job 목록
jobs:
build:
# Runner가 실행되는 환경을 정의
runs-on: ubuntu-latest

# build Job 내의 step 목록
steps:
# uses 키워드를 통해 Action 호출
- uses: actions/checkout@v4
# jdk 세팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# gradle 캐싱
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

### CI
#gradlew 권한 추가
- name: Grant Execute Permission For Gradlew
run: chmod +x gradlew

#test를 제외한 프로젝트 빌드
- name: Build With Gradle
run: ./gradlew build -x test

#test를 위한 mysql설정
- name: Start MySQL
uses: samin/[email protected]
with:
host port: 3305
container port: 3305
mysql database: 'algobaro'
mysql user: 'admin'
mysql password: 'admin1234'

#테스트를 위한 test properties 설정
- name: Make application-test.properties
run: |
cd ./src/test/resources
touch ./application.properties
echo "${{ secrets.PROPERTIES_TEST }}" > ./application.properties
shell: bash

#test코드 빌드
- name: Build With Test
run: ./gradlew test

#테스트 결과 파일 생성
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ always() }}
with:
files: build/test-results/**/*.xml
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17
ARG JAR_FILE=./build/libs/algobaro-api-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar", "--spring.profiles.active=prod"]
28 changes: 26 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,35 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'

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

// Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'

// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// Lombok
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'

// MySQL
runtimeOnly 'com.mysql:mysql-connector-j'

// QueryDSL
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"

services:
database:
container_name: mysql
image: mysql/mysql-server:latest
environment:
MYSQL_DATABASE: algobaro
MYSQL_USER: admin
MYSQL_PASSWORD: admin1234
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: rootpwd
command:
- --default-authentication-plugin=mysql_native_password
ports:
- 3305:3306
networks:
- db_network
restart: always
mytamla:
build: .
expose:
- 8080
depends_on:
- database

networks:
db_network:
driver: bridge
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package e5i.algobaroapi;
package ei.algobaroapi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ei.algobaroapi.domain.auth.controller;

import ei.algobaroapi.domain.auth.dto.AuthSignInRequest;
import ei.algobaroapi.domain.auth.dto.AuthSignInResponse;
import ei.algobaroapi.domain.auth.dto.AuthSignUpRequest;
import ei.algobaroapi.domain.auth.service.AuthService;
import ei.algobaroapi.domain.member.domain.Member;
import ei.algobaroapi.global.config.swaggerdoc.AuthControllerDoc;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class AuthController implements AuthControllerDoc {

private final AuthService authService;

@Override
@PostMapping("/auth/sign-up")
public void signUp(@RequestBody AuthSignUpRequest request) {
this.authService.signUp(request);
}

@Override
@PostMapping("/auth/sign-in")
public AuthSignInResponse signIn(@RequestBody AuthSignInRequest request) {
return this.authService.signIn(request);
}

@Override
@GetMapping("/auth/test")
public String hello(@AuthenticationPrincipal Member member) {
System.out.println(member.getEmail().getEmail());
return "Hello, World!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ei.algobaroapi.domain.auth.dto;

import lombok.Getter;

@Getter
public class AuthSignInRequest {

private String email;
private String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ei.algobaroapi.domain.auth.dto;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class AuthSignInResponse {

private final String accessToken;

public static AuthSignInResponse of(String accessToken) {
return new AuthSignInResponse(accessToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ei.algobaroapi.domain.auth.dto;

import ei.algobaroapi.domain.member.domain.Member;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class AuthSignUpRequest {

private String email;
private String password;

public Member toEntity(String encryptPassword) {
return Member.builder()
.email(this.email)
.password(encryptPassword)
.build();
}
}
Loading
Loading