diff --git a/.github/workflows/CD.yml b/.github/workflows/api-CD.yml similarity index 78% rename from .github/workflows/CD.yml rename to .github/workflows/api-CD.yml index 3003dbb8..e845e4cb 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/api-CD.yml @@ -1,10 +1,15 @@ # 워크플로우의 이름 지정 -name: Umbba-Server CD +name: Umbba API Server CD # 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 on: push: - branches: [ develop ] # develop branch로 push 될 때 실행됩니다. + branches: [ "develop" ] + paths: + - umbba-api/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** env: S3_BUCKET_NAME: umbba-storage @@ -37,10 +42,10 @@ jobs: aws-region: ap-northeast-2 # 3) 환경변수 파일 생성 - - name: make application.properties 파일 생성 + - name: make application.yml 파일 생성 run: | # application.yml 파일 생성 - cd ./src/main/resources + cd ./umbba-notification/src/main/resources rm application.yaml touch ./application.yml @@ -51,14 +56,14 @@ jobs: # 생성된 파일 확인 cat ./application.yml + #################################### + # FCM secret key 폴더 생성 mkdir ./firebase cd ./firebase aws s3 cp --region ap-northeast-2 s3://${{ secrets.S3_BUCKET_NAME }}/json/umbba-fcm-firebase-adminsdk.json . - - cat umbba-fcm-firebase-adminsdk.json - + shell: bash # 이 워크플로우는 gradle build @@ -66,7 +71,7 @@ jobs: run: chmod +x gradlew - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) - run: ./gradlew build -x test + run: ./gradlew umbba-api:bootJar -x test # 디렉토리 생성 - name: Make Directory @@ -74,19 +79,15 @@ jobs: # Jar 파일 복사 - name: Copy Jar - run: cp ./build/libs/*.jar ./deploy + run: cp ./umbba-api/build/libs/*.jar ./deploy # run: cp -r src/main/* ./deploy - # appspec.yml 파일 복사 - - name: Copy appspec.yml - run: cp appspec.yml ./deploy - - # script files 복사 - - name: Copy script - run: cp ./scripts/*.sh ./deploy + # appspec.yml, script files 파일 복사 + - name: Copy files + run: cp ./scripts/umbba-api/* ./deploy - name: Make zip file - run: zip -r ./umbba_server.zip ./deploy + run: zip -r ./umbba-api.zip ./deploy shell: bash - name: Configure AWS credentials @@ -97,7 +98,7 @@ jobs: aws-region: ap-northeast-2 - name: Upload to S3 - run: aws s3 cp --region ap-northeast-2 ./umbba_server.zip s3://$S3_BUCKET_NAME/ + run: aws s3 cp --region ap-northeast-2 ./umbba-api.zip s3://$S3_BUCKET_NAME/ # Deploy - name: Deploy @@ -107,7 +108,7 @@ jobs: run: aws deploy create-deployment --application-name umbba-server-codedeploy - --deployment-group-name umbba-server-codedeploy-group + --deployment-group-name umbba-api-server-codedeploy-group --file-exists-behavior OVERWRITE - --s3-location bucket=umbba-storage,bundleType=zip,key=umbba_server.zip + --s3-location bucket=umbba-storage,bundleType=zip,key=umbba-api.zip --region ap-northeast-2 diff --git a/.github/workflows/gradle.yml b/.github/workflows/api-CI.yml similarity index 84% rename from .github/workflows/gradle.yml rename to .github/workflows/api-CI.yml index 55e3ffeb..d8bd96ec 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/api-CI.yml @@ -11,13 +11,23 @@ # 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: Umbba-Server CI +name: Umbba API Server CI on: push: branches: [ "develop" ] + paths: + - umbba-api/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** pull_request: branches: [ "develop" ] + paths: + - umbba-api/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** permissions: contents: read @@ -41,10 +51,10 @@ jobs: distribution: 'temurin' # 3) 환경변수 파일 생성 - - name: make application.properties 파일 생성 + - name: make application.yml 파일 생성 run: | ## create application.yml - cd ./src/main/resources + cd ./umbba-api/src/main/resources rm application.yaml # application.yml 파일 생성 @@ -55,6 +65,7 @@ jobs: # application.yml 파일 확인 cat ./application.yml + shell: bash # 이 워크플로우는 gradle build @@ -62,4 +73,4 @@ jobs: run: chmod +x gradlew - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) - run: ./gradlew build -x test + run: ./gradlew umbba-api:bootJar -x test diff --git a/.github/workflows/notification-CD.yml b/.github/workflows/notification-CD.yml new file mode 100644 index 00000000..564ef527 --- /dev/null +++ b/.github/workflows/notification-CD.yml @@ -0,0 +1,114 @@ +# 워크플로우의 이름 지정 +name: Umbba Notification Server CD + +# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 +on: + push: + branches: [ "develop" ] + paths: + - umbba-notification/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + +env: + S3_BUCKET_NAME: umbba-storage + +jobs: + build: + name: Code deployment + + # 실행 환경 + runs-on: ubuntu-latest + + steps: + + # 1) 워크플로우 실행 전 기본적으로 체크아웃 필요 + - name: checkout + uses: actions/checkout@v3 + + # 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} + aws-region: ap-northeast-2 + + # 3) 환경변수 파일 생성 + - name: make application.yml 파일 생성 + run: | + # application.yml 파일 생성 + cd ./umbba-notification/src/main/resources + rm application.yaml + + touch ./application.yml + + # GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기 + echo "${{ secrets.UMBBA_SECRET }}" >> ./application.yml + + # 생성된 파일 확인 + cat ./application.yml + + #################################### + + # FCM secret key 폴더 생성 + mkdir ./firebase + cd ./firebase + + aws s3 cp --region ap-northeast-2 s3://${{ secrets.S3_BUCKET_NAME }}/json/umbba-fcm-firebase-adminsdk.json . + + shell: bash + + # 이 워크플로우는 gradle build + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) + run: ./gradlew umbba-notification:bootJar -x test + + # 디렉토리 생성 + - name: Make Directory + run: mkdir -p deploy + + # Jar 파일 복사 + - name: Copy Jar + run: cp ./umbba-notification/build/libs/*.jar ./deploy + # run: cp -r src/main/* ./deploy + + # appspec.yml, script files 파일 복사 + - name: Copy files + run: cp ./scripts/umbba-notification/* ./deploy + + - name: Make zip file + run: zip -r ./umbba-notification.zip ./deploy + shell: bash + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} + aws-region: ap-northeast-2 + + - name: Upload to S3 + run: aws s3 cp --region ap-northeast-2 ./umbba-notification.zip s3://$S3_BUCKET_NAME/ + + # Deploy + - name: Deploy + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }} + run: + aws deploy create-deployment + --application-name umbba-server-codedeploy + --deployment-group-name umbba-notification-server-codedeploy-group + --file-exists-behavior OVERWRITE + --s3-location bucket=umbba-storage,bundleType=zip,key=umbba-notification.zip + --region ap-northeast-2 diff --git a/.github/workflows/notification-CI.yml b/.github/workflows/notification-CI.yml new file mode 100644 index 00000000..9db9d55d --- /dev/null +++ b/.github/workflows/notification-CI.yml @@ -0,0 +1,76 @@ +# 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 +# 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: Umbba Notification Server CI + +on: + push: + branches: [ "develop" ] + paths: + - umbba-notification/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + pull_request: + branches: [ "develop" ] + paths: + - umbba-notification/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + + # 1) 워크플로우 실행 전 기본적으로 체크아웃 필요 + - name: checkout + uses: actions/checkout@v3 + + # 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + # 3) 환경변수 파일 생성 + - name: make application.yml 파일 생성 + run: | + ## create application.yml + cd ./umbba-api/src/main/resources + rm application.yaml + + # application.yml 파일 생성 + touch ./application.yml + + # GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기 + echo "${{ secrets.UMBBA_SECRET }}" >> ./application.yml + + # application.yml 파일 확인 + cat ./application.yml + + shell: bash + + # 이 워크플로우는 gradle build + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) + run: ./gradlew umbba-notification:bootJar -x test diff --git a/build.gradle b/build.gradle index fb026a23..0252238c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,76 +1,50 @@ -plugins { - id 'java' - id 'org.springframework.boot' version '2.7.13' - id 'io.spring.dependency-management' version '1.0.15.RELEASE' -} - -group = 'sopt.org' -version = '0.0.1-SNAPSHOT' - -java { - sourceCompatibility = '11' -} +buildscript { + ext { + springBootVersion = "2.7.14" + } -configurations { - compileOnly { - extendsFrom annotationProcessor + repositories { + mavenCentral() } -} -repositories { - mavenCentral() + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + } } -dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-validation' - testImplementation 'org.projectlombok:lombok:1.18.22' - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' - testAnnotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - - // Health Check - implementation 'org.springframework.boot:spring-boot-starter-actuator' - - // JPA & Database - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'mysql:mysql-connector-java:8.0.32' +subprojects { + group = "sopt.org.umbba" + version = '0.0.1-SNAPSHOT' + apply plugin: "java-library" + apply plugin: "org.springframework.boot" + apply plugin: "io.spring.dependency-management" - //JSON - implementation 'com.googlecode.json-simple:json-simple:1.1.1' + sourceCompatibility = "11" - // Slack Webhook - implementation 'com.slack.api:slack-api-client:1.28.0' - implementation 'com.google.code.gson:gson:2.10.1' - implementation 'com.squareup.okhttp3:okhttp:4.10.0' - implementation 'com.slack.api:slack-app-backend:1.28.0' - implementation 'com.slack.api:slack-api-model:1.28.0' - - // JWT - implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2' - implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2' - implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2' - - // Spring Security - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.springframework.security:spring-security-test' - - // Redis - implementation 'org.springframework.boot:spring-boot-starter-data-redis' + repositories { + mavenCentral() + } - // Social Login - implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:3.1.7' + configurations { + compileOnly { + extendsFrom annotationProcessor + } + } - // random String - implementation 'org.apache.commons:commons-lang3' + dependencies { + implementation "org.springframework.boot:spring-boot-starter-validation" + testImplementation "org.springframework.boot:spring-boot-starter-test" - // Firebase - implementation 'com.google.firebase:firebase-admin:9.1.1' + // lombok + compileOnly "org.projectlombok:lombok" + annotationProcessor "org.projectlombok:lombok" + // Health Check + implementation 'org.springframework.boot:spring-boot-starter-actuator' -} + } -tasks.named('test') { - useJUnitPlatform() -} + test { + useJUnitPlatform() + } +} \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100644 index 8b22c10e..00000000 --- a/scripts/deploy.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash -BUILD_PATH=$(ls /home/ubuntu/app/umbbaServer-0.0.1-SNAPSHOT.jar) -JAR_NAME=$(basename $BUILD_PATH) -echo "> build 파일명: $JAR_NAME" - -echo "> build 파일 복사" -DEPLOY_PATH=/home/ubuntu/app/nonstop/jar/ -cp $BUILD_PATH $DEPLOY_PATH - -echo "> 현재 구동중인 Set 확인" -CURRENT_PROFILE=$(curl -s http://localhost/profile) -echo "> $CURRENT_PROFILE" - -# 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음 -if [ $CURRENT_PROFILE == set1 ] -then - IDLE_PROFILE=set2 - IDLE_PORT=8082 -elif [ $CURRENT_PROFILE == set2 ] -then - IDLE_PROFILE=set1 - IDLE_PORT=8081 -else - echo "> 일치하는 Profile이 없습니다. Profile: $CURRENT_PROFILE" - echo "> set1을 할당합니다. IDLE_PROFILE: set1" - IDLE_PROFILE=set1 - IDLE_PORT=8081 -fi - -echo "> application.jar 교체" -IDLE_APPLICATION=$IDLE_PROFILE-Team-Umbba.jar -IDLE_APPLICATION_PATH=$DEPLOY_PATH$IDLE_APPLICATION - -ln -Tfs $DEPLOY_PATH$JAR_NAME $IDLE_APPLICATION_PATH - -echo "> $IDLE_PROFILE 에서 구동중인 애플리케이션 pid 확인" -IDLE_PID=$(pgrep -f $IDLE_APPLICATION) - -if [ -z $IDLE_PID ] -then - echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." -else - echo "> kill -15 $IDLE_PID" - kill -15 $IDLE_PID - echo wait 10 seconds... - sleep 10 - echo wait complete! - -fi - -echo "> $IDLE_PROFILE 배포" -nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 & - -echo "> $IDLE_PROFILE 10초 후 Health check 시작" -echo "> curl -s http://localhost:$IDLE_PORT/health " -sleep 10 - -for retry_count in {1..10} -do - response=$(curl -s http://localhost:$IDLE_PORT/actuator/health) - up_count=$(echo $response | grep 'UP' | wc -l) - - if [ $up_count -ge 1 ] - then # $up_count >= 1 ("UP" 문자열이 있는지 검증) - echo "> Health check 성공" - break - else - echo "> Health check의 응답을 알 수 없거나 혹은 status가 UP이 아닙니다." - echo "> Health check: ${response}" - fi - - if [ $retry_count -eq 10 ] - then - echo "> Health check 실패. " - echo "> Nginx에 연결하지 않고 배포를 종료합니다." - exit 1 - fi - - echo "> Health check 연결 실패. 재시도..." - sleep 10 -done - -echo "> 스위칭" -sleep 10 -/home/ubuntu/app/nonstop/switch.sh diff --git a/scripts/umbba-api/appspec.yml b/scripts/umbba-api/appspec.yml new file mode 100644 index 00000000..0386a216 --- /dev/null +++ b/scripts/umbba-api/appspec.yml @@ -0,0 +1,22 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/api-server + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + AfterInstall: + - location: deploy.sh + timeout: 180 + runas: ubuntu + - location: switch.sh + timeout: 180 + runas: ubuntu \ No newline at end of file diff --git a/scripts/umbba-api/deploy.sh b/scripts/umbba-api/deploy.sh new file mode 100644 index 00000000..b1d1a0ae --- /dev/null +++ b/scripts/umbba-api/deploy.sh @@ -0,0 +1,81 @@ +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +BUILD_PATH=$(ls /home/ubuntu/api-server/umbba-api-0.0.1-SNAPSHOT.jar) +JAR_NAME=$(basename $BUILD_PATH) +echo "[$NOW_TIME] build 파일명: $JAR_NAME" + +echo "[$NOW_TIME] build 파일 복사" +DEPLOY_PATH=/home/ubuntu/api-server/nonstop/jar/ +cp $BUILD_PATH $DEPLOY_PATH + +echo "[$NOW_TIME] 현재 구동중인 Set 확인" +CURRENT_PROFILE=$(curl -s http://localhost/profile) +echo "[$NOW_TIME] $CURRENT_PROFILE" + +# 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음 +if [ $CURRENT_PROFILE == set1 ] +then + IDLE_PROFILE=set2 + IDLE_PORT=8082 +elif [ $CURRENT_PROFILE == set2 ] +then + IDLE_PROFILE=set1 + IDLE_PORT=8081 +else + echo "[$NOW_TIME] 일치하는 Profile이 없습니다. Profile: $CURRENT_PROFILE" + echo "[$NOW_TIME] set1을 할당합니다. IDLE_PROFILE: set1" + IDLE_PROFILE=set1 + IDLE_PORT=8081 +fi + +echo "[$NOW_TIME] application.jar 교체" +IDLE_APPLICATION=$IDLE_PROFILE-Umbba-API.jar +IDLE_APPLICATION_PATH=$DEPLOY_PATH$IDLE_APPLICATION + +ln -Tfs $DEPLOY_PATH$JAR_NAME $IDLE_APPLICATION_PATH + +echo "[$NOW_TIME] $IDLE_PROFILE 에서 구동중인 애플리케이션 pid 확인" +IDLE_PID=$(pgrep -f $IDLE_APPLICATION) + +if [ -z $IDLE_PID ] +then + echo "[$NOW_TIME] 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." +else + echo "[$NOW_TIME] kill -15 $IDLE_PID" + kill -15 $IDLE_PID + sleep 10 +fi + +echo "[$NOW_TIME] $IDLE_PROFILE 배포" +nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/api-server/deploy.log 2>/home/ubuntu/api-server/deploy_err.log & + +################################################################## + +echo "[$NOW_TIME] $IDLE_PROFILE 10초 후 Health check 시작" +echo "[$NOW_TIME] curl -s http://localhost:$IDLE_PORT/health " +sleep 10 + +for retry_count in {1..10} +do + response=$(curl -s http://localhost:$IDLE_PORT/actuator/health) + up_count=$(echo $response | grep 'UP' | wc -l) + + if [ $up_count -ge 1 ] + then # $up_count >= 1 ("UP" 문자열이 있는지 검증) + echo "[$NOW_TIME] Health check 성공" + break + else + echo "[$NOW_TIME] Health check의 응답을 알 수 없거나 혹은 status가 UP이 아닙니다." + echo "[$NOW_TIME] Health check: ${response}" + fi + + if [ $retry_count -eq 10 ] + then + echo "[$NOW_TIME] Health check 실패. " + echo "[$NOW_TIME] Nginx에 연결하지 않고 배포를 종료합니다." + exit 1 + fi + + echo "[$NOW_TIME] Health check 연결 실패. 재시도..." + sleep 10 +done \ No newline at end of file diff --git a/scripts/umbba-api/switch.sh b/scripts/umbba-api/switch.sh new file mode 100644 index 00000000..31150cdd --- /dev/null +++ b/scripts/umbba-api/switch.sh @@ -0,0 +1,30 @@ +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +echo "[$NOW_TIME] 스위칭" +sleep 10 +#!/bin/bash +echo "[$NOW_TIME] 현재 구동중인 Port 확인" +CURRENT_PROFILE=$(curl -s http://localhost/profile) + +# 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음 +if [ $CURRENT_PROFILE == set1 ] +then + IDLE_PORT=8082 +elif [ $CURRENT_PROFILE == set2 ] +then + IDLE_PORT=8081 +else + echo "[$NOW_TIME] 일치하는 Profile이 없습니다. Profile: $CURRENT_PROFILE" + echo "[$NOW_TIME] 8081을 할당합니다." + IDLE_PORT=8081 +fi + +echo "[$NOW_TIME] 전환할 Port: $IDLE_PORT" +echo "[$NOW_TIME] Port 전환" +echo "[$NOW_TIME] set \$service_url http://127.0.0.1:${IDLE_PORT};" | sudo tee /etc/nginx/conf.d/service-url.inc + +PROXY_PORT=$(curl -s http://localhost/profile) +echo "[$NOW_TIME] Nginx Current Proxy Port: $PROXY_PORT" + +echo "[$NOW_TIME] Nginx Reload" +sudo service nginx reload \ No newline at end of file diff --git a/appspec.yml b/scripts/umbba-notification/appspec.yml similarity index 69% rename from appspec.yml rename to scripts/umbba-notification/appspec.yml index 44c46f6a..4a0bf554 100644 --- a/appspec.yml +++ b/scripts/umbba-notification/appspec.yml @@ -3,7 +3,7 @@ os: linux files: - source: / - destination: /home/ubuntu/app + destination: /home/ubuntu/notification-server overwrite: yes permissions: @@ -15,5 +15,5 @@ permissions: hooks: AfterInstall: - location: deploy.sh - timeout: 60 - runas: ubuntu + timeout: 180 + runas: ubuntu \ No newline at end of file diff --git a/scripts/umbba-notification/deploy.sh b/scripts/umbba-notification/deploy.sh new file mode 100644 index 00000000..0c27634a --- /dev/null +++ b/scripts/umbba-notification/deploy.sh @@ -0,0 +1,14 @@ +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +BUILD_PATH=/home/ubuntu/notification-server/umbba-notification-0.0.1-SNAPSHOT.jar +TARGET_PORT=8083 +TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') + +if [ ! -z ${TARGET_PID} ]; then + echo "[$NOW_TIME] Kill WAS running at ${TARGET_PORT}." >> /home/ubuntu/notification-server/deploy.log + sudo kill -15 ${TARGET_PID} +fi + +nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=notification $BUILD_PATH >> /home/ubuntu/notification-server/deploy.log 2>/home/ubuntu/notification-server/deploy_err.log & +echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/notification-server/deploy.log +exit 0 \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 05a1b1b2..12ede70b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,8 @@ rootProject.name = 'umbbaServer' + +include 'umbba-common' +include 'umbba-domain' +include 'umbba-external' +include 'umbba-api' +include 'umbba-notification' + diff --git a/src/main/java/sopt/org/umbbaServer/UmbbaServerApplication.java b/src/main/java/sopt/org/umbbaServer/UmbbaServerApplication.java deleted file mode 100644 index 57184e14..00000000 --- a/src/main/java/sopt/org/umbbaServer/UmbbaServerApplication.java +++ /dev/null @@ -1,22 +0,0 @@ -package sopt.org.umbbaServer; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; -import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import org.springframework.scheduling.annotation.EnableScheduling; - -@EnableJpaAuditing -@EnableScheduling -@SpringBootApplication(exclude = { UserDetailsServiceAutoConfiguration.class }) -@EnableFeignClients -public class UmbbaServerApplication { - - public static void main(String[] args) { - - SpringApplication.run(UmbbaServerApplication.class, args); - - } - -} diff --git a/src/test/java/sopt/org/umbbaServer/UmbbaServerApplicationTests.java b/src/test/java/sopt/org/umbbaServer/UmbbaServerApplicationTests.java deleted file mode 100644 index 580f0f43..00000000 --- a/src/test/java/sopt/org/umbbaServer/UmbbaServerApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package sopt.org.umbbaServer; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class UmbbaServerApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/umbba-api/build.gradle b/umbba-api/build.gradle new file mode 100644 index 00000000..fe36cb1d --- /dev/null +++ b/umbba-api/build.gradle @@ -0,0 +1,39 @@ +jar { enabled = false } + +dependencies { + implementation project(':umbba-common') + implementation project(':umbba-domain') + implementation project(':umbba-external') + + // spring mvc + implementation 'org.springframework.boot:spring-boot-starter-web' + + // swagger +// implementation 'org.springdoc:springdoc-openapi-ui:1.5.4' + + // SQS + implementation "org.springframework.cloud:spring-cloud-aws-messaging:2.2.6.RELEASE" + + // Spring Security + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.security:spring-security-test' + + // jwt + implementation group: "io.jsonwebtoken", name: "jjwt-api", version: "0.11.2" + implementation group: "io.jsonwebtoken", name: "jjwt-impl", version: "0.11.2" + implementation group: "io.jsonwebtoken", name: "jjwt-jackson", version: "0.11.2" + + // random String + implementation 'org.apache.commons:commons-lang3' + + // for FeignException + implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:3.1.7' + + // redis + implementation "org.springframework.boot:spring-boot-starter-data-redis" + implementation "org.springframework.session:spring-session-data-redis" + + // s3 +// implementation "org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE" +} + diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/ApiApplication.java b/umbba-api/src/main/java/sopt/org/umbba/api/ApiApplication.java new file mode 100644 index 00000000..97943392 --- /dev/null +++ b/umbba-api/src/main/java/sopt/org/umbba/api/ApiApplication.java @@ -0,0 +1,25 @@ +package sopt.org.umbba.api; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; +import org.springframework.cloud.openfeign.EnableFeignClients; +import sopt.org.umbba.common.UmbbaCommonRoot; +import sopt.org.umbba.domain.UmbbaDomainRoot; +import sopt.org.umbba.external.UmbbaExternalRoot; + +@SpringBootApplication(scanBasePackageClasses = { + UmbbaCommonRoot.class, + UmbbaDomainRoot.class, + UmbbaExternalRoot.class, + ApiApplication.class +}, exclude = { UserDetailsServiceAutoConfiguration.class }) +@EnableFeignClients(basePackageClasses = UmbbaExternalRoot.class) +public class ApiApplication { + + public static void main(String[] args) { + SpringApplication.run(ApiApplication.class, args); + } + +} diff --git a/src/main/java/sopt/org/umbbaServer/global/config/SecurityConfig.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/SecurityConfig.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/global/config/SecurityConfig.java rename to umbba-api/src/main/java/sopt/org/umbba/api/config/SecurityConfig.java index 8e32578f..76254bd2 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/SecurityConfig.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/SecurityConfig.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.config; +package sopt.org.umbba.api.config; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; @@ -8,8 +8,8 @@ import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import sopt.org.umbbaServer.global.config.auth.CustomJwtAuthenticationEntryPoint; -import sopt.org.umbbaServer.global.config.auth.JwtAuthenticationFilter; +import sopt.org.umbba.api.config.auth.CustomJwtAuthenticationEntryPoint; +import sopt.org.umbba.api.config.auth.JwtAuthenticationFilter; @Configuration @EnableWebSecurity diff --git a/src/main/java/sopt/org/umbbaServer/global/config/auth/CustomJwtAuthenticationEntryPoint.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/auth/CustomJwtAuthenticationEntryPoint.java similarity index 87% rename from src/main/java/sopt/org/umbbaServer/global/config/auth/CustomJwtAuthenticationEntryPoint.java rename to umbba-api/src/main/java/sopt/org/umbba/api/config/auth/CustomJwtAuthenticationEntryPoint.java index 530f1dce..39a23c4c 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/auth/CustomJwtAuthenticationEntryPoint.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/auth/CustomJwtAuthenticationEntryPoint.java @@ -1,12 +1,12 @@ -package sopt.org.umbbaServer.global.config.auth; +package sopt.org.umbba.api.config.auth; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.http.MediaType; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; -import sopt.org.umbbaServer.global.common.dto.ApiResponse; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.dto.ApiResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/src/main/java/sopt/org/umbbaServer/global/config/auth/JwtAuthenticationFilter.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/auth/JwtAuthenticationFilter.java similarity index 92% rename from src/main/java/sopt/org/umbbaServer/global/config/auth/JwtAuthenticationFilter.java rename to umbba-api/src/main/java/sopt/org/umbba/api/config/auth/JwtAuthenticationFilter.java index 4c77d09b..99951680 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/auth/JwtAuthenticationFilter.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/auth/JwtAuthenticationFilter.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.config.auth; +package sopt.org.umbba.api.config.auth; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -8,8 +8,8 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import org.springframework.web.filter.OncePerRequestFilter; -import sopt.org.umbbaServer.global.config.jwt.JwtValidationType; -import sopt.org.umbbaServer.global.config.jwt.JwtProvider; +import sopt.org.umbba.api.config.jwt.JwtProvider; +import sopt.org.umbba.api.config.jwt.JwtValidationType; import javax.servlet.FilterChain; import javax.servlet.ServletException; diff --git a/src/main/java/sopt/org/umbbaServer/global/config/auth/UserAuthentication.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/auth/UserAuthentication.java similarity index 89% rename from src/main/java/sopt/org/umbbaServer/global/config/auth/UserAuthentication.java rename to umbba-api/src/main/java/sopt/org/umbba/api/config/auth/UserAuthentication.java index 75ba55d6..f0f7083c 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/auth/UserAuthentication.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/auth/UserAuthentication.java @@ -1,5 +1,4 @@ -package sopt.org.umbbaServer.global.config.auth; - +package sopt.org.umbba.api.config.auth; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.GrantedAuthority; diff --git a/src/main/java/sopt/org/umbbaServer/global/config/jwt/JwtProvider.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/JwtProvider.java similarity index 94% rename from src/main/java/sopt/org/umbbaServer/global/config/jwt/JwtProvider.java rename to umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/JwtProvider.java index ea2dac14..77482664 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/jwt/JwtProvider.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/JwtProvider.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.config.jwt; +package sopt.org.umbba.api.config.jwt; import io.jsonwebtoken.*; @@ -8,10 +8,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; -import sopt.org.umbbaServer.global.config.jwt.redis.RefreshToken; -import sopt.org.umbbaServer.global.config.jwt.redis.TokenRepository; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.domain.domain.redis.RefreshToken; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; import javax.annotation.PostConstruct; import javax.crypto.SecretKey; @@ -19,7 +18,6 @@ import java.security.Principal; import java.util.Base64; import java.util.Date; -import java.util.UUID; import static java.util.Objects.isNull; diff --git a/src/main/java/sopt/org/umbbaServer/global/config/jwt/JwtValidationType.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/JwtValidationType.java similarity index 92% rename from src/main/java/sopt/org/umbbaServer/global/config/jwt/JwtValidationType.java rename to umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/JwtValidationType.java index 54c5d739..dd7cc444 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/jwt/JwtValidationType.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/JwtValidationType.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.config.jwt; +package sopt.org.umbba.api.config.jwt; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/sopt/org/umbbaServer/global/config/jwt/TokenDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/TokenDto.java similarity index 92% rename from src/main/java/sopt/org/umbbaServer/global/config/jwt/TokenDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/TokenDto.java index e41cadd3..4c456b26 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/jwt/TokenDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/TokenDto.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.config.jwt; +package sopt.org.umbba.api.config.jwt; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/global/config/jwt/redis/TokenRepository.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/TokenRepository.java similarity index 64% rename from src/main/java/sopt/org/umbbaServer/global/config/jwt/redis/TokenRepository.java rename to umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/TokenRepository.java index c37664f0..4de694a1 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/jwt/redis/TokenRepository.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/jwt/TokenRepository.java @@ -1,6 +1,7 @@ -package sopt.org.umbbaServer.global.config.jwt.redis; +package sopt.org.umbba.api.config.jwt; import org.springframework.data.repository.CrudRepository; +import sopt.org.umbba.domain.domain.redis.RefreshToken; //Redis에 저장해주는 역할 public interface TokenRepository extends CrudRepository { diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/config/sqs/SqsConfig.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/sqs/SqsConfig.java new file mode 100644 index 00000000..adc5d50a --- /dev/null +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/sqs/SqsConfig.java @@ -0,0 +1,33 @@ +package sopt.org.umbba.api.config.sqs; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.sqs.AmazonSQSAsync; +import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class SqsConfig { + + @Value("${cloud.aws.credentials.accessKey}") + private String AWS_ACCESS_KEY; + + @Value("${cloud.aws.credentials.secretKey}") + private String AWS_SECRET_KEY; + + @Value("${cloud.aws.region.static}") + private String AWS_REGION; + + @Primary + @Bean + public AmazonSQSAsync amazonSQSAsync() { + BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY); + return AmazonSQSAsyncClientBuilder.standard() + .withRegion(AWS_REGION) + .withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials)) + .build(); + } +} diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/config/sqs/producer/SqsProducer.java b/umbba-api/src/main/java/sopt/org/umbba/api/config/sqs/producer/SqsProducer.java new file mode 100644 index 00000000..5c8b42df --- /dev/null +++ b/umbba-api/src/main/java/sopt/org/umbba/api/config/sqs/producer/SqsProducer.java @@ -0,0 +1,80 @@ +package sopt.org.umbba.api.config.sqs.producer; + +import com.amazonaws.services.sqs.AmazonSQS; +import com.amazonaws.services.sqs.model.MessageAttributeValue; +import com.amazonaws.services.sqs.model.SendMessageRequest; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import sopt.org.umbba.common.sqs.MessageType; +import sopt.org.umbba.common.sqs.MessageUtils; +import sopt.org.umbba.common.sqs.dto.MessageDto; + +import java.util.Map; +import java.util.UUID; + +/** + * 큐에 메시지를 보내는 역할: API 서버에서 이벤트가 발생할 떄 푸시알림 전송 + * -> 처음 SQS 대기열 생성에서 설정해둔 사항이 여기서 적용 (지연시간, 메시지 수신 대기 등) + * + * 1. 처리할 작업 메시지를 SQS에 등록 + * 2. 큐에서 메시지를 소비(consume)하는 것을 실패한 경우, DLQ로 전송 + * + * TODO 기존에 푸시알림을 파이어베이스로 보내기 위해 호출했던 함수를 SQS Producer로 대체 + */ +@Slf4j +@Component +public class SqsProducer { + + @Value("${cloud.aws.sqs.notification.url}") + private String NOTIFICATION_URL; + + private static final String GROUP_ID = "sqs"; + private final ObjectMapper objectMapper; + private final AmazonSQS amazonSqs; + private static final String SQS_QUEUE_REQUEST_LOG_MESSAGE = "====> [SQS Queue Request] : %s "; + + public SqsProducer(ObjectMapper objectMapper, AmazonSQS amazonSqs) { + this.objectMapper = objectMapper; + this.amazonSqs = amazonSqs; + } + + + public void produce(MessageDto message) { + try { + SendMessageRequest request = new SendMessageRequest(NOTIFICATION_URL, + objectMapper.writeValueAsString(message)) +// .withMessageGroupId(GROUP_ID) +// .withMessageDeduplicationId(UUID.randomUUID().toString()) // TODO UUID Random String으로 변경 + .withMessageAttributes(createMessageAttributes(message.getType())); + + amazonSqs.sendMessage(request); + log.info(MessageUtils.generate(SQS_QUEUE_REQUEST_LOG_MESSAGE, request)); + + } catch (JsonProcessingException e) { + log.error(e.getMessage(), e); + } + } + + private Map createMessageAttributes(String type) { + + return Map.of(MessageType.MESSAGE_TYPE_HEADER, new MessageAttributeValue() + .withDataType("String") + .withStringValue(type)); + } + + + /* Queue에 단일 메시지를 보내는 함수 -> SQS 실습에서 사용한 함수 + public SendResult sendMessage(String groupId, String message) { +// Message newMessage = MessageBuilder.withPayload(message).build(); + System.out.println("Sender: " + message); + return queueMessagingTemplate.send(to -> to + .queue(QUEUE_NAME) + .messageGroupId(groupId) + .messageDeduplicationId(groupId) + .payload(message)); + } + */ +} \ No newline at end of file diff --git a/src/main/java/sopt/org/umbbaServer/global/common/advice/ControllerExceptionAdvice.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/advice/ControllerExceptionAdvice.java similarity index 95% rename from src/main/java/sopt/org/umbbaServer/global/common/advice/ControllerExceptionAdvice.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/advice/ControllerExceptionAdvice.java index 84052527..3d2e05ee 100644 --- a/src/main/java/sopt/org/umbbaServer/global/common/advice/ControllerExceptionAdvice.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/advice/ControllerExceptionAdvice.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.common.advice; +package sopt.org.umbba.api.controller.advice; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -20,10 +20,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.util.NestedServletException; -import sopt.org.umbbaServer.global.common.dto.ApiResponse; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; -import sopt.org.umbbaServer.global.util.slack.SlackApi; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.dto.ApiResponse; +import sopt.org.umbba.common.exception.model.CustomException; import javax.servlet.http.HttpServletRequest; import javax.validation.UnexpectedTypeException; @@ -38,7 +37,7 @@ @RequiredArgsConstructor public class ControllerExceptionAdvice { - private final SlackApi slackApi; +// private final SlackApi slackApi; /** * 400 BAD_REQUEST @@ -93,15 +92,13 @@ protected ApiResponse handlerHttpRequestMethodNotSupportedException(fina } - - /** * 500 INTERNEL_SERVER // TODO 서비스 단에서 예외가 꼼꼼하게 처리된 상태에서 500 에러를 가장 마지막에 던지도록 처리 */ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(Exception.class) protected ApiResponse handleException(final Exception e, final HttpServletRequest request) throws IOException { - slackApi.sendAlert(e, request); +// slackApi.sendAlert(e, request); TODO ⭐️이 지점에서 SQS에 넣어야함 log.error("Unexpected exception occurred: {}", e.getMessage(), e); @@ -181,8 +178,6 @@ public ApiResponse handlerNullPointerException(final NullPointerExcep return ApiResponse.error(ErrorType.NULL_POINTER_ERROR, e); } - - /** * CUSTOM_ERROR */ diff --git a/src/main/java/sopt/org/umbbaServer/global/common/DemoController.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/health/DemoController.java similarity index 64% rename from src/main/java/sopt/org/umbbaServer/global/common/DemoController.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/health/DemoController.java index ffebea2a..c278c058 100644 --- a/src/main/java/sopt/org/umbbaServer/global/common/DemoController.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/health/DemoController.java @@ -1,17 +1,21 @@ -package sopt.org.umbbaServer.global.common; +package sopt.org.umbba.api.controller.health; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import sopt.org.umbbaServer.domain.qna.service.QnAService; -import sopt.org.umbbaServer.global.common.dto.ApiResponse; -import sopt.org.umbbaServer.global.exception.SuccessType; +import sopt.org.umbba.api.config.sqs.producer.SqsProducer; +import sopt.org.umbba.api.service.notification.NotificationService; +import sopt.org.umbba.api.service.qna.QnAService; +import sopt.org.umbba.common.exception.SuccessType; +import sopt.org.umbba.common.exception.dto.ApiResponse; +import sopt.org.umbba.common.sqs.dto.FCMPushRequestDto; @RestController @RequiredArgsConstructor public class DemoController { private final QnAService qnAService; + private final NotificationService notificationService; /** * 데모데이 테스트용 QnA리스트 세팅 API @@ -44,4 +48,12 @@ public ApiResponse demoQnA(@PathVariable final Long userId) { return ApiResponse.success(SuccessType.TEST_SUCCESS); } + @PatchMapping("/demo/qna/alarm/{userId}") + @ResponseStatus(HttpStatus.OK) + public ApiResponse qnaAnswerAlarm(@PathVariable final Long userId, @RequestBody String question) { + + notificationService.pushOpponentReply(question, userId); + return ApiResponse.success(SuccessType.TEST_SUCCESS); + } + } diff --git a/src/main/java/sopt/org/umbbaServer/global/util/ServerProfileController.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/health/ServerProfileController.java similarity index 92% rename from src/main/java/sopt/org/umbbaServer/global/util/ServerProfileController.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/health/ServerProfileController.java index bfbd1f77..b0f7dc9f 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/ServerProfileController.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/health/ServerProfileController.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.util; +package sopt.org.umbba.api.controller.health; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; diff --git a/src/main/java/sopt/org/umbbaServer/global/util/slack/SlackTestController.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/health/SlackTestController.java similarity index 84% rename from src/main/java/sopt/org/umbbaServer/global/util/slack/SlackTestController.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/health/SlackTestController.java index ffdb2507..516dc45b 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/slack/SlackTestController.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/health/SlackTestController.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.util.slack; +package sopt.org.umbba.api.controller.health; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; @@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import sopt.org.umbbaServer.global.common.dto.ApiResponse; +import sopt.org.umbba.common.exception.dto.ApiResponse; @Slf4j @RestController diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/ParentchildController.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/ParentchildController.java similarity index 66% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/ParentchildController.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/ParentchildController.java index 58e6e3d9..593963d9 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/ParentchildController.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/ParentchildController.java @@ -1,20 +1,21 @@ -package sopt.org.umbbaServer.domain.parentchild.controller; +package sopt.org.umbba.api.controller.parentchild; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.request.InviteCodeRequestDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.request.OnboardingInviteRequestDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.request.OnboardingReceiveRequestDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.response.InviteResultResponseDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.response.OnboardingInviteResponseDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.response.OnboardingReceiveResponseDto; -import sopt.org.umbbaServer.domain.parentchild.service.ParentchildService; -import sopt.org.umbbaServer.domain.qna.service.QnAService; -import sopt.org.umbbaServer.global.common.dto.ApiResponse; -import sopt.org.umbbaServer.global.config.jwt.JwtProvider; -import sopt.org.umbbaServer.global.exception.SuccessType; +import sopt.org.umbba.api.config.jwt.JwtProvider; +import sopt.org.umbba.api.controller.parentchild.dto.request.InviteCodeRequestDto; +import sopt.org.umbba.api.controller.parentchild.dto.request.OnboardingInviteRequestDto; +import sopt.org.umbba.api.controller.parentchild.dto.request.OnboardingReceiveRequestDto; +import sopt.org.umbba.api.controller.parentchild.dto.response.InviteResultResponseDto; +import sopt.org.umbba.api.controller.parentchild.dto.response.OnboardingInviteResponseDto; +import sopt.org.umbba.api.controller.parentchild.dto.response.OnboardingReceiveResponseDto; +import sopt.org.umbba.api.service.parentchild.ParentchildService; +import sopt.org.umbba.api.service.qna.QnAService; +import sopt.org.umbba.common.exception.SuccessType; +import sopt.org.umbba.common.exception.dto.ApiResponse; + import javax.validation.Valid; import java.security.Principal; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/InviteCodeRequestDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/InviteCodeRequestDto.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/InviteCodeRequestDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/InviteCodeRequestDto.java index 485786f7..826589af 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/InviteCodeRequestDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/InviteCodeRequestDto.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.parentchild.controller.dto.request; +package sopt.org.umbba.api.controller.parentchild.dto.request; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/OnboardingInviteRequestDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/OnboardingInviteRequestDto.java similarity index 87% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/OnboardingInviteRequestDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/OnboardingInviteRequestDto.java index 243bcb8c..82d8ff3e 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/OnboardingInviteRequestDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/OnboardingInviteRequestDto.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.parentchild.controller.dto.request; +package sopt.org.umbba.api.controller.parentchild.dto.request; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; @@ -8,7 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto; +import sopt.org.umbba.api.controller.user.dto.request.UserInfoDto; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/OnboardingReceiveRequestDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/OnboardingReceiveRequestDto.java similarity index 81% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/OnboardingReceiveRequestDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/OnboardingReceiveRequestDto.java index 15f99d24..7eb6d0fa 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/request/OnboardingReceiveRequestDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/request/OnboardingReceiveRequestDto.java @@ -1,11 +1,11 @@ -package sopt.org.umbbaServer.domain.parentchild.controller.dto.request; +package sopt.org.umbba.api.controller.parentchild.dto.request; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto; +import sopt.org.umbba.api.controller.user.dto.request.UserInfoDto; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/InviteResultResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/InviteResultResponseDto.java similarity index 82% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/InviteResultResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/InviteResultResponseDto.java index 5007d36e..60b5cbf2 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/InviteResultResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/InviteResultResponseDto.java @@ -1,14 +1,13 @@ -package sopt.org.umbbaServer.domain.parentchild.controller.dto.response; +package sopt.org.umbba.api.controller.parentchild.dto.response; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Builder; import lombok.Getter; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto; -import sopt.org.umbbaServer.domain.user.model.User; +import sopt.org.umbba.api.controller.user.dto.request.UserInfoDto; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; +import sopt.org.umbba.domain.domain.user.User; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/OnboardingInviteResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/OnboardingInviteResponseDto.java similarity index 79% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/OnboardingInviteResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/OnboardingInviteResponseDto.java index c8fa6b37..bce5d63f 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/OnboardingInviteResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/OnboardingInviteResponseDto.java @@ -1,13 +1,13 @@ -package sopt.org.umbbaServer.domain.parentchild.controller.dto.response; +package sopt.org.umbba.api.controller.parentchild.dto.response; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Builder; import lombok.Getter; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto; -import sopt.org.umbbaServer.domain.user.model.User; +import sopt.org.umbba.api.controller.user.dto.request.UserInfoDto; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; +import sopt.org.umbba.domain.domain.user.User; import java.time.LocalTime; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/OnboardingReceiveResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/OnboardingReceiveResponseDto.java similarity index 78% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/OnboardingReceiveResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/OnboardingReceiveResponseDto.java index 91c52cf2..141192ab 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/dto/response/OnboardingReceiveResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/parentchild/dto/response/OnboardingReceiveResponseDto.java @@ -1,13 +1,13 @@ -package sopt.org.umbbaServer.domain.parentchild.controller.dto.response; +package sopt.org.umbba.api.controller.parentchild.dto.response; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Builder; import lombok.Getter; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto; -import sopt.org.umbbaServer.domain.user.model.User; +import sopt.org.umbba.api.controller.user.dto.request.UserInfoDto; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; +import sopt.org.umbba.domain.domain.user.User; import java.time.LocalTime; import java.util.List; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/QnAController.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/QnAController.java similarity index 84% rename from src/main/java/sopt/org/umbbaServer/domain/qna/controller/QnAController.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/QnAController.java index c201a206..37c910ec 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/QnAController.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/QnAController.java @@ -1,14 +1,14 @@ -package sopt.org.umbbaServer.domain.qna.controller; +package sopt.org.umbba.api.controller.qna; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import sopt.org.umbbaServer.domain.qna.controller.dto.request.TodayAnswerRequestDto; -import sopt.org.umbbaServer.domain.qna.controller.dto.response.*; -import sopt.org.umbbaServer.domain.qna.service.QnAService; -import sopt.org.umbbaServer.global.common.dto.ApiResponse; -import sopt.org.umbbaServer.global.config.jwt.JwtProvider; -import sopt.org.umbbaServer.global.exception.SuccessType; +import sopt.org.umbba.api.config.jwt.JwtProvider; +import sopt.org.umbba.api.controller.qna.dto.request.TodayAnswerRequestDto; +import sopt.org.umbba.api.controller.qna.dto.response.*; +import sopt.org.umbba.api.service.qna.QnAService; +import sopt.org.umbba.common.exception.SuccessType; +import sopt.org.umbba.common.exception.dto.ApiResponse; import javax.validation.Valid; import java.security.Principal; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/request/TodayAnswerRequestDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/request/TodayAnswerRequestDto.java similarity index 90% rename from src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/request/TodayAnswerRequestDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/request/TodayAnswerRequestDto.java index f988ca22..36eecdf2 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/request/TodayAnswerRequestDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/request/TodayAnswerRequestDto.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.qna.controller.dto.request; +package sopt.org.umbba.api.controller.qna.dto.request; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/GetInvitationResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/GetInvitationResponseDto.java similarity index 96% rename from src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/GetInvitationResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/GetInvitationResponseDto.java index 7677d6ee..5c61e0da 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/GetInvitationResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/GetInvitationResponseDto.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.qna.controller.dto.response; +package sopt.org.umbba.api.controller.qna.dto.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/GetMainViewResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/GetMainViewResponseDto.java similarity index 85% rename from src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/GetMainViewResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/GetMainViewResponseDto.java index 858a09ec..bf00508a 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/GetMainViewResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/GetMainViewResponseDto.java @@ -1,10 +1,10 @@ -package sopt.org.umbbaServer.domain.qna.controller.dto.response; +package sopt.org.umbba.api.controller.qna.dto.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Builder; import lombok.Getter; -import sopt.org.umbbaServer.domain.qna.model.QnA; +import sopt.org.umbba.domain.domain.qna.QnA; @Getter @Builder diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/QnAListResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/QnAListResponseDto.java similarity index 84% rename from src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/QnAListResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/QnAListResponseDto.java index a5d65dd8..50931530 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/QnAListResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/QnAListResponseDto.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.qna.controller.dto.response; +package sopt.org.umbba.api.controller.qna.dto.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/SingleQnAResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/SingleQnAResponseDto.java similarity index 89% rename from src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/SingleQnAResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/SingleQnAResponseDto.java index 6e17205b..55372ff7 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/SingleQnAResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/SingleQnAResponseDto.java @@ -1,12 +1,12 @@ -package sopt.org.umbbaServer.domain.qna.controller.dto.response; +package sopt.org.umbba.api.controller.qna.dto.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Builder; import lombok.Getter; -import sopt.org.umbbaServer.domain.qna.model.QnA; -import sopt.org.umbbaServer.domain.qna.model.Question; -import sopt.org.umbbaServer.domain.user.model.User; +import sopt.org.umbba.domain.domain.qna.QnA; +import sopt.org.umbba.domain.domain.qna.Question; +import sopt.org.umbba.domain.domain.user.User; @Getter @Builder diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/TodayQnAResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/TodayQnAResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java index be1d374b..998d555b 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/TodayQnAResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java @@ -1,12 +1,12 @@ -package sopt.org.umbbaServer.domain.qna.controller.dto.response; +package sopt.org.umbba.api.controller.qna.dto.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Builder; import lombok.Getter; -import sopt.org.umbbaServer.domain.qna.model.QnA; -import sopt.org.umbbaServer.domain.qna.model.Question; -import sopt.org.umbbaServer.domain.user.model.User; +import sopt.org.umbba.domain.domain.qna.QnA; +import sopt.org.umbba.domain.domain.qna.Question; +import sopt.org.umbba.domain.domain.user.User; @Getter @Builder diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/controller/AuthController.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/AuthController.java similarity index 76% rename from src/main/java/sopt/org/umbbaServer/domain/user/controller/AuthController.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/user/AuthController.java index eb1110e8..2c9407fa 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/controller/AuthController.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/AuthController.java @@ -1,17 +1,17 @@ -package sopt.org.umbbaServer.domain.user.controller; +package sopt.org.umbba.api.controller.user; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import sopt.org.umbbaServer.domain.user.controller.dto.request.RefreshRequestDto; -import sopt.org.umbbaServer.domain.user.controller.dto.request.SocialLoginRequestDto; -import sopt.org.umbbaServer.domain.user.controller.dto.response.UserLoginResponseDto; -import sopt.org.umbbaServer.domain.user.service.AuthService; -import sopt.org.umbbaServer.domain.user.social.kakao.KakaoLoginService; -import sopt.org.umbbaServer.global.common.dto.ApiResponse; -import sopt.org.umbbaServer.global.config.jwt.JwtProvider; -import sopt.org.umbbaServer.global.config.jwt.TokenDto; -import sopt.org.umbbaServer.global.exception.SuccessType; +import sopt.org.umbba.api.config.jwt.JwtProvider; +import sopt.org.umbba.api.config.jwt.TokenDto; +import sopt.org.umbba.api.controller.user.dto.request.RefreshRequestDto; +import sopt.org.umbba.api.controller.user.dto.request.SocialLoginRequestDto; +import sopt.org.umbba.api.controller.user.dto.response.UserLoginResponseDto; +import sopt.org.umbba.api.service.user.AuthService; +import sopt.org.umbba.api.service.user.social.kakao.KakaoLoginService; +import sopt.org.umbba.common.exception.SuccessType; +import sopt.org.umbba.common.exception.dto.ApiResponse; import java.security.NoSuchAlgorithmException; import java.security.Principal; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/RefreshRequestDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/RefreshRequestDto.java similarity index 85% rename from src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/RefreshRequestDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/RefreshRequestDto.java index a0551ba5..525728fa 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/RefreshRequestDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/RefreshRequestDto.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.user.controller.dto.request; +package sopt.org.umbba.api.controller.user.dto.request; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/SocialLoginRequestDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/SocialLoginRequestDto.java similarity index 86% rename from src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/SocialLoginRequestDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/SocialLoginRequestDto.java index 5917fefa..c89ced53 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/SocialLoginRequestDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/SocialLoginRequestDto.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.user.controller.dto.request; +package sopt.org.umbba.api.controller.user.dto.request; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/UserInfoDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/UserInfoDto.java similarity index 89% rename from src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/UserInfoDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/UserInfoDto.java index b37a1115..9336b0b4 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/UserInfoDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/request/UserInfoDto.java @@ -1,10 +1,10 @@ -package sopt.org.umbbaServer.domain.user.controller.dto.request; +package sopt.org.umbba.api.controller.user.dto.request; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Builder; import lombok.Getter; -import sopt.org.umbbaServer.domain.user.model.User; +import sopt.org.umbba.domain.domain.user.User; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/response/UserLoginResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/response/UserLoginResponseDto.java similarity index 87% rename from src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/response/UserLoginResponseDto.java rename to umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/response/UserLoginResponseDto.java index 4aede703..015b8442 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/response/UserLoginResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/user/dto/response/UserLoginResponseDto.java @@ -1,12 +1,12 @@ -package sopt.org.umbbaServer.domain.user.controller.dto.response; +package sopt.org.umbba.api.controller.user.dto.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Builder; import lombok.Getter; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.domain.user.social.SocialPlatform; -import sopt.org.umbbaServer.global.config.jwt.TokenDto; +import sopt.org.umbba.api.config.jwt.TokenDto; +import sopt.org.umbba.domain.domain.user.SocialPlatform; +import sopt.org.umbba.domain.domain.user.User; @Getter @Builder diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/service/notification/NotificationService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/notification/NotificationService.java new file mode 100644 index 00000000..80c8c33e --- /dev/null +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/notification/NotificationService.java @@ -0,0 +1,50 @@ +package sopt.org.umbba.api.service.notification; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import sopt.org.umbba.api.config.sqs.producer.SqsProducer; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.common.sqs.dto.FCMPushRequestDto; +import sopt.org.umbba.common.sqs.dto.SlackDto; +import sopt.org.umbba.domain.domain.user.User; +import sopt.org.umbba.domain.domain.user.repository.UserRepository; + +import java.io.IOException; + +/** + * SQS 대기열로 알림 메시지를 추가 + */ +@Slf4j +@RequiredArgsConstructor +@Service +@Transactional +public class NotificationService { + + private final SqsProducer sqsProducer; + private final UserRepository userRepository; + + public void pushOpponentReply(String question, Long userId) { + + // 상대 측 유저의 FCM 토큰 찾기 + User user = userRepository.findById(userId).orElseThrow( + () -> new CustomException(ErrorType.INVALID_USER) + ); + + log.info("상대방 답변 완료!"); + sqsProducer.produce(FCMPushRequestDto.sendOpponentReply(user.getFcmToken(), question)); + + /* try { + log.info("상대방 답변 완료!"); + sqsProducer.produce(FCMPushRequestDto.sendOpponentReply(user.getFcmToken(), question)); + } catch (IOException e) { + log.error("푸시메시지 전송 실패 - IOException: {}", e.getMessage()); + throw new CustomException(ErrorType.FAIL_TO_SEND_PUSH_ALARM); + } catch (FirebaseMessagingException e) { + log.error("푸시메시지 전송 실패 - FirebaseMessagingException: {}", e.getMessage()); + throw new CustomException(ErrorType.FAIL_TO_SEND_PUSH_ALARM); + }*/ + } +} diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/service/ParentchildService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/parentchild/ParentchildService.java similarity index 78% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/service/ParentchildService.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/parentchild/ParentchildService.java index 65140a58..9cb2c8db 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/service/ParentchildService.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/parentchild/ParentchildService.java @@ -1,29 +1,27 @@ -package sopt.org.umbbaServer.domain.parentchild.service; +package sopt.org.umbba.api.service.parentchild; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.request.InviteCodeRequestDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.request.OnboardingInviteRequestDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.request.OnboardingReceiveRequestDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.response.InviteResultResponseDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.response.OnboardingInviteResponseDto; -import sopt.org.umbbaServer.domain.parentchild.controller.dto.response.OnboardingReceiveResponseDto; -import sopt.org.umbbaServer.domain.parentchild.dao.ParentchildDao; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.parentchild.model.ParentchildRelation; -import sopt.org.umbbaServer.domain.parentchild.repository.ParentchildRepository; -import sopt.org.umbbaServer.domain.qna.model.OnboardingAnswer; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.domain.user.repository.UserRepository; -import sopt.org.umbbaServer.global.config.ScheduleConfig; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; -import sopt.org.umbbaServer.global.util.fcm.FCMScheduler; -import sopt.org.umbbaServer.global.util.fcm.FCMService; - +import sopt.org.umbba.api.controller.parentchild.dto.request.InviteCodeRequestDto; +import sopt.org.umbba.api.controller.parentchild.dto.request.OnboardingInviteRequestDto; +import sopt.org.umbba.api.controller.parentchild.dto.request.OnboardingReceiveRequestDto; +import sopt.org.umbba.api.controller.parentchild.dto.response.InviteResultResponseDto; +import sopt.org.umbba.api.controller.parentchild.dto.response.OnboardingInviteResponseDto; +import sopt.org.umbba.api.controller.parentchild.dto.response.OnboardingReceiveResponseDto; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; +import sopt.org.umbba.domain.domain.parentchild.ParentchildRelation; +import sopt.org.umbba.domain.domain.parentchild.dao.ParentchildDao; +import sopt.org.umbba.domain.domain.parentchild.repository.ParentchildRepository; +import sopt.org.umbba.domain.domain.qna.OnboardingAnswer; +import sopt.org.umbba.domain.domain.user.User; +import sopt.org.umbba.domain.domain.user.repository.UserRepository; + +import javax.validation.Valid; import java.util.List; import java.util.stream.Collectors; @@ -36,8 +34,7 @@ public class ParentchildService { private final ParentchildRepository parentchildRepository; private final UserRepository userRepository; private final ParentchildDao parentchildDao; - private final FCMScheduler fcmScheduler; - private final FCMService fcmService; +// private final FCMScheduler fcmScheduler; TODO ⭐️SQS로 변경 // [발신] 초대하는 측의 온보딩 정보 입력 @Transactional @@ -123,9 +120,9 @@ public OnboardingReceiveResponseDto onboardReceive(Long userId, OnboardingReceiv /*if (!ParentchildRelation.validate(parentChildUsers, parentchild.getRelation())) { throw new CustomException(ErrorType.INVALID_PARENT_CHILD_RELATION); }*/ - ScheduleConfig.resetScheduler(); - fcmScheduler.pushTodayQna(); - + // TODO ⭐️SQS로 변경 +// ScheduleConfig.resetScheduler(); +// fcmScheduler.pushTodayQna(); return OnboardingReceiveResponseDto.of(parentchild, user, parentChildUsers); @@ -140,7 +137,7 @@ private String generateInviteCode() { // 초대코드 확인 후 부모자식 관계 성립 @Transactional - public InviteResultResponseDto matchRelation(Long userId, InviteCodeRequestDto request) { + public InviteResultResponseDto matchRelation(Long userId, @Valid InviteCodeRequestDto request) { log.info("ParentchlidService 실행 - 요청 초대코드: {}", request.getInviteCode()); Parentchild newMatchRelation = parentchildRepository.findByInviteCode(request.getInviteCode()).orElseThrow( diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/service/QnAService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/qna/QnAService.java similarity index 84% rename from src/main/java/sopt/org/umbbaServer/domain/qna/service/QnAService.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/qna/QnAService.java index a4a3e2e5..434dc8f5 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/service/QnAService.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/qna/QnAService.java @@ -1,34 +1,37 @@ -package sopt.org.umbbaServer.domain.qna.service; +package sopt.org.umbba.api.service.qna; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import sopt.org.umbbaServer.domain.parentchild.dao.ParentchildDao; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.qna.controller.dto.request.TodayAnswerRequestDto; -import sopt.org.umbbaServer.domain.qna.controller.dto.response.*; -import sopt.org.umbbaServer.domain.qna.model.*; -import sopt.org.umbbaServer.domain.qna.repository.QnARepository; -import sopt.org.umbbaServer.domain.qna.repository.QuestionRepository; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.domain.user.repository.UserRepository; -import sopt.org.umbbaServer.domain.user.social.SocialPlatform; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; -import sopt.org.umbbaServer.global.util.fcm.FCMService; -import sopt.org.umbbaServer.global.util.fcm.controller.dto.FCMPushRequestDto; - -import java.util.ArrayList; +import sopt.org.umbba.api.config.sqs.producer.SqsProducer; +import sopt.org.umbba.api.controller.qna.dto.request.TodayAnswerRequestDto; +import sopt.org.umbba.api.controller.qna.dto.response.*; +import sopt.org.umbba.api.service.notification.NotificationService; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; +import sopt.org.umbba.domain.domain.parentchild.dao.ParentchildDao; +import sopt.org.umbba.domain.domain.qna.OnboardingAnswer; +import sopt.org.umbba.domain.domain.qna.QnA; +import sopt.org.umbba.domain.domain.qna.Question; +import sopt.org.umbba.domain.domain.qna.repository.QnARepository; +import sopt.org.umbba.domain.domain.qna.repository.QuestionRepository; +import sopt.org.umbba.domain.domain.user.SocialPlatform; +import sopt.org.umbba.domain.domain.user.User; +import sopt.org.umbba.domain.domain.user.repository.UserRepository; + +import javax.validation.constraints.NotNull; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; -import static sopt.org.umbbaServer.domain.qna.model.OnboardingAnswer.*; -import static sopt.org.umbbaServer.domain.qna.model.QuestionSection.*; -import static sopt.org.umbbaServer.domain.qna.model.QuestionType.*; +import static sopt.org.umbba.domain.domain.qna.OnboardingAnswer.NO; +import static sopt.org.umbba.domain.domain.qna.OnboardingAnswer.YES; +import static sopt.org.umbba.domain.domain.qna.QuestionSection.*; +import static sopt.org.umbba.domain.domain.qna.QuestionType.*; + @Slf4j @Service @@ -40,7 +43,7 @@ public class QnAService { private final QuestionRepository questionRepository; private final UserRepository userRepository; private final ParentchildDao parentchildDao; - private final FCMService fcmService; //TODO Service에서 Service를 주입받는 부분 수정 + private final NotificationService notificationService; public TodayQnAResponseDto getTodayQnA(Long userId) { @@ -81,10 +84,12 @@ public void answerTodayQuestion(Long userId, TodayAnswerRequestDto request) { if (myUser.isMeChild()) { todayQnA.saveChildAnswer(request.getAnswer()); - fcmService.pushOpponentReply(todayQnA.getQuestion().getParentQuestion(), opponentUser.getId()); + notificationService.pushOpponentReply(todayQnA.getQuestion().getChildQuestion(), opponentUser.getId()); +// fcmService.pushOpponentReply(todayQnA.getQuestion().getChildQuestion(), opponentUser.getId()); } else { todayQnA.saveParentAnswer(request.getAnswer()); - fcmService.pushOpponentReply(todayQnA.getQuestion().getChildQuestion(), opponentUser.getId()); + notificationService.pushOpponentReply(todayQnA.getQuestion().getParentQuestion(), opponentUser.getId()); +// fcmService.pushOpponentReply(todayQnA.getQuestion().getParentQuestion(), opponentUser.getId()); } } @@ -236,7 +241,7 @@ private User getOpponentByParentchild(Parentchild parentchild, Long userId) { } @Transactional - private void customQuestion(List childList, List parentList, List qnAList) { + public void customQuestion(List childList, List parentList, List qnAList) { // Type 1 : 1번째 선택 질문인 거주 현황에 대해 한명이라도 아니/애매해라고 답한 경우 if (childList.get(0) != YES || parentList.get(0) !=YES) { @@ -319,7 +324,7 @@ private GetInvitationResponseDto invitation(Long userId) { () -> new CustomException(ErrorType.USER_HAVE_NO_PARENTCHILD) ); - return GetInvitationResponseDto.of(parentchild.getInviteCode(), user.getUsername(), "http://umbba.site/"); // TODO url 설정 필요 (Firebase) + return GetInvitationResponseDto.of(parentchild.getInviteCode(), user.getUsername(), "http://umbba.site/"); // TODO Firebase 동적링크 연결 예정 } private GetInvitationResponseDto withdrawUser() { @@ -343,9 +348,10 @@ public void updateDemoList(Long userId) { } QnA fifthQnA = getTodayQnAByParentchild(parentchild); log.info("💖💖💖💖Day 5 QnA: {}", fifthQnA.getId()); - fcmService.multipleSendByToken(FCMPushRequestDto.sendTodayQna( - fifthQnA.getQuestion().getSection().getValue(), - fifthQnA.getQuestion().getTopic()), parentchild.getId()); + //TODO ⭐️SQS로 변경 +// fcmService.multipleSendByToken(FCMPushRequestDto.sendTodayQna( +// fifthQnA.getQuestion().getSection().getValue(), +// fifthQnA.getQuestion().getTopic()), parentchild.getId()); } @@ -360,9 +366,10 @@ public void todayUpdate(Long userId) { "오구 내 똥강아지~ 어렸을 때는 매일 볼 수 있었는데, 어른이 되고 나서 자주 못봐서 너무 아쉽다... 연락 잘하거라 요녀석~"); QnA todayQnA = getTodayQnAByParentchild(parentchild); - fcmService.multipleSendByToken(FCMPushRequestDto.sendTodayQna( - todayQnA.getQuestion().getSection().getValue(), - todayQnA.getQuestion().getTopic()), parentchild.getId()); + //TODO ⭐️SQS로 변경 +// fcmService.multipleSendByToken(FCMPushRequestDto.sendTodayQna( +// todayQnA.getQuestion().getSection().getValue(), +// todayQnA.getQuestion().getTopic()), parentchild.getId()); } private void updateDay(Parentchild parentchild, String childAnswer, String parentAnswer) { diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/service/AuthService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/AuthService.java similarity index 83% rename from src/main/java/sopt/org/umbbaServer/domain/user/service/AuthService.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/user/AuthService.java index aa7d8da7..beb26084 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/service/AuthService.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/AuthService.java @@ -1,24 +1,23 @@ -package sopt.org.umbbaServer.domain.user.service; - +package sopt.org.umbba.api.service.user; import feign.FeignException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import sopt.org.umbbaServer.domain.user.controller.dto.request.RefreshRequestDto; -import sopt.org.umbbaServer.domain.user.controller.dto.request.SocialLoginRequestDto; -import sopt.org.umbbaServer.domain.user.controller.dto.response.UserLoginResponseDto; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.domain.user.repository.UserRepository; -import sopt.org.umbbaServer.domain.user.social.SocialPlatform; -import sopt.org.umbbaServer.domain.user.social.apple.AppleLoginService; -import sopt.org.umbbaServer.domain.user.social.kakao.KakaoLoginService; -import sopt.org.umbbaServer.global.config.auth.UserAuthentication; -import sopt.org.umbbaServer.global.config.jwt.JwtProvider; -import sopt.org.umbbaServer.global.config.jwt.TokenDto; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.api.config.auth.UserAuthentication; +import sopt.org.umbba.api.config.jwt.JwtProvider; +import sopt.org.umbba.api.config.jwt.TokenDto; +import sopt.org.umbba.api.controller.user.dto.request.RefreshRequestDto; +import sopt.org.umbba.api.controller.user.dto.request.SocialLoginRequestDto; +import sopt.org.umbba.api.controller.user.dto.response.UserLoginResponseDto; +import sopt.org.umbba.api.service.user.social.apple.AppleLoginService; +import sopt.org.umbba.api.service.user.social.kakao.KakaoLoginService; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.domain.domain.user.SocialPlatform; +import sopt.org.umbba.domain.domain.user.User; +import sopt.org.umbba.domain.domain.user.repository.UserRepository; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/AppleLoginService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/AppleLoginService.java similarity index 66% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/apple/AppleLoginService.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/AppleLoginService.java index a4438666..d4624410 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/AppleLoginService.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/AppleLoginService.java @@ -1,15 +1,16 @@ -package sopt.org.umbbaServer.domain.user.social.apple; +package sopt.org.umbba.api.service.user.social.apple; import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import sopt.org.umbbaServer.domain.user.social.apple.feign.AppleApiClient; -import sopt.org.umbbaServer.domain.user.social.apple.response.ApplePublicKeys; -import sopt.org.umbbaServer.domain.user.social.apple.verify.AppleClaimsValidator; -import sopt.org.umbbaServer.domain.user.social.apple.verify.AppleJwtParser; -import sopt.org.umbbaServer.domain.user.social.apple.verify.PublicKeyGenerator; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.api.service.user.social.apple.verify.AppleClaimsValidator; +import sopt.org.umbba.api.service.user.social.apple.verify.AppleJwtParser; +import sopt.org.umbba.api.service.user.social.apple.verify.PublicKeyGenerator; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.external.client.auth.apple.AppleApiClient; +import sopt.org.umbba.external.client.auth.apple.response.ApplePublicKeys; + import java.security.PublicKey; import java.util.Map; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/AppleClaimsValidator.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/AppleClaimsValidator.java similarity index 93% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/AppleClaimsValidator.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/AppleClaimsValidator.java index e5eb7500..f25deb13 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/AppleClaimsValidator.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/AppleClaimsValidator.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.user.social.apple.verify; +package sopt.org.umbba.api.service.user.social.apple.verify; import io.jsonwebtoken.Claims; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/AppleJwtParser.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/AppleJwtParser.java similarity index 90% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/AppleJwtParser.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/AppleJwtParser.java index 88e5f6bf..33942031 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/AppleJwtParser.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/AppleJwtParser.java @@ -1,12 +1,12 @@ -package sopt.org.umbbaServer.domain.user.social.apple.verify; +package sopt.org.umbba.api.service.user.social.apple.verify; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.jsonwebtoken.*; import org.springframework.stereotype.Component; import org.springframework.util.Base64Utils; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; import java.security.PublicKey; import java.util.Map; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/EncryptUtils.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/EncryptUtils.java similarity index 80% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/EncryptUtils.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/EncryptUtils.java index 486b0902..2211ed45 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/EncryptUtils.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/EncryptUtils.java @@ -1,7 +1,8 @@ -package sopt.org.umbbaServer.domain.user.social.apple.verify; +package sopt.org.umbba.api.service.user.social.apple.verify; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; + +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/PublicKeyGenerator.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/PublicKeyGenerator.java similarity index 83% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/PublicKeyGenerator.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/PublicKeyGenerator.java index b2c37944..5e86e6e1 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/verify/PublicKeyGenerator.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/apple/verify/PublicKeyGenerator.java @@ -1,11 +1,11 @@ -package sopt.org.umbbaServer.domain.user.social.apple.verify; +package sopt.org.umbba.api.service.user.social.apple.verify; import org.springframework.stereotype.Component; import org.springframework.util.Base64Utils; -import sopt.org.umbbaServer.domain.user.social.apple.response.ApplePublicKey; -import sopt.org.umbbaServer.domain.user.social.apple.response.ApplePublicKeys; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.external.client.auth.apple.response.ApplePublicKey; +import sopt.org.umbba.external.client.auth.apple.response.ApplePublicKeys; import java.math.BigInteger; import java.security.KeyFactory; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/KakaoLoginService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/kakao/KakaoLoginService.java similarity index 82% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/KakaoLoginService.java rename to umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/kakao/KakaoLoginService.java index 54f18bda..e04aeb9c 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/KakaoLoginService.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/user/social/kakao/KakaoLoginService.java @@ -1,14 +1,14 @@ -package sopt.org.umbbaServer.domain.user.social.kakao; +package sopt.org.umbba.api.service.user.social.kakao; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.domain.user.social.kakao.feign.KakaoApiClient; -import sopt.org.umbbaServer.domain.user.social.kakao.feign.KakaoAuthApiClient; -import sopt.org.umbbaServer.domain.user.social.kakao.response.KakaoAccessTokenResponse; -import sopt.org.umbbaServer.domain.user.social.kakao.response.KakaoUserResponse; +import sopt.org.umbba.domain.domain.user.User; +import sopt.org.umbba.external.client.auth.kakao.KakaoApiClient; +import sopt.org.umbba.external.client.auth.kakao.KakaoAuthApiClient; +import sopt.org.umbba.external.client.auth.kakao.response.KakaoAccessTokenResponse; +import sopt.org.umbba.external.client.auth.kakao.response.KakaoUserResponse; @Service @Transactional diff --git a/src/main/resources/application.yaml b/umbba-api/src/main/resources/application.yaml similarity index 88% rename from src/main/resources/application.yaml rename to umbba-api/src/main/resources/application.yaml index 9b76edcd..6b561220 100644 --- a/src/main/resources/application.yaml +++ b/umbba-api/src/main/resources/application.yaml @@ -9,6 +9,14 @@ cloud: bucket: ${bucket-name} stack: auto: false + sqs: + notification: + name: ${sqs-notification-name} + url: ${sqs-notification-url} + #api: + # name: ${sqs-api-name} + # url: ${sqs-api-url} + spring: datasource: @@ -16,7 +24,6 @@ spring: url: ${db-url} username: ${db-user} password: ${db-pwd} - hikari: pool-name: Hikari 커넥션 풀 # Pool connection-timeout: 30000 # 30초(default: 30초) @@ -71,4 +78,4 @@ logging: com.zaxxer.hikari.pool.HikariPool: debug server: - port: 9091 + port: 9091 \ No newline at end of file diff --git a/umbba-common/build.gradle b/umbba-common/build.gradle new file mode 100644 index 00000000..5a66b154 --- /dev/null +++ b/umbba-common/build.gradle @@ -0,0 +1,10 @@ +bootJar { enabled = false } +jar { enabled = true } +dependencies { + + // for HttpStatus + implementation 'org.springframework.boot:spring-boot-starter-web' + + // Jackson + implementation group: "io.jsonwebtoken", name: "jjwt-jackson", version: "0.11.2" +} \ No newline at end of file diff --git a/umbba-common/src/main/java/sopt/org/umbba/common/UmbbaCommonRoot.java b/umbba-common/src/main/java/sopt/org/umbba/common/UmbbaCommonRoot.java new file mode 100644 index 00000000..14910c5f --- /dev/null +++ b/umbba-common/src/main/java/sopt/org/umbba/common/UmbbaCommonRoot.java @@ -0,0 +1,8 @@ +package sopt.org.umbba.common; + +import org.springframework.context.annotation.ComponentScan; + +@ComponentScan(basePackageClasses = {UmbbaCommonRoot.class}) +public interface UmbbaCommonRoot { + +} diff --git a/src/main/java/sopt/org/umbbaServer/global/exception/ErrorType.java b/umbba-common/src/main/java/sopt/org/umbba/common/exception/ErrorType.java similarity index 99% rename from src/main/java/sopt/org/umbbaServer/global/exception/ErrorType.java rename to umbba-common/src/main/java/sopt/org/umbba/common/exception/ErrorType.java index 73c386b8..361b75eb 100644 --- a/src/main/java/sopt/org/umbbaServer/global/exception/ErrorType.java +++ b/umbba-common/src/main/java/sopt/org/umbba/common/exception/ErrorType.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.exception; +package sopt.org.umbba.common.exception; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/sopt/org/umbbaServer/global/exception/SuccessType.java b/umbba-common/src/main/java/sopt/org/umbba/common/exception/SuccessType.java similarity index 96% rename from src/main/java/sopt/org/umbbaServer/global/exception/SuccessType.java rename to umbba-common/src/main/java/sopt/org/umbba/common/exception/SuccessType.java index 2b59321c..c1ab240b 100644 --- a/src/main/java/sopt/org/umbbaServer/global/exception/SuccessType.java +++ b/umbba-common/src/main/java/sopt/org/umbba/common/exception/SuccessType.java @@ -1,6 +1,5 @@ -package sopt.org.umbbaServer.global.exception; +package sopt.org.umbba.common.exception; -import com.google.api.Http; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/sopt/org/umbbaServer/global/common/dto/ApiResponse.java b/umbba-common/src/main/java/sopt/org/umbba/common/exception/dto/ApiResponse.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/global/common/dto/ApiResponse.java rename to umbba-common/src/main/java/sopt/org/umbba/common/exception/dto/ApiResponse.java index ce638ddc..d86fc811 100644 --- a/src/main/java/sopt/org/umbbaServer/global/common/dto/ApiResponse.java +++ b/umbba-common/src/main/java/sopt/org/umbba/common/exception/dto/ApiResponse.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.common.dto; +package sopt.org.umbba.common.exception.dto; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @@ -6,8 +6,8 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; -import sopt.org.umbbaServer.global.exception.ErrorType; -import sopt.org.umbbaServer.global.exception.SuccessType; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.SuccessType; @Getter @JsonPropertyOrder({"status", "message", "data"}) diff --git a/src/main/java/sopt/org/umbbaServer/global/exception/CustomException.java b/umbba-common/src/main/java/sopt/org/umbba/common/exception/model/CustomException.java similarity index 78% rename from src/main/java/sopt/org/umbbaServer/global/exception/CustomException.java rename to umbba-common/src/main/java/sopt/org/umbba/common/exception/model/CustomException.java index 5539429e..8d4e568d 100644 --- a/src/main/java/sopt/org/umbbaServer/global/exception/CustomException.java +++ b/umbba-common/src/main/java/sopt/org/umbba/common/exception/model/CustomException.java @@ -1,6 +1,7 @@ -package sopt.org.umbbaServer.global.exception; +package sopt.org.umbba.common.exception.model; import lombok.Getter; +import sopt.org.umbba.common.exception.ErrorType; @Getter public class CustomException extends RuntimeException { diff --git a/umbba-common/src/main/java/sopt/org/umbba/common/sqs/MessageType.java b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/MessageType.java new file mode 100644 index 00000000..2fd110db --- /dev/null +++ b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/MessageType.java @@ -0,0 +1,12 @@ +package sopt.org.umbba.common.sqs; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class MessageType { + + public static final String MESSAGE_TYPE_HEADER = "TYPE"; + public static final String FIREBASE = "FIREBASE"; + public static final String SLACK = "SLACK"; +} diff --git a/umbba-common/src/main/java/sopt/org/umbba/common/sqs/MessageUtils.java b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/MessageUtils.java new file mode 100644 index 00000000..a2dcd1c7 --- /dev/null +++ b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/MessageUtils.java @@ -0,0 +1,17 @@ +package sopt.org.umbba.common.sqs; + +public class MessageUtils { + + public static String generate(String message, P1 param1) { + return String.format(message, param1); + } + + public static String generate(String message, P1 param1, P2 param2) { + return String.format(message, param1, param2); + } + + public static String generate(String message, P1 param1, P2 param2, P3 param3) { + return String.format(message, param1, param2, param3); + } + +} diff --git a/src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/FCMPushRequestDto.java b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/FCMPushRequestDto.java similarity index 83% rename from src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/FCMPushRequestDto.java rename to umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/FCMPushRequestDto.java index d5e528a4..923faad7 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/FCMPushRequestDto.java +++ b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/FCMPushRequestDto.java @@ -1,18 +1,17 @@ -package sopt.org.umbbaServer.global.util.fcm.controller.dto; +package sopt.org.umbba.common.sqs.dto; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.*; +import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; - -import java.util.logging.Logger; +import sopt.org.umbba.common.sqs.MessageType; @Slf4j @Getter -@Builder +@SuperBuilder @AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class FCMPushRequestDto { +public class FCMPushRequestDto extends MessageDto{ private String targetToken; @@ -27,6 +26,7 @@ public class FCMPushRequestDto { public static FCMPushRequestDto sendTodayQna(String section, String topic) { return FCMPushRequestDto.builder() + .type(MessageType.FIREBASE) .title("📞" + section + PushMessage.TODAY_QNA.getTitle()) .body("'" + topic + PushMessage.TODAY_QNA.getBody()) .build(); @@ -36,6 +36,7 @@ public static FCMPushRequestDto sendTodayQna(String section, String topic) { public static FCMPushRequestDto sendOpponentReply(String targetToken, String question) { return FCMPushRequestDto.builder() + .type(MessageType.FIREBASE) .targetToken(targetToken) .title(PushMessage.OPPONENT_REPLY.getTitle()) .body("'" + question + PushMessage.OPPONENT_REPLY.getBody()) diff --git a/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/FirebaseDto.java b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/FirebaseDto.java new file mode 100644 index 00000000..329e604d --- /dev/null +++ b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/FirebaseDto.java @@ -0,0 +1,26 @@ +package sopt.org.umbba.common.sqs.dto; + +import lombok.*; +import lombok.experimental.SuperBuilder; +import sopt.org.umbba.common.sqs.MessageType; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@SuperBuilder +public class FirebaseDto extends MessageDto { + + private String fcmToken; + private String title; + private String body; + + public static FirebaseDto of(String fcmToken, String title, String body) { + return FirebaseDto.builder() + .type(MessageType.FIREBASE) + .fcmToken(fcmToken) + .title(title) + .body(body) + .build(); + } +} diff --git a/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/MessageDto.java b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/MessageDto.java new file mode 100644 index 00000000..84ea7620 --- /dev/null +++ b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/MessageDto.java @@ -0,0 +1,14 @@ +package sopt.org.umbba.common.sqs.dto; + +import lombok.*; +import lombok.experimental.SuperBuilder; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@SuperBuilder +public class MessageDto { + + protected String type; +} diff --git a/src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/PushMessage.java b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/PushMessage.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/PushMessage.java rename to umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/PushMessage.java index 35d205ec..9ab5ea22 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/PushMessage.java +++ b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/PushMessage.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.util.fcm.controller.dto; +package sopt.org.umbba.common.sqs.dto; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/SlackDto.java b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/SlackDto.java new file mode 100644 index 00000000..fdcd3bbc --- /dev/null +++ b/umbba-common/src/main/java/sopt/org/umbba/common/sqs/dto/SlackDto.java @@ -0,0 +1,29 @@ +package sopt.org.umbba.common.sqs.dto; + +import lombok.*; +import lombok.experimental.SuperBuilder; +import sopt.org.umbba.common.sqs.MessageType; + +import javax.servlet.http.HttpServletRequest; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@SuperBuilder +public class SlackDto extends MessageDto { + + private Exception error; + private HttpServletRequest request; + private String requestMethod; + private String requestURI; + + public static SlackDto of(Exception error, String requestMethod, String requestURI) { + return SlackDto.builder() + .type(MessageType.SLACK) + .error(error) + .requestMethod(requestMethod) + .requestURI(requestURI) + .build(); + } +} diff --git a/umbba-domain/build.gradle b/umbba-domain/build.gradle new file mode 100644 index 00000000..5c44fbc2 --- /dev/null +++ b/umbba-domain/build.gradle @@ -0,0 +1,43 @@ +bootJar { enabled = false } +jar { enabled = true } + +dependencies { + implementation project(path: ':umbba-common') + + // JPA & Database + api "org.springframework.boot:spring-boot-starter-data-jpa" + implementation 'mysql:mysql-connector-java:8.0.32' +// runtimeOnly "mysql:mysql-connector-java" + + // JSON + implementation 'com.googlecode.json-simple:json-simple:1.1.1' + + // redis + implementation "org.springframework.boot:spring-boot-starter-data-redis" + implementation "org.springframework.session:spring-session-data-redis" + + // jackson + implementation group: "io.jsonwebtoken", name: "jjwt-jackson", version: "0.11.2" + + // querydsl +// implementation "com.querydsl:querydsl-jpa" +// implementation "com.querydsl:querydsl-core" +// annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties["querydsl.version"]}:jpa" +// annotationProcessor "jakarta.persistence:jakarta.persistence-api:2.2.3" +// annotationProcessor "jakarta.annotation:jakarta.annotation-api:1.3.5" +} + +//def queryDslDir = "build/querydsl/generated" +// +//sourceSets { +// main.java.srcDirs += [queryDslDir] +//} +// +//tasks.withType(JavaCompile) { +// options.annotationProcessorGeneratedSourcesDirectory = file(queryDslDir) +//} +// +//clean.doLast { +// file(queryDslDir).deleteDir() +//} + diff --git a/umbba-domain/src/main/java/sopt/org/umbba/domain/UmbbaDomainRoot.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/UmbbaDomainRoot.java new file mode 100644 index 00000000..0a867733 --- /dev/null +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/UmbbaDomainRoot.java @@ -0,0 +1,7 @@ +package sopt.org.umbba.domain; + +import org.springframework.context.annotation.ComponentScan; + +@ComponentScan(basePackageClasses = {UmbbaDomainRoot.class}) +public interface UmbbaDomainRoot { +} diff --git a/umbba-domain/src/main/java/sopt/org/umbba/domain/config/jpa/JpaConfig.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/config/jpa/JpaConfig.java new file mode 100644 index 00000000..0e0ab3c6 --- /dev/null +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/config/jpa/JpaConfig.java @@ -0,0 +1,14 @@ +package sopt.org.umbba.domain.config.jpa; + +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import sopt.org.umbba.domain.UmbbaDomainRoot; + +@Configuration +@EntityScan(basePackageClasses = {UmbbaDomainRoot.class}) +@EnableJpaRepositories(basePackageClasses = {UmbbaDomainRoot.class}) +@EnableJpaAuditing +public class JpaConfig { +} diff --git a/src/main/java/sopt/org/umbbaServer/global/util/AuditingTimeEntity.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/common/AuditingTimeEntity.java similarity index 92% rename from src/main/java/sopt/org/umbbaServer/global/util/AuditingTimeEntity.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/common/AuditingTimeEntity.java index e400d722..0c085732 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/AuditingTimeEntity.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/common/AuditingTimeEntity.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.util; +package sopt.org.umbba.domain.domain.common; import lombok.Getter; import org.springframework.data.annotation.CreatedDate; @@ -19,4 +19,4 @@ public abstract class AuditingTimeEntity { @LastModifiedDate private LocalDateTime updatedAt; -} +} \ No newline at end of file diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/model/Parentchild.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/Parentchild.java similarity index 87% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/model/Parentchild.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/Parentchild.java index 166c5a0e..b77985e0 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/model/Parentchild.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/Parentchild.java @@ -1,11 +1,10 @@ -package sopt.org.umbbaServer.domain.parentchild.model; +package sopt.org.umbba.domain.domain.parentchild; import lombok.*; import lombok.extern.slf4j.Slf4j; -import org.springframework.transaction.annotation.Transactional; -import sopt.org.umbbaServer.domain.qna.model.OnboardingAnswer; -import sopt.org.umbbaServer.domain.qna.model.QnA; -import sopt.org.umbbaServer.global.util.AuditingTimeEntity; +import sopt.org.umbba.domain.domain.common.AuditingTimeEntity; +import sopt.org.umbba.domain.domain.qna.OnboardingAnswer; +import sopt.org.umbba.domain.domain.qna.QnA; import javax.persistence.*; import java.time.LocalTime; @@ -48,11 +47,13 @@ public void addCount() { @Enumerated(EnumType.STRING) @Column(name = "answer", nullable = false) @ElementCollection + @Builder.Default private List childOnboardingAnswerList = new ArrayList<>(); @Enumerated(EnumType.STRING) @Column(name = "answer", nullable = false) @ElementCollection + @Builder.Default private List parentOnboardingAnswerList = new ArrayList<>(); public void changeChildOnboardingAnswerList(List onboardingAnswerList) { diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/model/ParentchildRelation.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/ParentchildRelation.java similarity index 92% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/model/ParentchildRelation.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/ParentchildRelation.java index 4ed3a377..39a84dc2 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/model/ParentchildRelation.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/ParentchildRelation.java @@ -1,11 +1,11 @@ -package sopt.org.umbbaServer.domain.parentchild.model; +package sopt.org.umbba.domain.domain.parentchild; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.domain.domain.user.User; import java.util.List; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/dao/ParentchildDao.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/dao/ParentchildDao.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/dao/ParentchildDao.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/dao/ParentchildDao.java index a21c66a1..adf41436 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/dao/ParentchildDao.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/dao/ParentchildDao.java @@ -1,9 +1,9 @@ -package sopt.org.umbbaServer.domain.parentchild.dao; +package sopt.org.umbba.domain.domain.parentchild.dao; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Repository; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.user.model.User; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; +import sopt.org.umbba.domain.domain.user.User; import javax.persistence.EntityManager; import javax.persistence.NoResultException; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/repository/ParentchildRepository.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/repository/ParentchildRepository.java similarity index 77% rename from src/main/java/sopt/org/umbbaServer/domain/parentchild/repository/ParentchildRepository.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/repository/ParentchildRepository.java index 6915353a..f9efe00c 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/repository/ParentchildRepository.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/repository/ParentchildRepository.java @@ -1,7 +1,7 @@ -package sopt.org.umbbaServer.domain.parentchild.repository; +package sopt.org.umbba.domain.domain.parentchild.repository; import org.springframework.data.repository.Repository; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; import java.util.List; import java.util.Optional; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/model/OnboardingAnswer.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/OnboardingAnswer.java similarity index 78% rename from src/main/java/sopt/org/umbbaServer/domain/qna/model/OnboardingAnswer.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/OnboardingAnswer.java index ab604828..c817bf19 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/model/OnboardingAnswer.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/OnboardingAnswer.java @@ -1,10 +1,10 @@ -package sopt.org.umbbaServer.domain.qna.model; +package sopt.org.umbba.domain.domain.qna; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/model/QnA.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QnA.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/domain/qna/model/QnA.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QnA.java index c81672f6..e689f60b 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/model/QnA.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QnA.java @@ -1,7 +1,7 @@ -package sopt.org.umbbaServer.domain.qna.model; +package sopt.org.umbba.domain.domain.qna; import lombok.*; -import sopt.org.umbbaServer.global.util.AuditingTimeEntity; +import sopt.org.umbba.domain.domain.common.AuditingTimeEntity; import javax.persistence.*; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/model/Question.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/Question.java similarity index 87% rename from src/main/java/sopt/org/umbbaServer/domain/qna/model/Question.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/Question.java index 5b24e078..703645df 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/model/Question.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/Question.java @@ -1,7 +1,7 @@ -package sopt.org.umbbaServer.domain.qna.model; +package sopt.org.umbba.domain.domain.qna; import lombok.*; -import sopt.org.umbbaServer.global.util.AuditingTimeEntity; +import sopt.org.umbba.domain.domain.common.AuditingTimeEntity; import javax.persistence.*; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/model/QuestionSection.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QuestionSection.java similarity index 92% rename from src/main/java/sopt/org/umbbaServer/domain/qna/model/QuestionSection.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QuestionSection.java index 219a8c6d..38ee957d 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/model/QuestionSection.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QuestionSection.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.qna.model; +package sopt.org.umbba.domain.domain.qna; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/model/QuestionType.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QuestionType.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/domain/qna/model/QuestionType.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QuestionType.java index c9a5e088..461406c6 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/model/QuestionType.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/QuestionType.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.qna.model; +package sopt.org.umbba.domain.domain.qna; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/dao/QnADao.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/dao/QnADao.java similarity index 92% rename from src/main/java/sopt/org/umbbaServer/domain/qna/dao/QnADao.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/dao/QnADao.java index f46b3367..bb629199 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/dao/QnADao.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/dao/QnADao.java @@ -1,8 +1,8 @@ -package sopt.org.umbbaServer.domain.qna.dao; +package sopt.org.umbba.domain.domain.qna.dao; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Repository; -import sopt.org.umbbaServer.domain.qna.model.QnA; +import sopt.org.umbba.domain.domain.qna.QnA; import javax.persistence.EntityManager; import javax.persistence.NoResultException; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/repository/QnARepository.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/repository/QnARepository.java similarity index 67% rename from src/main/java/sopt/org/umbbaServer/domain/qna/repository/QnARepository.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/repository/QnARepository.java index 4bc4033e..a90632b7 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/repository/QnARepository.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/repository/QnARepository.java @@ -1,7 +1,7 @@ -package sopt.org.umbbaServer.domain.qna.repository; +package sopt.org.umbba.domain.domain.qna.repository; import org.springframework.data.repository.Repository; -import sopt.org.umbbaServer.domain.qna.model.QnA; +import sopt.org.umbba.domain.domain.qna.QnA; import java.util.Optional; diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/repository/QuestionRepository.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/repository/QuestionRepository.java similarity index 86% rename from src/main/java/sopt/org/umbbaServer/domain/qna/repository/QuestionRepository.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/repository/QuestionRepository.java index bd7aa833..1a9d7586 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/repository/QuestionRepository.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/qna/repository/QuestionRepository.java @@ -1,9 +1,9 @@ -package sopt.org.umbbaServer.domain.qna.repository; +package sopt.org.umbba.domain.domain.qna.repository; import org.springframework.data.repository.Repository; -import sopt.org.umbbaServer.domain.qna.model.Question; -import sopt.org.umbbaServer.domain.qna.model.QuestionSection; -import sopt.org.umbbaServer.domain.qna.model.QuestionType; +import sopt.org.umbba.domain.domain.qna.Question; +import sopt.org.umbba.domain.domain.qna.QuestionSection; +import sopt.org.umbba.domain.domain.qna.QuestionType; import java.util.*; import java.util.stream.Collectors; diff --git a/src/main/java/sopt/org/umbbaServer/global/config/jwt/redis/RefreshToken.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/redis/RefreshToken.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/global/config/jwt/redis/RefreshToken.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/redis/RefreshToken.java index 9fbe2a3f..5d1f35c7 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/jwt/redis/RefreshToken.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/redis/RefreshToken.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.config.jwt.redis; +package sopt.org.umbba.domain.domain.redis; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/SocialPlatform.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/SocialPlatform.java similarity index 78% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/SocialPlatform.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/SocialPlatform.java index dd742562..f1503589 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/SocialPlatform.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/SocialPlatform.java @@ -1,10 +1,10 @@ -package sopt.org.umbbaServer.domain.user.social; +package sopt.org.umbba.domain.domain.user; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/model/User.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/User.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/domain/user/model/User.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/User.java index 098e5745..6af074f2 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/model/User.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/User.java @@ -1,12 +1,9 @@ -package sopt.org.umbbaServer.domain.user.model; +package sopt.org.umbba.domain.domain.user; import lombok.*; import lombok.extern.slf4j.Slf4j; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.user.social.SocialPlatform; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; -import sopt.org.umbbaServer.global.util.AuditingTimeEntity; +import sopt.org.umbba.domain.domain.common.AuditingTimeEntity; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; import javax.persistence.*; import java.util.List; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/repository/UserRepository.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/repository/UserRepository.java similarity index 77% rename from src/main/java/sopt/org/umbbaServer/domain/user/repository/UserRepository.java rename to umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/repository/UserRepository.java index f513945d..cb6ecdc7 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/repository/UserRepository.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/user/repository/UserRepository.java @@ -1,9 +1,9 @@ -package sopt.org.umbbaServer.domain.user.repository; +package sopt.org.umbba.domain.domain.user.repository; import org.springframework.data.repository.Repository; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.domain.user.social.SocialPlatform; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; +import sopt.org.umbba.domain.domain.user.SocialPlatform; +import sopt.org.umbba.domain.domain.user.User; import java.util.List; import java.util.Optional; diff --git a/umbba-external/build.gradle b/umbba-external/build.gradle new file mode 100644 index 00000000..1bc7fa04 --- /dev/null +++ b/umbba-external/build.gradle @@ -0,0 +1,15 @@ +bootJar { enabled = false } +jar { enabled = true } + +dependencies { + implementation project(":umbba-common") + + // Social Login + implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:3.1.7' + + // for JsonIgnore + implementation group: "io.jsonwebtoken", name: "jjwt-jackson", version: "0.11.2" + + // spring webflux +// implementation "org.springframework.boot:spring-boot-starter-webflux" +} \ No newline at end of file diff --git a/umbba-external/src/main/java/sopt/org/umbba/external/UmbbaExternalRoot.java b/umbba-external/src/main/java/sopt/org/umbba/external/UmbbaExternalRoot.java new file mode 100644 index 00000000..09e80219 --- /dev/null +++ b/umbba-external/src/main/java/sopt/org/umbba/external/UmbbaExternalRoot.java @@ -0,0 +1,7 @@ +package sopt.org.umbba.external; + +import org.springframework.context.annotation.ComponentScan; + +@ComponentScan(basePackageClasses = {UmbbaExternalRoot.class}) +public interface UmbbaExternalRoot { +} diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/feign/AppleApiClient.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/AppleApiClient.java similarity index 68% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/apple/feign/AppleApiClient.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/AppleApiClient.java index 5ff1d4e4..50897a71 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/feign/AppleApiClient.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/AppleApiClient.java @@ -1,8 +1,8 @@ -package sopt.org.umbbaServer.domain.user.social.apple.feign; +package sopt.org.umbba.external.client.auth.apple; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; -import sopt.org.umbbaServer.domain.user.social.apple.response.ApplePublicKeys; +import sopt.org.umbba.external.client.auth.apple.response.ApplePublicKeys; @FeignClient(name = "apple-public-verify-client", url = "https://appleid.apple.com/auth") public interface AppleApiClient { diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/response/ApplePublicKey.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/response/ApplePublicKey.java similarity index 85% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/apple/response/ApplePublicKey.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/response/ApplePublicKey.java index 071f7523..402f9081 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/response/ApplePublicKey.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/response/ApplePublicKey.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.user.social.apple.response; +package sopt.org.umbba.external.client.auth.apple.response; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/response/ApplePublicKeys.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/response/ApplePublicKeys.java similarity index 77% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/apple/response/ApplePublicKeys.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/response/ApplePublicKeys.java index 0bc79d64..a3938682 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/apple/response/ApplePublicKeys.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/apple/response/ApplePublicKeys.java @@ -1,11 +1,11 @@ -package sopt.org.umbbaServer.domain.user.social.apple.response; +package sopt.org.umbba.external.client.auth.apple.response; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.common.exception.ErrorType; import java.util.List; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/feign/KakaoApiClient.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/KakaoApiClient.java similarity index 79% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/feign/KakaoApiClient.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/KakaoApiClient.java index c1521a00..6d7d9769 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/feign/KakaoApiClient.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/KakaoApiClient.java @@ -1,10 +1,10 @@ -package sopt.org.umbbaServer.domain.user.social.kakao.feign; +package sopt.org.umbba.external.client.auth.kakao; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; -import sopt.org.umbbaServer.domain.user.social.kakao.response.KakaoUserResponse; +import sopt.org.umbba.external.client.auth.kakao.response.KakaoUserResponse; @FeignClient(name = "kakaoApiClient", url = "https://kapi.kakao.com") public interface KakaoApiClient { diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/feign/KakaoAuthApiClient.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/KakaoAuthApiClient.java similarity index 84% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/feign/KakaoAuthApiClient.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/KakaoAuthApiClient.java index b5d277e9..a39f765d 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/feign/KakaoAuthApiClient.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/KakaoAuthApiClient.java @@ -1,10 +1,10 @@ -package sopt.org.umbbaServer.domain.user.social.kakao.feign; +package sopt.org.umbba.external.client.auth.kakao; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; -import sopt.org.umbbaServer.domain.user.social.kakao.response.KakaoAccessTokenResponse; +import sopt.org.umbba.external.client.auth.kakao.response.KakaoAccessTokenResponse; @FeignClient(name = "kakaoAuthApiClient", url = "https://kauth.kakao.com") public interface KakaoAuthApiClient { diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoAccessTokenResponse.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoAccessTokenResponse.java similarity index 90% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoAccessTokenResponse.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoAccessTokenResponse.java index 81aaec52..2305ae7a 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoAccessTokenResponse.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoAccessTokenResponse.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.user.social.kakao.response; +package sopt.org.umbba.external.client.auth.kakao.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoAccount.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoAccount.java similarity index 85% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoAccount.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoAccount.java index 14a37c8f..0a673876 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoAccount.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoAccount.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.user.social.kakao.response; +package sopt.org.umbba.external.client.auth.kakao.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoUserProfile.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoUserProfile.java similarity index 86% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoUserProfile.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoUserProfile.java index 6f7e8aff..5303e0ea 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoUserProfile.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoUserProfile.java @@ -1,8 +1,9 @@ -package sopt.org.umbbaServer.domain.user.social.kakao.response; +package sopt.org.umbba.external.client.auth.kakao.response; + +import lombok.*; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; -import lombok.*; @ToString @Getter diff --git a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoUserResponse.java b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoUserResponse.java similarity index 88% rename from src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoUserResponse.java rename to umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoUserResponse.java index 7c46edbe..858ca383 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/user/social/kakao/response/KakaoUserResponse.java +++ b/umbba-external/src/main/java/sopt/org/umbba/external/client/auth/kakao/response/KakaoUserResponse.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.domain.user.social.kakao.response; +package sopt.org.umbba.external.client.auth.kakao.response; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/umbba-notification/build.gradle b/umbba-notification/build.gradle new file mode 100644 index 00000000..533d885c --- /dev/null +++ b/umbba-notification/build.gradle @@ -0,0 +1,23 @@ +jar { enabled = false } + +dependencies { + implementation project(":umbba-domain") + implementation project(":umbba-common") + implementation project(":umbba-external") + + implementation "org.springframework.boot:spring-boot-starter-web" + + // SQS + implementation "org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE" + implementation "org.springframework.cloud:spring-cloud-aws-messaging:2.2.6.RELEASE" + + // FCM + implementation "com.google.firebase:firebase-admin:9.1.1" + + // Slack Webhook + implementation 'com.slack.api:slack-api-client:1.28.0' + implementation 'com.google.code.gson:gson:2.10.1' + implementation 'com.squareup.okhttp3:okhttp:4.10.0' + implementation 'com.slack.api:slack-app-backend:1.28.0' + implementation 'com.slack.api:slack-api-model:1.28.0' +} \ No newline at end of file diff --git a/umbba-notification/src/main/java/sopt/org/umbba/notification/NotificationApplication.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/NotificationApplication.java new file mode 100644 index 00000000..aa42b4e9 --- /dev/null +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/NotificationApplication.java @@ -0,0 +1,21 @@ +package sopt.org.umbba.notification; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import sopt.org.umbba.common.UmbbaCommonRoot; +import sopt.org.umbba.domain.UmbbaDomainRoot; +import sopt.org.umbba.external.UmbbaExternalRoot; + +@SpringBootApplication(scanBasePackageClasses = { + UmbbaCommonRoot.class, + UmbbaDomainRoot.class, + UmbbaExternalRoot.class, + NotificationApplication.class +})public class NotificationApplication { + + public static void main(String[] args) { + SpringApplication.run(NotificationApplication.class, args); + } + +} \ No newline at end of file diff --git a/src/main/java/sopt/org/umbbaServer/global/config/FCMConfig.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/config/fcm/FCMConfig.java similarity index 93% rename from src/main/java/sopt/org/umbbaServer/global/config/FCMConfig.java rename to umbba-notification/src/main/java/sopt/org/umbba/notification/config/fcm/FCMConfig.java index 806c791e..1bc81e06 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/FCMConfig.java +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/config/fcm/FCMConfig.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.config; +package sopt.org.umbba.notification.config.fcm; import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; @@ -9,9 +9,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; -import sopt.org.umbbaServer.global.util.fcm.controller.dto.FCMPushRequestDto; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.common.sqs.dto.FCMPushRequestDto; import javax.annotation.PostConstruct; import java.io.IOException; diff --git a/src/main/java/sopt/org/umbbaServer/global/config/ScheduleConfig.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/config/scheduler/ScheduleConfig.java similarity index 88% rename from src/main/java/sopt/org/umbbaServer/global/config/ScheduleConfig.java rename to umbba-notification/src/main/java/sopt/org/umbba/notification/config/scheduler/ScheduleConfig.java index cff0eb21..f88168ce 100644 --- a/src/main/java/sopt/org/umbbaServer/global/config/ScheduleConfig.java +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/config/scheduler/ScheduleConfig.java @@ -1,10 +1,11 @@ -package sopt.org.umbbaServer.global.config; +package sopt.org.umbba.notification.config.scheduler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.TaskScheduler; +import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import sopt.org.umbbaServer.global.util.fcm.FCMService; +import sopt.org.umbba.notification.service.fcm.FCMService; import java.util.concurrent.ThreadPoolExecutor; @@ -12,6 +13,7 @@ * 특정 시간대에 알림을 보내주기 위해 Spring이 제공하는 TaskScheduler를 빈으로 등록 */ @Configuration +@EnableScheduling public class ScheduleConfig { private static final int POOL_SIZE = 10; diff --git a/umbba-notification/src/main/java/sopt/org/umbba/notification/config/sqs/SqsConfig.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/config/sqs/SqsConfig.java new file mode 100644 index 00000000..8aa52b01 --- /dev/null +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/config/sqs/SqsConfig.java @@ -0,0 +1,34 @@ +package sopt.org.umbba.notification.config.sqs; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.sqs.AmazonSQSAsync; +import com.amazonaws.services.sqs.AmazonSQSAsyncClient; +import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class SqsConfig { + + @Value("${cloud.aws.credentials.accessKey}") + private String AWS_ACCESS_KEY; + + @Value("${cloud.aws.credentials.secretKey}") + private String AWS_SECRET_KEY; + + @Value("${cloud.aws.region.static}") + private String AWS_REGION; + + @Primary + @Bean + public AmazonSQSAsync amazonSQSAsync() { + BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY); + return AmazonSQSAsyncClientBuilder.standard() + .withRegion(AWS_REGION) + .withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials)) + .build(); + } +} diff --git a/umbba-notification/src/main/java/sopt/org/umbba/notification/config/sqs/consumer/SqsConsumer.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/config/sqs/consumer/SqsConsumer.java new file mode 100644 index 00000000..c55a1309 --- /dev/null +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/config/sqs/consumer/SqsConsumer.java @@ -0,0 +1,66 @@ +package sopt.org.umbba.notification.config.sqs.consumer; + +import com.amazonaws.services.sqs.AmazonSQS; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.aws.messaging.listener.Acknowledgment; +import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy; +import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener; +import org.springframework.messaging.handler.annotation.Headers; +import org.springframework.messaging.handler.annotation.Payload; +import org.springframework.stereotype.Component; +import sopt.org.umbba.common.sqs.MessageType; +import sopt.org.umbba.common.sqs.MessageUtils; +import sopt.org.umbba.common.sqs.dto.FCMPushRequestDto; +import sopt.org.umbba.common.sqs.dto.FirebaseDto; +import sopt.org.umbba.common.sqs.dto.SlackDto; +import sopt.org.umbba.notification.service.fcm.FCMService; +import sopt.org.umbba.notification.service.slack.SlackApi; + +import javax.websocket.SendResult; +import java.util.Map; + +/** + * 큐 대기열에 있는 메시지 목록을 조회하여 받아오는(pull) 역할 + * + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class SqsConsumer { + + private final ObjectMapper objectMapper; + private final FCMService fcmService; + private final SlackApi slackApi; + private static final String SQS_CONSUME_LOG_MESSAGE = + "====> [SQS Queue Response]\n" + "info: %s\n" + "header: %s\n"; + + + // SQS로부터 메시지를 받는 Listener | 메시지를 받은 이후의 삭제 정책을 NEVER로 지정 + // -> 절대 삭제 요청을 보내지 않고, ack 메서드를 호출할 때 삭제 요청을 보냄 + @SqsListener(value = "${cloud.aws.sqs.notification.name}", deletionPolicy = SqsMessageDeletionPolicy.NEVER) + public void consume(@Payload String payload, @Headers Map headers, Acknowledgment ack) { + try { + log.info(MessageUtils.generate(SQS_CONSUME_LOG_MESSAGE, payload, headers)); + + switch (headers.get(MessageType.MESSAGE_TYPE_HEADER)) { + + case MessageType.FIREBASE: + FCMPushRequestDto request = objectMapper.readValue(payload, FCMPushRequestDto.class); + fcmService.pushAlarm(request); // TODO userId 를 넘겨주는 방식 대신 어떻게 유저 식별할지? + break; + + case MessageType.SLACK: + SlackDto slackDto = objectMapper.readValue(payload, SlackDto.class); + slackApi.sendAlert(slackDto.getError(), slackDto.getRequestMethod(), slackDto.getRequestURI()); + break; + } + } catch (Exception e) { + log.error(e.getMessage(), e); + } + + ack.acknowledge(); + } + +} \ No newline at end of file diff --git a/src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/FCMController.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/FCMController.java similarity index 78% rename from src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/FCMController.java rename to umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/FCMController.java index cbc994cb..5d65b1a9 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/FCMController.java +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/FCMController.java @@ -1,14 +1,13 @@ -package sopt.org.umbbaServer.global.util.fcm.controller; +package sopt.org.umbba.notification.service.fcm; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import sopt.org.umbbaServer.global.common.dto.ApiResponse; -import sopt.org.umbbaServer.global.config.jwt.JwtProvider; -import sopt.org.umbbaServer.global.exception.SuccessType; -import sopt.org.umbbaServer.global.util.fcm.FCMScheduler; -import sopt.org.umbbaServer.global.util.fcm.FCMService; -import sopt.org.umbbaServer.global.util.fcm.controller.dto.FCMPushRequestDto; +import sopt.org.umbba.common.exception.SuccessType; +import sopt.org.umbba.common.exception.dto.ApiResponse; +import sopt.org.umbba.common.sqs.dto.FCMPushRequestDto; +import sopt.org.umbba.notification.service.fcm.FCMService; +import sopt.org.umbba.notification.service.scheduler.FCMScheduler; import java.io.IOException; import java.security.Principal; @@ -49,7 +48,7 @@ public ApiResponse sendTopicScheduledTest() { @ResponseStatus(HttpStatus.OK) public ApiResponse sendNotificationByToken(@RequestBody FCMPushRequestDto request, Principal principal) throws IOException { - return ApiResponse.success(SuccessType.PUSH_ALARM_SUCCESS, fcmService.pushAlarm(request, JwtProvider.getUserFromPrincial(principal))); + return ApiResponse.success(SuccessType.PUSH_ALARM_SUCCESS, fcmService.pushAlarm(request)); } /** diff --git a/src/main/java/sopt/org/umbbaServer/global/util/fcm/FCMService.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/FCMService.java similarity index 91% rename from src/main/java/sopt/org/umbbaServer/global/util/fcm/FCMService.java rename to umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/FCMService.java index 755966ee..7971f0ae 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/fcm/FCMService.java +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/FCMService.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.util.fcm; +package sopt.org.umbba.notification.service.fcm; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -19,17 +19,17 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.DefaultTransactionDefinition; -import sopt.org.umbbaServer.domain.parentchild.dao.ParentchildDao; -import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; -import sopt.org.umbbaServer.domain.parentchild.repository.ParentchildRepository; -import sopt.org.umbbaServer.domain.qna.model.QnA; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.domain.user.repository.UserRepository; -import sopt.org.umbbaServer.domain.user.social.SocialPlatform; -import sopt.org.umbbaServer.global.exception.CustomException; -import sopt.org.umbbaServer.global.exception.ErrorType; -import sopt.org.umbbaServer.global.util.fcm.controller.dto.FCMMessage; -import sopt.org.umbbaServer.global.util.fcm.controller.dto.FCMPushRequestDto; +import sopt.org.umbba.common.exception.ErrorType; +import sopt.org.umbba.common.exception.model.CustomException; +import sopt.org.umbba.domain.domain.parentchild.Parentchild; +import sopt.org.umbba.domain.domain.parentchild.dao.ParentchildDao; +import sopt.org.umbba.domain.domain.parentchild.repository.ParentchildRepository; +import sopt.org.umbba.domain.domain.qna.QnA; +import sopt.org.umbba.domain.domain.user.SocialPlatform; +import sopt.org.umbba.domain.domain.user.User; +import sopt.org.umbba.domain.domain.user.repository.UserRepository; +import sopt.org.umbba.notification.service.fcm.dto.FCMMessage; +import sopt.org.umbba.common.sqs.dto.FCMPushRequestDto; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @@ -39,6 +39,9 @@ import java.util.List; import java.util.concurrent.ScheduledFuture; +/** + * 서버에서 파이어베이스로 전송이 잘 이루어지는지 테스트하기 위한 컨트롤러 + */ @Slf4j @Service @RequiredArgsConstructor @@ -121,13 +124,7 @@ String makeMessage(FCMPushRequestDto request, Long userId) throws FirebaseMessag // FCM Service에 메시지를 수신하는 함수 (헤더와 바디 직접 만들기) -> 상대 답변 알람 전송에 사용 @Transactional - public String pushAlarm(FCMPushRequestDto request, Long userId) throws IOException { - - // TODO 같은 Parentchild ID를 가진 User를 찾은 후, 이들에 대한 토큰 리스트로 동일한 알림 메시지 전송하도록 - User user = userRepository.findById(userId).orElseThrow( - () -> new CustomException(ErrorType.INVALID_USER) - ); - user.updateFcmToken(request.getTargetToken()); + public String pushAlarm(FCMPushRequestDto request) throws IOException { String message = makeMessage(request); sendPushMessage(message); @@ -235,7 +232,6 @@ public void schedulePushAlarm(String cronExpression, Long parentchildId) { QnA todayQnA = parentchild.getQnaList().get(parentchild.getCount() - 1); // em.close(); - log.info("\n Current QnA: {} \n Today QnA: {}", currentQnA.getId(), todayQnA.getId()); if (todayQnA == null) { log.error("{}번째 Parentchild의 QnaList가 존재하지 않음!", parentchild.getId()); diff --git a/src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/FCMMessage.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/dto/FCMMessage.java similarity index 97% rename from src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/FCMMessage.java rename to umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/dto/FCMMessage.java index e363ef28..d7ebeafa 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/fcm/controller/dto/FCMMessage.java +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/fcm/dto/FCMMessage.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.util.fcm.controller.dto; +package sopt.org.umbba.notification.service.fcm.dto; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/sopt/org/umbbaServer/global/util/fcm/FCMScheduler.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/scheduler/FCMScheduler.java similarity index 78% rename from src/main/java/sopt/org/umbbaServer/global/util/fcm/FCMScheduler.java rename to umbba-notification/src/main/java/sopt/org/umbba/notification/service/scheduler/FCMScheduler.java index 57083e6f..a03be6bb 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/fcm/FCMScheduler.java +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/scheduler/FCMScheduler.java @@ -1,17 +1,16 @@ -package sopt.org.umbbaServer.global.util.fcm; +package sopt.org.umbba.notification.service.scheduler; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.RestController; -import sopt.org.umbbaServer.domain.parentchild.dao.ParentchildDao; -import sopt.org.umbbaServer.domain.parentchild.repository.ParentchildRepository; -import sopt.org.umbbaServer.domain.user.model.User; -import sopt.org.umbbaServer.domain.user.repository.UserRepository; -import sopt.org.umbbaServer.domain.user.social.SocialPlatform; -import sopt.org.umbbaServer.global.util.fcm.controller.dto.FCMPushRequestDto; + +import sopt.org.umbba.domain.domain.parentchild.dao.ParentchildDao; +import sopt.org.umbba.domain.domain.parentchild.repository.ParentchildRepository; +import sopt.org.umbba.domain.domain.user.SocialPlatform; +import sopt.org.umbba.domain.domain.user.User; +import sopt.org.umbba.domain.domain.user.repository.UserRepository; +import sopt.org.umbba.notification.service.fcm.FCMService; import java.util.List; diff --git a/src/main/java/sopt/org/umbbaServer/global/util/slack/SlackApi.java b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/slack/SlackApi.java similarity index 87% rename from src/main/java/sopt/org/umbbaServer/global/util/slack/SlackApi.java rename to umbba-notification/src/main/java/sopt/org/umbba/notification/service/slack/SlackApi.java index 0030e4f8..22249112 100644 --- a/src/main/java/sopt/org/umbbaServer/global/util/slack/SlackApi.java +++ b/umbba-notification/src/main/java/sopt/org/umbba/notification/service/slack/SlackApi.java @@ -1,4 +1,4 @@ -package sopt.org.umbbaServer.global.util.slack; +package sopt.org.umbba.notification.service.slack; import com.slack.api.Slack; import com.slack.api.model.block.Blocks; @@ -32,7 +32,7 @@ public class SlackApi { // Slack으로 알림 보내기 - public void sendAlert(Exception error, HttpServletRequest request) throws IOException { + public void sendAlert(Exception error, String requestMethod, String requestURI) throws IOException { // 현재 프로파일이 특정 프로파일이 아니면 알림보내지 않기 // if (!env.getActiveProfiles()[0].equals("set1")) { @@ -40,7 +40,7 @@ public void sendAlert(Exception error, HttpServletRequest request) throws IOExce // } // 메시지 내용인 LayoutBlock List 생성 - List layoutBlocks = generateLayoutBlock(error, request); + List layoutBlocks = generateLayoutBlock(error, requestMethod, requestURI); // 슬랙의 send API과 webhookURL을 통해 생성한 메시지 내용 전송 Slack.getInstance().send(webhookUrl, WebhookPayloads @@ -54,13 +54,13 @@ public void sendAlert(Exception error, HttpServletRequest request) throws IOExce } // 전체 메시지가 담긴 LayoutBlock 생성 - private List generateLayoutBlock(Exception error, HttpServletRequest request) { + private List generateLayoutBlock(Exception error, String requestMethod, String requestURI) { return Blocks.asBlocks( getHeader("서버 측 오류로 예상되는 예외 상황이 발생하였습니다."), Blocks.divider(), getSection(generateErrorMessage(error)), Blocks.divider(), - getSection(generateErrorPointMessage(request)), + getSection(generateErrorPointMessage(requestMethod, requestURI)), Blocks.divider(), // 이슈 생성을 위해 프로젝트의 Issue URL을 입력하여 바로가기 링크를 생성 getSection("") @@ -77,11 +77,11 @@ private String generateErrorMessage(Exception error) { } // HttpServletRequest를 사용하여 예외발생 요청에 대한 정보 메시지 생성 - private String generateErrorPointMessage(HttpServletRequest request) { + private String generateErrorPointMessage(String requestMethod, String requestURI) { sb.setLength(0); sb.append("*[🧾세부정보]*" + NEW_LINE); - sb.append("Request URL : " + request.getRequestURL().toString() + NEW_LINE); - sb.append("Request Method : " + request.getMethod() + NEW_LINE); + sb.append("Request URL : " + requestURI + NEW_LINE); + sb.append("Request Method : " + requestMethod + NEW_LINE); sb.append("Request Time : " + new Date() + NEW_LINE); return sb.toString(); diff --git a/umbba-notification/src/main/resources/application.yaml b/umbba-notification/src/main/resources/application.yaml new file mode 100644 index 00000000..93c96e4d --- /dev/null +++ b/umbba-notification/src/main/resources/application.yaml @@ -0,0 +1,81 @@ +cloud: + aws: + credentials: + accessKey: ${cloud-access} + secretKey: ${cloud-secret} + region: + static: ${cloud-region} + s3: + bucket: ${bucket-name} + stack: + auto: false + sqs: + notification: + name: ${sqs-notification-name} + url: ${sqs-notification-url} + #api: + # name: ${sqs-api-name} + # url: ${sqs-api-url} + + +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: ${db-url} + username: ${db-user} + password: ${db-pwd} + hikari: + pool-name: Hikari 커넥션 풀 # Pool + connection-timeout: 30000 # 30초(default: 30초) + maximum-pool-size: 10 # default: 10개 + max-lifetime: 600000 # 10분(default: 30분) + leak-detection-threshold: 2000 # default: 0(이용X) + jpa: + show-sql: false + hibernate: + ddl-auto: update + ejb: + naming_strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy + properties: + hibernate: + format_sql: false + +kakao: + client-id: ${kakao-id} + authorization-grant-type: authorization_code + redirect-uri: ${kakao-redirect} + +apple: + iss: ${apple-iss} + client-id: ${apple-id} +# nonce: ${apple-nonce} + +jwt: + secret: ${jwt-secret} + +slack: + webhook: + url: ${slack-url} + +fcm: + key: + path: ${fcm-json-path} + scope: ${fcm-scope} + # firebase-create-scoped: "https://www.googleapis.com/auth/firebase.messaging" + api: + url: ${fcm-api-url} + topic: + "qna_notification" + +logging: + level: + org: + hibernate: + type: + descriptor: + sql: debug + com.zaxxer.hikari.pool.HikariPool: debug + + +server: + port: 9092 \ No newline at end of file