From 91084c122d623c250587d1b17f90a470d385f94f Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 14:41:42 +0900 Subject: [PATCH 01/54] =?UTF-8?q?chore:=20github=20actions=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 39 +++++++++++++++++++++++++++ be/src/main/resources/application.yml | 3 --- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/actions.yml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000000..a6d2cf6037 --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,39 @@ +name: CI + +on: + push: + branches: [ "deploy" ] + pull_request: + branches: [ "develop-BE" ] + + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Java JDK + uses: actions/setup-java@v3.4.0 + with: + distribution: 'adopt-hotspot' + java-version: '11' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Setup MySQL + uses: mirromutth/mysql-action@v1.1 + with: + mysql database: actions + mysql user: root + mysql root password: ${{ secrets.MYSQL_ROOT_PASSWORD }} + + - name: Set application.yml for deploy + working-directory: ./src/main/resources + run: echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml + + - name: Build with Gradle + run: ./gradlew bootJar diff --git a/be/src/main/resources/application.yml b/be/src/main/resources/application.yml index c01e7031d2..a4aa4a3e8e 100644 --- a/be/src/main/resources/application.yml +++ b/be/src/main/resources/application.yml @@ -1,7 +1,4 @@ spring: -# mvc: -# servlet: -# path: /api datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/issuetracker From 53d56ddeb398f847cf6594ff171edad3abe76059 Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 14:46:00 +0900 Subject: [PATCH 02/54] =?UTF-8?q?chore:=20github=20actions=20=EB=94=94?= =?UTF-8?q?=EB=A0=89=ED=86=A0=EB=A6=AC=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index a6d2cf6037..a32af79780 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -9,6 +9,9 @@ on: workflow_dispatch: jobs: + defaults: + run: + working-directory: "./be" build: runs-on: ubuntu-latest From 4851abd0801e9b27e58e5c3a466c64e864dfc1bc Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 14:47:28 +0900 Subject: [PATCH 03/54] =?UTF-8?q?style:=20github=20actions=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index a32af79780..46e1a04986 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -9,11 +9,11 @@ on: workflow_dispatch: jobs: - defaults: - run: - working-directory: "./be" build: runs-on: ubuntu-latest + defaults: + run: + working-directory: "./be" steps: - uses: actions/checkout@v3 From 7bf558dc0ed4be7b92394c41829ce954645696f8 Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 14:49:37 +0900 Subject: [PATCH 04/54] =?UTF-8?q?chore:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 46e1a04986..e4dff117b6 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -35,7 +35,7 @@ jobs: mysql root password: ${{ secrets.MYSQL_ROOT_PASSWORD }} - name: Set application.yml for deploy - working-directory: ./src/main/resources + working-directory: ./be/src/main/resources run: echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml - name: Build with Gradle From 51b26bdc026064eb8f27f9447910d68e2016fe60 Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 14:53:19 +0900 Subject: [PATCH 05/54] =?UTF-8?q?chore:=20application-prod=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index e4dff117b6..f3436bda65 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -30,13 +30,15 @@ jobs: - name: Setup MySQL uses: mirromutth/mysql-action@v1.1 with: - mysql database: actions + mysql database: issuetracker mysql user: root mysql root password: ${{ secrets.MYSQL_ROOT_PASSWORD }} - name: Set application.yml for deploy working-directory: ./be/src/main/resources - run: echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml + run: | + touch application-prod.yml + echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml - name: Build with Gradle run: ./gradlew bootJar From a882d27c294b83ad5a6dbb7cf1650630973eb036 Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 14:56:58 +0900 Subject: [PATCH 06/54] Update actions.yml --- .github/workflows/actions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index f3436bda65..9e8ef1c9bb 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -37,8 +37,8 @@ jobs: - name: Set application.yml for deploy working-directory: ./be/src/main/resources run: | - touch application-prod.yml - echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml + touch application-prod.yml + echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml - name: Build with Gradle run: ./gradlew bootJar From 10e891ea6855fc4f2d1427412e4d52ba3d718fec Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 15:26:14 +0900 Subject: [PATCH 07/54] =?UTF-8?q?chore:=20step=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 9e8ef1c9bb..e70a43c1b1 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -18,12 +18,18 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set application.yml for deploy + working-directory: ./be/src/main/resources + run: | + touch application-prod.yml + echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml + - name: Setup Java JDK uses: actions/setup-java@v3.4.0 with: distribution: 'adopt-hotspot' java-version: '11' - + - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -33,12 +39,6 @@ jobs: mysql database: issuetracker mysql user: root mysql root password: ${{ secrets.MYSQL_ROOT_PASSWORD }} - - - name: Set application.yml for deploy - working-directory: ./be/src/main/resources - run: | - touch application-prod.yml - echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml - name: Build with Gradle run: ./gradlew bootJar From f49f23ad3f40b1771126c4dbe5c43ea91f305086 Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 15:27:52 +0900 Subject: [PATCH 08/54] =?UTF-8?q?chore:=20application-yml=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index e70a43c1b1..5d4b50810b 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -21,8 +21,8 @@ jobs: - name: Set application.yml for deploy working-directory: ./be/src/main/resources run: | - touch application-prod.yml echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml + cat application-prod.yml - name: Setup Java JDK uses: actions/setup-java@v3.4.0 From 46c5dcce47d923ff0bcba4ff1f6d077b709d3d67 Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 15:39:16 +0900 Subject: [PATCH 09/54] =?UTF-8?q?chore:=20docker=20=EB=B9=8C=EB=93=9C=20?= =?UTF-8?q?=ED=9B=84=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4=ED=81=AC=EB=A6=BD?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 5d4b50810b..d7c693877e 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -42,3 +42,28 @@ jobs: - name: Build with Gradle run: ./gradlew bootJar + + - name: Docker Login + uses: docker/login-action@v2.0.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_SECRET }} + + - name: Docker build + run: | + docker build -t issue-tracker . + docker tag issue-tracker ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:${GITHUB_SHA::7} + docker push ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:${GITHUB_SHA::7} + + - name: deploy! + uses: appleboy/ssh-action@v0.1.4 + with: + host: ${{ secrets.SSH_HOST }} + username: ubuntu + key: ${{ secrets.PRIVATE_KEY }} + envs: GITHUB_SHA + script: | + sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && docker stop issue-tracker && docker rm issue-tracker | true + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:${GITHUB_SHA::7} + sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-trakcer:${GITHUB_SHA::7} issue-tracker + sudo docker run -d -e --name issue-tracker -p 80:8080 issue-tracker From da0eb2d41999f1bcb1de93aa74c7bbae3f2f10eb Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 15:39:53 +0900 Subject: [PATCH 10/54] =?UTF-8?q?style:=20indent=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index d7c693877e..509f7c385e 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -43,7 +43,7 @@ jobs: - name: Build with Gradle run: ./gradlew bootJar - - name: Docker Login + - name: Docker Login uses: docker/login-action@v2.0.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -63,7 +63,7 @@ jobs: key: ${{ secrets.PRIVATE_KEY }} envs: GITHUB_SHA script: | - sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && docker stop issue-tracker && docker rm issue-tracker | true + sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && docker stop issue-tracker && docker rm issue-tracker | true sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:${GITHUB_SHA::7} sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-trakcer:${GITHUB_SHA::7} issue-tracker sudo docker run -d -e --name issue-tracker -p 80:8080 issue-tracker From 93ba08b1de63fd0991397d8690069f00a609379c Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 15:41:07 +0900 Subject: [PATCH 11/54] =?UTF-8?q?chore:=20Dockerfile=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 be/Dockerfile diff --git a/be/Dockerfile b/be/Dockerfile new file mode 100644 index 0000000000..88da91a8c1 --- /dev/null +++ b/be/Dockerfile @@ -0,0 +1,5 @@ +FROM adoptopenjdk/openjdk11 +ARG JAR_FILE=build/libs/*.jar +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "/app.jar"] + From a74782d8d5f8efb02af7ef56310e2910850f9208 Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 15:49:52 +0900 Subject: [PATCH 12/54] =?UTF-8?q?style:=20=EC=BB=A8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=84=88=20=EB=B2=84=EC=A0=84=20=EB=AA=85=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 509f7c385e..41557c1ece 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -52,8 +52,8 @@ jobs: - name: Docker build run: | docker build -t issue-tracker . - docker tag issue-tracker ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:${GITHUB_SHA::7} - docker push ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:${GITHUB_SHA::7} + docker tag issue-tracker ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 + docker push ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 - name: deploy! uses: appleboy/ssh-action@v0.1.4 @@ -64,6 +64,6 @@ jobs: envs: GITHUB_SHA script: | sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && docker stop issue-tracker && docker rm issue-tracker | true - sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:${GITHUB_SHA::7} - sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-trakcer:${GITHUB_SHA::7} issue-tracker + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 + sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-trakcer:1.0.0 issue-tracker sudo docker run -d -e --name issue-tracker -p 80:8080 issue-tracker From ce86ad0d56109db9a4fb7338272477d14bec30c6 Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 15:54:35 +0900 Subject: [PATCH 13/54] Update actions.yml --- .github/workflows/actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 41557c1ece..910a2fc3ae 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -63,6 +63,7 @@ jobs: key: ${{ secrets.PRIVATE_KEY }} envs: GITHUB_SHA script: | + ls -al sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && docker stop issue-tracker && docker rm issue-tracker | true sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-trakcer:1.0.0 issue-tracker From 0b243653cb4ca0c386fe6e6c082ecdb2428c6baf Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 16:00:28 +0900 Subject: [PATCH 14/54] =?UTF-8?q?style:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 910a2fc3ae..d5b79cc700 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -66,5 +66,5 @@ jobs: ls -al sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && docker stop issue-tracker && docker rm issue-tracker | true sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 - sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-trakcer:1.0.0 issue-tracker + sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 issue-tracker sudo docker run -d -e --name issue-tracker -p 80:8080 issue-tracker From d339c59d6111642ab108d68c92a5f878ce0489eb Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 16:00:54 +0900 Subject: [PATCH 15/54] =?UTF-8?q?style:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=98=B5=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index d5b79cc700..70c0493642 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -67,4 +67,4 @@ jobs: sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && docker stop issue-tracker && docker rm issue-tracker | true sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 issue-tracker - sudo docker run -d -e --name issue-tracker -p 80:8080 issue-tracker + sudo docker run -d --name issue-tracker -p 80:8080 issue-tracker From 056999a19dba0f7635850470d12a5ed86fc52ffe Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 16:09:36 +0900 Subject: [PATCH 16/54] =?UTF-8?q?style:=20sudo=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 70c0493642..2d7d15b78f 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -64,7 +64,7 @@ jobs: envs: GITHUB_SHA script: | ls -al - sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && docker stop issue-tracker && docker rm issue-tracker | true + sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && sudo docker stop issue-tracker && sudo docker rm issue-tracker | true sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 issue-tracker sudo docker run -d --name issue-tracker -p 80:8080 issue-tracker From f30ab23669a1191e0498208c238d38bb8ded06fb Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 16:45:13 +0900 Subject: [PATCH 17/54] =?UTF-8?q?style:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/main/resources/application.yml b/be/src/main/resources/application.yml index a4aa4a3e8e..75aa51f067 100644 --- a/be/src/main/resources/application.yml +++ b/be/src/main/resources/application.yml @@ -21,7 +21,7 @@ oauth: google: client_id: 886648386281-q6205r09trl1iu29qa09b2sdufbvhgth.apps.googleusercontent.com client_secret: ${GOOGLE_CLIENT_SECRET} - redirect_url: https://accounts.google.com/o/oauth2/v2/auth?client_id=${oauth.github.client_id}&redirect_uri=${oauth.redirect_url}/oauth/google/callback&response_type=code&scope=profile email' + redirect_url: https://accounts.google.com/o/oauth2/v2/auth?client_id=${oauth.google.client_id}&redirect_uri=${oauth.redirect_url}/oauth/google/callback&response_type=code&scope=profile email auth: jwt: From b031de5d0cb91df4cf27743bb15f4bbd72238291 Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 16:47:58 +0900 Subject: [PATCH 18/54] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20script=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 2d7d15b78f..a106268044 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -22,7 +22,6 @@ jobs: working-directory: ./be/src/main/resources run: | echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml - cat application-prod.yml - name: Setup Java JDK uses: actions/setup-java@v3.4.0 @@ -41,7 +40,7 @@ jobs: mysql root password: ${{ secrets.MYSQL_ROOT_PASSWORD }} - name: Build with Gradle - run: ./gradlew bootJar + run: ./gradlew build - name: Docker Login uses: docker/login-action@v2.0.0 @@ -63,7 +62,6 @@ jobs: key: ${{ secrets.PRIVATE_KEY }} envs: GITHUB_SHA script: | - ls -al sudo docker ps -a -q -f "name=issue-tracker" | grep -q . && sudo docker stop issue-tracker && sudo docker rm issue-tracker | true sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracker:1.0.0 issue-tracker From 0549cf066fc127bdd1ca7c4cca4b3a62b2cb044f Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 17:00:53 +0900 Subject: [PATCH 19/54] =?UTF-8?q?chore:=20=EB=B9=8C=EB=93=9C=20=EC=8B=9C?= =?UTF-8?q?=20=ED=94=84=EB=A1=9C=ED=95=84=20=EB=AA=85=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index a106268044..b39ed6844c 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -40,7 +40,7 @@ jobs: mysql root password: ${{ secrets.MYSQL_ROOT_PASSWORD }} - name: Build with Gradle - run: ./gradlew build + run: ./gradlew build -Pprofile=prod - name: Docker Login uses: docker/login-action@v2.0.0 From a4aca8ba08cc694132f98c42da6318d1fc6f3f2f Mon Sep 17 00:00:00 2001 From: "Seyeong Kim(Suntory)" Date: Sun, 26 Jun 2022 17:18:30 +0900 Subject: [PATCH 20/54] =?UTF-8?q?chore:=20=EB=B9=8C=EB=93=9C=20=EC=8B=9C?= =?UTF-8?q?=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=EA=B0=80=20=EB=93=A4?= =?UTF-8?q?=EC=96=B4=EA=B0=84=20application.yml=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B5=90=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index b39ed6844c..737d22c3f7 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -21,6 +21,8 @@ jobs: - name: Set application.yml for deploy working-directory: ./be/src/main/resources run: | + cat /dev/null > application.yml + echo "${{ secrets.APPLICATION_DEVELOP }}" >> ./application.yml echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml - name: Setup Java JDK @@ -40,7 +42,7 @@ jobs: mysql root password: ${{ secrets.MYSQL_ROOT_PASSWORD }} - name: Build with Gradle - run: ./gradlew build -Pprofile=prod + run: ./gradlew build - name: Docker Login uses: docker/login-action@v2.0.0 From 2e49f072481f3b49b1c31436f0319314282e7c9c Mon Sep 17 00:00:00 2001 From: seyeong Date: Sun, 26 Jun 2022 17:26:27 +0900 Subject: [PATCH 21/54] =?UTF-8?q?chore:=20plain=20jar=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/be/build.gradle b/be/build.gradle index 0f9b70e605..34de9b0a21 100644 --- a/be/build.gradle +++ b/be/build.gradle @@ -4,6 +4,10 @@ plugins { id 'java' } +jar { + enabled = false +} + group = 'com.codesquad' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' From d130535e8bbeb1ba796b7e10009c64b8d942c50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=A8=EC=84=9D=ED=98=B8?= Date: Tue, 28 Jun 2022 10:49:25 +0900 Subject: [PATCH 22/54] =?UTF-8?q?refactor=20:=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=A5=BC=20=ED=95=84=EB=93=9C=EB=A1=9C=20?= =?UTF-8?q?=EA=B0=80=EC=A7=80=EB=8A=94=20Property=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/properties/GithubProperty.java | 25 ++++++++++++++++++ .../common/properties/GoogleProperty.java | 26 +++++++++++++++++++ .../user/application/oauth/OAuthProvider.java | 7 +++++ be/src/main/resources/application.yml | 7 ++++- 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 be/src/main/java/com/codesquad/issuetracker/common/properties/GithubProperty.java create mode 100644 be/src/main/java/com/codesquad/issuetracker/common/properties/GoogleProperty.java diff --git a/be/src/main/java/com/codesquad/issuetracker/common/properties/GithubProperty.java b/be/src/main/java/com/codesquad/issuetracker/common/properties/GithubProperty.java new file mode 100644 index 0000000000..c1b6c225fd --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/common/properties/GithubProperty.java @@ -0,0 +1,25 @@ +package com.codesquad.issuetracker.common.properties; + +import lombok.Getter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; + +@Getter +@ConstructorBinding +@ConfigurationProperties(prefix = "oauth.github") +public class GithubProperty { + + private final String clientId; + private final String clientSecret; + private final String redirectUrl; + private final String accessTokenUrl; + private final String resourceUrl; + + public GithubProperty(String clientId, String clientSecret, String redirectUrl, String accessTokenUrl, String resourceUrl) { + this.clientId = clientId; + this.clientSecret = clientSecret; + this.redirectUrl = redirectUrl; + this.accessTokenUrl = accessTokenUrl; + this.resourceUrl = resourceUrl; + } +} diff --git a/be/src/main/java/com/codesquad/issuetracker/common/properties/GoogleProperty.java b/be/src/main/java/com/codesquad/issuetracker/common/properties/GoogleProperty.java new file mode 100644 index 0000000000..4c1e15a496 --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/common/properties/GoogleProperty.java @@ -0,0 +1,26 @@ +package com.codesquad.issuetracker.common.properties; + +import lombok.Getter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; + +@Getter +@ConstructorBinding +@ConfigurationProperties(prefix = "oauth.google") +public class GoogleProperty { + + private final String clientId; + private final String clientSecret; + private final String redirectUrl; + private final String accessTokenUrl; + private final String resourceUrl; + + + public GoogleProperty(String clientId, String clientSecret, String redirectUrl, String accessTokenUrl, String resourceUrl) { + this.clientId = clientId; + this.clientSecret = clientSecret; + this.redirectUrl = redirectUrl; + this.accessTokenUrl = accessTokenUrl; + this.resourceUrl = resourceUrl; + } +} diff --git a/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/OAuthProvider.java b/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/OAuthProvider.java index 101dedc517..5f9f01a95f 100644 --- a/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/OAuthProvider.java +++ b/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/OAuthProvider.java @@ -1,10 +1,17 @@ package com.codesquad.issuetracker.user.application.oauth; import com.codesquad.issuetracker.user.application.dto.OAuthUserInformation; +import com.codesquad.issuetracker.user.domain.LoginType; import org.springframework.stereotype.Service; @Service public interface OAuthProvider { + LoginType getOAuthType(); + + String getRedirectUrl(); + OAuthUserInformation requestUserInformation(String code); + + } diff --git a/be/src/main/resources/application.yml b/be/src/main/resources/application.yml index 75aa51f067..936008bd07 100644 --- a/be/src/main/resources/application.yml +++ b/be/src/main/resources/application.yml @@ -10,7 +10,8 @@ spring: open-in-view: false logging: - level.com.codesquad.issuetracker: debug + level: + com.codesquad.issuetracker: debug oauth: redirect_url: ${REDIRECT_URL} @@ -18,10 +19,14 @@ oauth: client_id: fbfd3db42dc5b227d1b8 client_secret: ${GITHUB_CLIENT_SECRET} redirect_url: https://github.com/login/oauth/authorize?client_id=${oauth.github.client_id}&scope=user:email + access_token_url: https://github.com/login/oauth/access_token + resource_url: https://api.github.com/user google: client_id: 886648386281-q6205r09trl1iu29qa09b2sdufbvhgth.apps.googleusercontent.com client_secret: ${GOOGLE_CLIENT_SECRET} redirect_url: https://accounts.google.com/o/oauth2/v2/auth?client_id=${oauth.google.client_id}&redirect_uri=${oauth.redirect_url}/oauth/google/callback&response_type=code&scope=profile email + access_token_url: https://oauth2.googleapis.com/token + resource_url: https://www.googleapis.com/oauth2/v2/userinfo?alt=json auth: jwt: From b8d00e0d679b796ab09ccb2a4b3e335c649cacc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=A8=EC=84=9D=ED=98=B8?= Date: Tue, 28 Jun 2022 10:51:16 +0900 Subject: [PATCH 23/54] =?UTF-8?q?refactor=20:=20Oauth=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=EB=B0=94=EC=9D=B4=EB=8D=94=EC=97=90=20=EA=B3=B5=ED=86=B5=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nService.java => GithubLoginProvider.java} | 33 ++++++++++------- ...nService.java => GoogleLoginProvider.java} | 37 +++++++++++-------- 2 files changed, 41 insertions(+), 29 deletions(-) rename be/src/main/java/com/codesquad/issuetracker/user/application/oauth/{GithubLoginService.java => GithubLoginProvider.java} (77%) rename be/src/main/java/com/codesquad/issuetracker/user/application/oauth/{GoogleLoginService.java => GoogleLoginProvider.java} (65%) diff --git a/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GithubLoginService.java b/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GithubLoginProvider.java similarity index 77% rename from be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GithubLoginService.java rename to be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GithubLoginProvider.java index 47d7e372b8..d63c8a679b 100644 --- a/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GithubLoginService.java +++ b/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GithubLoginProvider.java @@ -1,10 +1,11 @@ package com.codesquad.issuetracker.user.application.oauth; +import com.codesquad.issuetracker.common.properties.GithubProperty; import com.codesquad.issuetracker.user.application.dto.GithubAccessToken; import com.codesquad.issuetracker.user.application.dto.GithubTokenRequestDto; import com.codesquad.issuetracker.user.application.dto.GithubUserInformation; +import com.codesquad.issuetracker.user.domain.LoginType; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,24 +14,28 @@ @Slf4j @Transactional @Service -public class GithubLoginService implements OAuthProvider { +public class GithubLoginProvider implements OAuthProvider { - private static final String GITHUB_ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token"; - private static final String GITHUB_RESOURCE_URL = "https://api.github.com/user"; + private final GithubProperty githubProperty; - private final String clientId; - private final String clientSecret; + public GithubLoginProvider(GithubProperty githubProperty) { + this.githubProperty = githubProperty; + } + + + @Override + public LoginType getOAuthType() { + return LoginType.GITHUB; + } - public GithubLoginService( - @Value("${oauth.github.client_id}") String clientId, - @Value("${oauth.github.client_secret}") String clientSecret) { - this.clientId = clientId; - this.clientSecret = clientSecret; + @Override + public String getRedirectUrl() { + return githubProperty.getRedirectUrl(); } @Override public GithubUserInformation requestUserInformation(String code) { - GithubTokenRequestDto githubTokenRequestDto = new GithubTokenRequestDto(clientId, clientSecret, code); + GithubTokenRequestDto githubTokenRequestDto = new GithubTokenRequestDto(githubProperty.getClientId(), githubProperty.getClientSecret(), code); log.debug("OAuthService, login: {}", githubTokenRequestDto); GithubAccessToken githubAccessToken = requestAccessToken(githubTokenRequestDto); @@ -45,7 +50,7 @@ public GithubUserInformation requestUserInformation(String code) { private GithubAccessToken requestAccessToken(GithubTokenRequestDto githubTokenRequestDto) { return WebClient .builder() - .baseUrl(GITHUB_ACCESS_TOKEN_URL) + .baseUrl(githubProperty.getAccessTokenUrl()) .build() .post() .bodyValue(githubTokenRequestDto) @@ -59,7 +64,7 @@ private GithubUserInformation requestUserInformation(GithubAccessToken githubAcc String tokenString = createTokenString(githubAccessToken); GithubUserInformation userInformation = WebClient.builder() - .baseUrl(GITHUB_RESOURCE_URL) + .baseUrl(githubProperty.getResourceUrl()) .build() .get() .header("Authorization", tokenString) diff --git a/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GoogleLoginService.java b/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GoogleLoginProvider.java similarity index 65% rename from be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GoogleLoginService.java rename to be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GoogleLoginProvider.java index ca450d5d3e..17d51e6d26 100644 --- a/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GoogleLoginService.java +++ b/be/src/main/java/com/codesquad/issuetracker/user/application/oauth/GoogleLoginProvider.java @@ -1,8 +1,12 @@ package com.codesquad.issuetracker.user.application.oauth; -import com.codesquad.issuetracker.user.application.dto.*; +import com.codesquad.issuetracker.common.properties.GoogleProperty; +import com.codesquad.issuetracker.user.application.dto.GoogleAccessToken; +import com.codesquad.issuetracker.user.application.dto.GoogleTokenRequestDto; +import com.codesquad.issuetracker.user.application.dto.GoogleUserInformation; +import com.codesquad.issuetracker.user.application.dto.OAuthUserInformation; +import com.codesquad.issuetracker.user.domain.LoginType; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -11,24 +15,27 @@ @Slf4j @Transactional @Service -public class GoogleLoginService implements OAuthProvider { +public class GoogleLoginProvider implements OAuthProvider { - private static final String GOOGLE_ACCESS_TOKEN_URL = "https://oauth2.googleapis.com/token"; - private static final String GOOGLE_RESOURCE_URL = "https://www.googleapis.com/oauth2/v2/userinfo?alt=json"; + private final GoogleProperty googleProperty; - private final String clientId; - private final String clientSecret; + public GoogleLoginProvider(GoogleProperty googleProperty) { + this.googleProperty = googleProperty; + } - public GoogleLoginService( - @Value("${oauth.google.client_id}") String clientId, - @Value("${oauth.google.client_secret}") String clientSecret) { - this.clientId = clientId; - this.clientSecret = clientSecret; + @Override + public LoginType getOAuthType() { + return LoginType.GOOGLE; + } + + @Override + public String getRedirectUrl() { + return googleProperty.getRedirectUrl(); } @Override public OAuthUserInformation requestUserInformation(String code) { - GoogleTokenRequestDto googleTokenRequestDto = new GoogleTokenRequestDto(clientId, clientSecret, code); + GoogleTokenRequestDto googleTokenRequestDto = new GoogleTokenRequestDto(googleProperty.getClientId(), googleProperty.getClientSecret(), code); log.debug("OAuthService, login: {}", googleTokenRequestDto); GoogleAccessToken googleAccessToken = requestAccessToken(googleTokenRequestDto); @@ -40,7 +47,7 @@ public OAuthUserInformation requestUserInformation(String code) { private GoogleAccessToken requestAccessToken(GoogleTokenRequestDto googleTokenRequestDto) { return WebClient .builder() - .baseUrl(GOOGLE_ACCESS_TOKEN_URL) + .baseUrl(googleProperty.getAccessTokenUrl()) .build() .post() .bodyValue(googleTokenRequestDto) @@ -54,7 +61,7 @@ private GoogleUserInformation requestUserInformation(GoogleAccessToken googleAcc String tokenString = createTokenString(googleAccessToken); GoogleUserInformation userInformation = WebClient.builder() - .baseUrl(GOOGLE_RESOURCE_URL) + .baseUrl(googleProperty.getResourceUrl()) .build() .get() .header("Authorization", tokenString) From b1a6f048d06778c43d53a54bbe2478a0536d3327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=A8=EC=84=9D=ED=98=B8?= Date: Tue, 28 Jun 2022 10:51:38 +0900 Subject: [PATCH 24/54] =?UTF-8?q?refactor=20:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20api=20=EC=B6=94=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/config/AuthConfig.java | 12 ++++++ .../user/application/OAuthLoginService.java | 23 +++++------ .../controller/LoginController.java | 38 +++++-------------- 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/be/src/main/java/com/codesquad/issuetracker/common/config/AuthConfig.java b/be/src/main/java/com/codesquad/issuetracker/common/config/AuthConfig.java index 6085d3e44c..9d622dcbd7 100644 --- a/be/src/main/java/com/codesquad/issuetracker/common/config/AuthConfig.java +++ b/be/src/main/java/com/codesquad/issuetracker/common/config/AuthConfig.java @@ -2,14 +2,20 @@ import com.codesquad.issuetracker.auth.presentation.argumentresolver.AuthArgumentResolver; import com.codesquad.issuetracker.auth.presentation.interceptor.AuthInterceptor; +import com.codesquad.issuetracker.user.application.oauth.OAuthProvider; +import com.codesquad.issuetracker.user.domain.LoginType; import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.EnumMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; @RequiredArgsConstructor @Configuration @@ -44,4 +50,10 @@ public void addCorsMappings(CorsRegistry registry) { .allowedOrigins("*") .allowedMethods("*"); } + + @Bean + public EnumMap oAuthProviderEnumMap(List oAuthProviders) { + return new EnumMap<>(oAuthProviders.stream() + .collect(Collectors.toMap(OAuthProvider::getOAuthType, u -> u))); + } } diff --git a/be/src/main/java/com/codesquad/issuetracker/user/application/OAuthLoginService.java b/be/src/main/java/com/codesquad/issuetracker/user/application/OAuthLoginService.java index 28147d1f48..9962a164ff 100644 --- a/be/src/main/java/com/codesquad/issuetracker/user/application/OAuthLoginService.java +++ b/be/src/main/java/com/codesquad/issuetracker/user/application/OAuthLoginService.java @@ -2,9 +2,10 @@ import com.codesquad.issuetracker.auth.application.JwtProvider; import com.codesquad.issuetracker.user.application.dto.OAuthUserInformation; -import com.codesquad.issuetracker.user.application.oauth.GithubLoginService; -import com.codesquad.issuetracker.user.application.oauth.GoogleLoginService; +import com.codesquad.issuetracker.user.application.oauth.GithubLoginProvider; +import com.codesquad.issuetracker.user.application.oauth.GoogleLoginProvider; import com.codesquad.issuetracker.user.application.oauth.OAuthProvider; +import com.codesquad.issuetracker.user.domain.LoginType; import com.codesquad.issuetracker.user.domain.User; import com.codesquad.issuetracker.user.presentation.dto.LoginResponseDto; import com.codesquad.issuetracker.user.presentation.dto.UserJoinRequestDto; @@ -13,6 +14,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.EnumMap; + @Slf4j @RequiredArgsConstructor @Transactional @@ -21,18 +24,16 @@ public class OAuthLoginService { private final JwtProvider jwtProvider; private final UserService userService; - private final GithubLoginService githubLoginService; - private final GoogleLoginService googleLoginService; - public LoginResponseDto githubLogin(String code) { - return login(code, githubLoginService); - } + private final EnumMap oAuthProviderEnumMap; - public LoginResponseDto googleLogin(String code) { - return login(code, googleLoginService); + public String getRedirectUrl(LoginType type) { + OAuthProvider oAuthProvider = oAuthProviderEnumMap.get(type); + return oAuthProvider.getRedirectUrl(); } - public LoginResponseDto login(String code, OAuthProvider oAuthProvider) { + public LoginResponseDto login(String code, LoginType type) { + OAuthProvider oAuthProvider = oAuthProviderEnumMap.get(type); OAuthUserInformation oAuthUserInformation = oAuthProvider.requestUserInformation(code); User user = oAuthLogin(oAuthUserInformation); @@ -45,7 +46,7 @@ public LoginResponseDto login(String code, OAuthProvider oAuthProvider) { return new LoginResponseDto(accessToken, refreshToken); } - public User oAuthLogin(OAuthUserInformation oAuthUserInformation) { + private User oAuthLogin(OAuthUserInformation oAuthUserInformation) { return userService.findByUsername(oAuthUserInformation.getUsername()) .orElseGet(() -> userService.join(UserJoinRequestDto.from(oAuthUserInformation))); } diff --git a/be/src/main/java/com/codesquad/issuetracker/user/presentation/controller/LoginController.java b/be/src/main/java/com/codesquad/issuetracker/user/presentation/controller/LoginController.java index db6ce65010..dfb2234223 100644 --- a/be/src/main/java/com/codesquad/issuetracker/user/presentation/controller/LoginController.java +++ b/be/src/main/java/com/codesquad/issuetracker/user/presentation/controller/LoginController.java @@ -3,19 +3,15 @@ import com.codesquad.issuetracker.auth.presentation.argumentresolver.Auth; import com.codesquad.issuetracker.user.application.BasicLoginService; import com.codesquad.issuetracker.user.application.OAuthLoginService; +import com.codesquad.issuetracker.user.domain.LoginType; import com.codesquad.issuetracker.user.presentation.dto.LoginResponseDto; import com.codesquad.issuetracker.user.presentation.dto.UserLoginRequestDto; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.net.URI; -import java.net.URISyntaxException; - @Slf4j @RequiredArgsConstructor @RestController @@ -23,35 +19,19 @@ public class LoginController { private final OAuthLoginService oAuthLoginService; private final BasicLoginService basicLoginService; - @Value("${oauth.github.redirect_url}") - private String githubRedirectUrl; - @Value("${oauth.google.redirect_url}") - private String googleRedirectUrl; @Operation(summary = "Github 로그인 화면으로 Redirect 하기", description = "Github 로그인 페이지로 이동합니다.") - @GetMapping("/oauth/github/login") - public ResponseEntity loginByGithub() { - return ResponseEntity.ok().body(githubRedirectUrl); + @GetMapping("/oauth/{platform}/login") + public ResponseEntity oauthLogin(@PathVariable String platform) { + LoginType loginType = LoginType.valueOf(platform.toUpperCase()); + return ResponseEntity.ok().body(oAuthLoginService.getRedirectUrl(loginType)); } @Operation(summary = "Github 로그인 처리하기", description = "Github Authorization code 를 받아서 로그인을 완료합니다.") - @GetMapping("/oauth/github/callback") - public LoginResponseDto receiveCallbackFromGithub(@RequestParam String code) { - return oAuthLoginService.githubLogin(code); - } - - @Operation(summary = "Google 로그인 화면으로 Redirect 하기", description = "Google 로그인 페이지로 이동합니다.") - @GetMapping("/oauth/google/login") - public ResponseEntity loginByGoogle() { - return ResponseEntity.status(HttpStatus.FOUND) - .header("Location", googleRedirectUrl).build(); - } - - @Operation(summary = "Google 로그인 처리하기", description = "Google Authorization code 를 받아서 로그인을 완료합니다.") - @GetMapping("/oauth/google/callback") - public LoginResponseDto receiveCallbackFromGoogle(@RequestParam String code) { - log.debug("LoginController Google login code: {}", code); - return oAuthLoginService.googleLogin(code); + @GetMapping("/oauth/{platform}/callback") + public LoginResponseDto receiveCallback(@RequestParam String code, @PathVariable String platform) { + LoginType loginType = LoginType.valueOf(platform.toUpperCase()); + return oAuthLoginService.login(code, loginType); } @Operation(summary = "유저 로그인하기", description = "사용자의 로그인을 처리합니다.") From 3d4ec4c6bbfd308d9199e2cca22a0b7568eb603d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=A8=EC=84=9D=ED=98=B8?= Date: Mon, 27 Jun 2022 15:42:06 +0900 Subject: [PATCH 25/54] =?UTF-8?q?refactor=20:=20ExceptionType=EC=97=90=20@?= =?UTF-8?q?Getter=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/type/AuthExceptionType.java | 13 ++---------- .../domain/type/MilestoneExceptionType.java | 20 +++++++++++++++++++ .../domain/type/UserExceptionType.java | 20 +++++-------------- 3 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 be/src/main/java/com/codesquad/issuetracker/exception/domain/type/MilestoneExceptionType.java diff --git a/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/AuthExceptionType.java b/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/AuthExceptionType.java index 39fbf056f0..ce1d5e4db3 100644 --- a/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/AuthExceptionType.java +++ b/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/AuthExceptionType.java @@ -1,7 +1,9 @@ package com.codesquad.issuetracker.exception.domain.type; +import lombok.Getter; import org.springframework.http.HttpStatus; +@Getter public enum AuthExceptionType implements ExceptionType { TOKEN_NOT_FOUND(HttpStatus.UNAUTHORIZED, "AUTH001", "이 api에 접근하기 위해서는 Access 토큰이 필요합니다."), @@ -19,15 +21,4 @@ public enum AuthExceptionType implements ExceptionType { this.message = message; } - public HttpStatus getStatusCode() { - return statusCode; - } - - public String getErrorCode() { - return errorCode; - } - - public String getMessage() { - return message; - } } diff --git a/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/MilestoneExceptionType.java b/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/MilestoneExceptionType.java new file mode 100644 index 0000000000..8ec208c0a6 --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/MilestoneExceptionType.java @@ -0,0 +1,20 @@ +package com.codesquad.issuetracker.exception.domain.type; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +public enum MilestoneExceptionType implements ExceptionType{ + + NOT_FOUND(HttpStatus.NOT_FOUND, "MILE001", "마일스톤이 존재하지 않습니다."); + + private final HttpStatus statusCode; + private final String errorCode; + private final String message; + + MilestoneExceptionType(HttpStatus statusCode, String errorCode, String message) { + this.statusCode = statusCode; + this.errorCode = errorCode; + this.message = message; + } +} diff --git a/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/UserExceptionType.java b/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/UserExceptionType.java index 00dc45b502..94964c0fd4 100644 --- a/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/UserExceptionType.java +++ b/be/src/main/java/com/codesquad/issuetracker/exception/domain/type/UserExceptionType.java @@ -1,13 +1,15 @@ package com.codesquad.issuetracker.exception.domain.type; +import lombok.Getter; import org.springframework.http.HttpStatus; +@Getter public enum UserExceptionType implements ExceptionType { - NOT_FOUND(HttpStatus.NOT_FOUND, "USER001","유저를 찾을 수 없습니다."), - INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "USER002","비밀번호가 틀렸습니다."), + NOT_FOUND(HttpStatus.NOT_FOUND, "USER001", "유저를 찾을 수 없습니다."), + INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "USER002", "비밀번호가 틀렸습니다."), INVALID_FORMAT(HttpStatus.BAD_REQUEST, "USER003", "아이디나 비밀번호 형식이 잘못 되었습니다."), - DUPLICATED_USERNAME(HttpStatus.BAD_REQUEST, "USER004","이미 가입된 아이디입니다."); + DUPLICATED_USERNAME(HttpStatus.BAD_REQUEST, "USER004", "이미 가입된 아이디입니다."); private final HttpStatus statusCode; private final String errorCode; @@ -18,16 +20,4 @@ public enum UserExceptionType implements ExceptionType { this.errorCode = errorCode; this.message = message; } - - public HttpStatus getStatusCode() { - return statusCode; - } - - public String getErrorCode() { - return errorCode; - } - - public String getMessage() { - return message; - } } From 45b4e7ca6872e3afd1b949796233c6e60ecbcb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=A8=EC=84=9D=ED=98=B8?= Date: Mon, 27 Jun 2022 15:46:28 +0900 Subject: [PATCH 26/54] =?UTF-8?q?feat=20:=20Issue,=20Comment,=20Label,=20M?= =?UTF-8?q?ilestone=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issuetracker/comment/domain/Comment.java | 21 +++++++ .../issuetracker/issue/domain/Issue.java | 59 +++++++++++++++++++ .../issue/domain/IssueAssignee.java | 28 +++++++++ .../issuetracker/label/domain/Label.java | 21 +++++++ .../milestone/domain/Milestone.java | 22 +++++++ .../issuetracker/user/domain/User.java | 1 - 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 be/src/main/java/com/codesquad/issuetracker/comment/domain/Comment.java create mode 100644 be/src/main/java/com/codesquad/issuetracker/issue/domain/Issue.java create mode 100644 be/src/main/java/com/codesquad/issuetracker/issue/domain/IssueAssignee.java create mode 100644 be/src/main/java/com/codesquad/issuetracker/label/domain/Label.java create mode 100644 be/src/main/java/com/codesquad/issuetracker/milestone/domain/Milestone.java diff --git a/be/src/main/java/com/codesquad/issuetracker/comment/domain/Comment.java b/be/src/main/java/com/codesquad/issuetracker/comment/domain/Comment.java new file mode 100644 index 0000000000..677a26de8d --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/comment/domain/Comment.java @@ -0,0 +1,21 @@ +package com.codesquad.issuetracker.comment.domain; + +import com.codesquad.issuetracker.issue.domain.Issue; +import com.codesquad.issuetracker.user.domain.User; + +import javax.persistence.*; + +@Entity +public class Comment { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String content; + + @ManyToOne(fetch = FetchType.LAZY) + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + private Issue issue; +} diff --git a/be/src/main/java/com/codesquad/issuetracker/issue/domain/Issue.java b/be/src/main/java/com/codesquad/issuetracker/issue/domain/Issue.java new file mode 100644 index 0000000000..5d3a424eb8 --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/issue/domain/Issue.java @@ -0,0 +1,59 @@ +package com.codesquad.issuetracker.issue.domain; + +import com.codesquad.issuetracker.comment.domain.Comment; +import com.codesquad.issuetracker.milestone.domain.Milestone; +import com.codesquad.issuetracker.user.domain.User; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Getter +@NoArgsConstructor +@Entity +public class Issue { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + private String content; + + @ManyToOne(fetch = FetchType.LAZY) + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + private Milestone milestone; + + @OneToMany(mappedBy = "issue", cascade = CascadeType.ALL) + private Set assignees = new HashSet<>(); + + @OneToMany(mappedBy = "issue", cascade = CascadeType.ALL) + private Set labels = new HashSet<>(); + + @OneToMany(mappedBy = "issue", cascade = CascadeType.ALL) + private List comments = new ArrayList<>(); + + public Issue(String title, String content, User user) { + this.title = title; + this.content = content; + this.user = user; + } + + public void updateMilestone(Milestone milestone) { + this.milestone = milestone; + } + + public void addAssignees(List issueAssignees) { + this.assignees.addAll(issueAssignees); + } + + public void addLabels(List labels) { + this.labels.addAll(labels); + } +} diff --git a/be/src/main/java/com/codesquad/issuetracker/issue/domain/IssueAssignee.java b/be/src/main/java/com/codesquad/issuetracker/issue/domain/IssueAssignee.java new file mode 100644 index 0000000000..5bdb7a9953 --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/issue/domain/IssueAssignee.java @@ -0,0 +1,28 @@ +package com.codesquad.issuetracker.issue.domain; + +import com.codesquad.issuetracker.user.domain.User; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@NoArgsConstructor +@Entity +public class IssueAssignee { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + private User assignee; + + @ManyToOne(fetch = FetchType.LAZY) + private Issue issue; + + public IssueAssignee(Issue issue, User user) { + this.issue = issue; + this.assignee = user; + } +} diff --git a/be/src/main/java/com/codesquad/issuetracker/label/domain/Label.java b/be/src/main/java/com/codesquad/issuetracker/label/domain/Label.java new file mode 100644 index 0000000000..b1d377da3c --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/label/domain/Label.java @@ -0,0 +1,21 @@ +package com.codesquad.issuetracker.label.domain; + +import lombok.Getter; + +import javax.persistence.*; + +@Getter +@Entity +public class Label { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String labelName; + private String description; + private String colorCode; + + @Enumerated(EnumType.STRING) + private TextColor textColor; +} diff --git a/be/src/main/java/com/codesquad/issuetracker/milestone/domain/Milestone.java b/be/src/main/java/com/codesquad/issuetracker/milestone/domain/Milestone.java new file mode 100644 index 0000000000..20d87a9b83 --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/milestone/domain/Milestone.java @@ -0,0 +1,22 @@ +package com.codesquad.issuetracker.milestone.domain; + +import lombok.Getter; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.time.LocalDate; + +@Getter +@Entity +public class Milestone { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + private LocalDate dueDate; + private String description; +} diff --git a/be/src/main/java/com/codesquad/issuetracker/user/domain/User.java b/be/src/main/java/com/codesquad/issuetracker/user/domain/User.java index c58d146e7a..499824bc77 100644 --- a/be/src/main/java/com/codesquad/issuetracker/user/domain/User.java +++ b/be/src/main/java/com/codesquad/issuetracker/user/domain/User.java @@ -6,7 +6,6 @@ import com.codesquad.issuetracker.exception.domain.type.UserExceptionType; import lombok.Getter; import lombok.NoArgsConstructor; -import org.mindrot.jbcrypt.BCrypt; import javax.persistence.*; From 9ef688d836f230bb1ffcc881e6d34980aeb2ff25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=A8=EC=84=9D=ED=98=B8?= Date: Mon, 27 Jun 2022 15:47:14 +0900 Subject: [PATCH 27/54] =?UTF-8?q?feat=20:=20Issue,=20Label,=20Milestone=20?= =?UTF-8?q?Repository=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issuetracker/issue/domain/IssueRepository.java | 6 ++++++ .../issuetracker/label/domain/LabelRepository.java | 11 +++++++++++ .../milestone/domain/MilestoneRepository.java | 9 +++++++++ 3 files changed, 26 insertions(+) create mode 100644 be/src/main/java/com/codesquad/issuetracker/issue/domain/IssueRepository.java create mode 100644 be/src/main/java/com/codesquad/issuetracker/label/domain/LabelRepository.java create mode 100644 be/src/main/java/com/codesquad/issuetracker/milestone/domain/MilestoneRepository.java diff --git a/be/src/main/java/com/codesquad/issuetracker/issue/domain/IssueRepository.java b/be/src/main/java/com/codesquad/issuetracker/issue/domain/IssueRepository.java new file mode 100644 index 0000000000..b7dd65ca15 --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/issue/domain/IssueRepository.java @@ -0,0 +1,6 @@ +package com.codesquad.issuetracker.issue.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface IssueRepository extends JpaRepository { +} diff --git a/be/src/main/java/com/codesquad/issuetracker/label/domain/LabelRepository.java b/be/src/main/java/com/codesquad/issuetracker/label/domain/LabelRepository.java new file mode 100644 index 0000000000..6f2611c307 --- /dev/null +++ b/be/src/main/java/com/codesquad/issuetracker/label/domain/LabelRepository.java @@ -0,0 +1,11 @@ +package com.codesquad.issuetracker.label.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface LabelRepository extends JpaRepository { + + + List