From bc2b5c21462bc514e0f221fe1731daabe0dd9ad2 Mon Sep 17 00:00:00 2001 From: dragontaek-lee Date: Wed, 15 May 2024 02:01:59 +0900 Subject: [PATCH 01/15] =?UTF-8?q?feat:=20dev=20CD=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=EC=84=B8=EC=8A=A4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-develop.yml | 96 ++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/cd-develop.yml diff --git a/.github/workflows/cd-develop.yml b/.github/workflows/cd-develop.yml new file mode 100644 index 00000000..948ae932 --- /dev/null +++ b/.github/workflows/cd-develop.yml @@ -0,0 +1,96 @@ +# 워크플로우의 이름 지정 +name: Gam-dev-server CD + +# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 +on: + push: + branches: [ develop ] + +env: + S3_BUCKET_NAME: gam-dev-deploy + +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 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + # 3) 환경변수 파일 생성 + - name: make application.properties 파일 생성 + run: | + ## create application.yml + cd ./src/main/resources + + # application.yml 파일 생성 + touch ./application-dev.yml + + # GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기 + echo "${{ secrets.GAM_DEV_APPLICATION }}" >> ./application-dev.yml + + # application.yml 파일 확인 + cat ./application-dev.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 build -x test + + # 디렉토리 생성 + - name: Make Directory + run: mkdir -p deploy + + # Jar 파일 복사 + - name: Copy Jar + run: cp ./build/libs/*.jar ./deploy + + # appspec.yml 파일 복사 + - name: Copy appspec.yml + run: cp appspec.yml ./deploy + + # script files 복사 + - name: Copy script + run: cp ./scripts/*.sh ./deploy + + - name: Make zip file + run: zip -r ./gam-dev-server.zip ./deploy + shell: bash + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_CONFIG_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_CONFIG_SECRET_KEY }} + aws-region: ap-northeast-2 + + - name: Upload to S3 + run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{ secrets.AWS_S3_BUCKET_NAME }}/dev/$GITHUB_SHA.zip + + # Deploy + - name: Deploy + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_CONFIG_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_CONFIG_SECRET_KEY }} + run: + aws deploy create-deployment + --application-name gam-codeDeploy + --deployment-group-name dev + --file-exists-behavior OVERWRITE + --s3-location bucket=${{ secrets.AWS_S3_BUCKET_NAME }},bundleType=zip,key=prod/$GITHUB_SHA.zip + --region ap-northeast-2 From e3d06352098392f32d0cdbc2f759681f4b8b269c Mon Sep 17 00:00:00 2001 From: dragontaek-lee Date: Wed, 15 May 2024 02:33:47 +0900 Subject: [PATCH 02/15] =?UTF-8?q?fix:=20s3=20key=EA=B0=92=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CD.yml | 96 -------------------------------- .github/workflows/cd-develop.yml | 2 +- appspec.yml | 3 - scripts/deploy.sh | 34 +++-------- scripts/switch.sh | 34 ----------- 5 files changed, 8 insertions(+), 161 deletions(-) delete mode 100644 .github/workflows/CD.yml delete mode 100644 scripts/switch.sh diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml deleted file mode 100644 index d9b44cd0..00000000 --- a/.github/workflows/CD.yml +++ /dev/null @@ -1,96 +0,0 @@ -# 워크플로우의 이름 지정 -name: Gam-dev-server CD - -# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 -on: - push: - branches: [ develop ] - -env: - S3_BUCKET_NAME: gam-dev-deploy - -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 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - # 3) 환경변수 파일 생성 - - name: make application.properties 파일 생성 - run: | - ## create application.yml - cd ./src/main/resources - - # application.yml 파일 생성 - touch ./application-dev.yml - - # GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기 - echo "${{ secrets.GAM_DEV_APPLICATION }}" >> ./application-dev.yml - - # application.yml 파일 확인 - cat ./application-dev.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 build -x test - - # 디렉토리 생성 - - name: Make Directory - run: mkdir -p deploy - - # Jar 파일 복사 - - name: Copy Jar - run: cp ./build/libs/*.jar ./deploy - - # appspec.yml 파일 복사 - - name: Copy appspec.yml - run: cp appspec.yml ./deploy - - # script files 복사 - - name: Copy script - run: cp ./scripts/*.sh ./deploy - - - name: Make zip file - run: zip -r ./gam-dev-server.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 ./gam-dev-server.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 gam-dev-codedeploy - --deployment-group-name gam-dev-server-codedeploy-group - --file-exists-behavior OVERWRITE - --s3-location bucket=gam-dev-deploy,bundleType=zip,key=gam-dev-server.zip - --region ap-northeast-2 diff --git a/.github/workflows/cd-develop.yml b/.github/workflows/cd-develop.yml index 948ae932..497a29b8 100644 --- a/.github/workflows/cd-develop.yml +++ b/.github/workflows/cd-develop.yml @@ -92,5 +92,5 @@ jobs: --application-name gam-codeDeploy --deployment-group-name dev --file-exists-behavior OVERWRITE - --s3-location bucket=${{ secrets.AWS_S3_BUCKET_NAME }},bundleType=zip,key=prod/$GITHUB_SHA.zip + --s3-location bucket=${{ secrets.AWS_S3_BUCKET_NAME }},bundleType=zip,key=dev/$GITHUB_SHA.zip --region ap-northeast-2 diff --git a/appspec.yml b/appspec.yml index 6e814a98..44c46f6a 100644 --- a/appspec.yml +++ b/appspec.yml @@ -17,6 +17,3 @@ hooks: - location: deploy.sh timeout: 60 runas: ubuntu - - location: switch.sh - timeout: 180 - runas: ubuntu diff --git a/scripts/deploy.sh b/scripts/deploy.sh index e8f65838..bb0b06b8 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -2,35 +2,15 @@ REPOSITORY=/home/ubuntu/app BUILD_PATH=$(ls /home/ubuntu/app/*SNAPSHOT.jar) JAR_NAME=$(basename $BUILD_PATH) -echo "> build 파일명: $JAR_NAME" IDLE_APPLICATION_PATH=/home/ubuntu/app/${JAR_NAME} -CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1) -TARGET_PORT=0 +TARGET_PORT=8080 -echo "> Current port of running WAS is ${CURRENT_PORT}." - -if [ ${CURRENT_PORT} -eq 8081 ]; then - TARGET_PORT=8082 -elif [ ${CURRENT_PORT} -eq 8082 ]; then - TARGET_PORT=8081 -else - echo "> No WAS is connected to nginx" +if [ "$DEPLOYMENT_GROUP_NAME" == "prod" ] +then + nohup java -jar -Duser.timezone=Asia/Seoul -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 & fi -echo "> Target port is ${TARGET_PORT}." - -TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') -echo "> Target PID is ${TARGET_PID}." -if [ ! -z ${TARGET_PID} ]; then - echo "> Kill WAS running at ${TARGET_PORT}." - sudo kill ${TARGET_PID} +if [ "$DEPLOYMENT_GROUP_NAME" == "dev" ] +then + nohup java -jar -Duser.timezone=Asia/Seoul -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 & fi - -nohup java -jar -Duser.timezone=Asia/Seoul -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 & -echo "> Running port is ${TARGET_PORT}." - -echo "> Running PID is" -lsof -i TCP:${TARGET_PORT} - - -echo "> Now new WAS runs at ${TARGET_PORT}." diff --git a/scripts/switch.sh b/scripts/switch.sh deleted file mode 100644 index 1fe48ebd..00000000 --- a/scripts/switch.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -echo "> lsof -i TCP:8080-8085" -lsof -i TCP:8080-8085 - -CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1) -TARGET_PORT=0 - -echo "> Nginx currently proxies to ${CURRENT_PORT}." - -if [ ${CURRENT_PORT} -eq 8081 ]; then - TARGET_PORT=8082 -elif [ ${CURRENT_PORT} -eq 8082 ]; then - TARGET_PORT=8081 -else - echo "> No WAS is connected to nginx" - exit 1 -fi - -echo "set \$service_url http://127.0.0.1:${TARGET_PORT};" |sudo tee /etc/nginx/conf.d/service-url.inc - -echo "> Now Nginx proxies to ${TARGET_PORT}." - -sudo service nginx reload - -echo "> Nginx reloaded." - -CURRENT_PID=$(lsof -Fp -i TCP:${CURRENT_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') -echo "> kill ${CURRENT_PID}" - -sudo kill ${CURRENT_PID} - -echo "> lsof -i TCP:8080-8085" -lsof -i TCP:8080-8085 From 1c581a00640e429155418ef7549205095c4c86e9 Mon Sep 17 00:00:00 2001 From: dragontaek-lee Date: Wed, 15 May 2024 02:45:34 +0900 Subject: [PATCH 03/15] =?UTF-8?q?fix:=20zip=20=EC=95=94=ED=98=B8=ED=99=94?= =?UTF-8?q?=20=EB=88=84=EB=9D=BD=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-develop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-develop.yml b/.github/workflows/cd-develop.yml index 497a29b8..90e5466d 100644 --- a/.github/workflows/cd-develop.yml +++ b/.github/workflows/cd-develop.yml @@ -69,7 +69,7 @@ jobs: run: cp ./scripts/*.sh ./deploy - name: Make zip file - run: zip -r ./gam-dev-server.zip ./deploy + run: zip -r ./$GITHUB_SHA.zip ./deploy shell: bash - name: Configure AWS credentials From a25c1ef8f8b6c3449e240924d0507df3cb190849 Mon Sep 17 00:00:00 2001 From: kjy Date: Fri, 31 May 2024 17:51:15 +0900 Subject: [PATCH 04/15] =?UTF-8?q?fix:=20=EB=AA=A8=EB=93=A0=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=EB=AC=BC=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/UserDiscoveryResponseDTO.java | 2 + .../domain/user/service/UserServiceImpl.java | 54 ++++++++++--------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/gam/api/domain/user/dto/response/UserDiscoveryResponseDTO.java b/src/main/java/com/gam/api/domain/user/dto/response/UserDiscoveryResponseDTO.java index 96c006f0..e5d6ab90 100644 --- a/src/main/java/com/gam/api/domain/user/dto/response/UserDiscoveryResponseDTO.java +++ b/src/main/java/com/gam/api/domain/user/dto/response/UserDiscoveryResponseDTO.java @@ -5,6 +5,8 @@ import com.gam.api.domain.work.entity.Work; import lombok.Builder; +import java.time.LocalDateTime; + @Builder public record UserDiscoveryResponseDTO( UserInfoVO UserInfo, diff --git a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java index 674bb032..fc829b20 100644 --- a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java @@ -290,32 +290,36 @@ public List getDiscoveryUsers(Long userId, int[] tags) users = userRepository.findAllDiscoveryUserWithTag(userId, tags); } - return users.stream().map((dto) -> { - val firstWorkId = dto.user().getFirstWorkId(); - Work firstWork; - - if (firstWorkId == null && !dto.user().getActiveWorks().isEmpty()) { // User 권한 에러 - firstWork = workRepository.findFirstByUserIdAndIsActiveOrderByCreatedAtDesc(dto.user().getId(), true) - .orElse(Work.builder() - .user(dto.user()) - .photoUrl("해당하는 작업물을 찾을 수 없습니다.") - .detail("해당하는 작업물을 찾을 수 없습니다.") - .title("해당하는 작업물을 찾을 수 없습니다.") - .build()); - dto.user().setUserStatus(UserStatus.NOT_PERMITTED); - } - else { - firstWork = dto.user().getActiveWorks().stream() - .filter(work -> dto.user().getFirstWorkId().equals(work.getId())) - .findFirst().get(); - } + Map scrapMap = new HashMap(); + for (UserScrapUserQueryDto user:users) { + scrapMap.put(user.user(), user.scrapStatus()); + } - val userScrap = dto.scrapStatus(); - if (Objects.isNull(userScrap)) { - return UserDiscoveryResponseDTO.of(dto.user(), false, firstWork); - } - return UserDiscoveryResponseDTO.of(dto.user(), userScrap, firstWork); - }).collect(Collectors.toList()); + List workAll = new LinkedList(); + + for (UserScrapUserQueryDto user:users) { + workAll.addAll(workRepository.findAllByUserId(user.user().getId())); + } + workAll.stream().sorted(); + +// List userDiscoveryResponseDTOS = users.stream().map((dto) -> { +// val targetUserId = dto.user().getId(); +// List works = workRepository.findAllByUserId(targetUserId); +// +// val userScrap = dto.scrapStatus(); +// List responseDTOs = new ArrayList<>(); +// +// for (Work work : works) { +// if (Objects.isNull(userScrap)) { +// responseDTOs.add(UserDiscoveryResponseDTO.of(dto.user(), false, work)); +// } else { +// responseDTOs.add(UserDiscoveryResponseDTO.of(dto.user(), userScrap, work)); +// } +// } +// return responseDTOs; +// }).flatMap(Collection::stream).collect(Collectors.toList()); +// +// return userDiscoveryResponseDTOS; } From 57c3c1b5f1bb0d2a6222e15256bc2ea6f60ec33c Mon Sep 17 00:00:00 2001 From: dragontaek-lee Date: Sat, 1 Jun 2024 12:13:15 +0900 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20=EA=B8=B0=EC=A1=B4=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=ED=8F=AC=ED=8A=B8=20=EC=A2=85=EB=A3=8C=20=EC=A0=84?= =?UTF-8?q?=EB=9E=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index bb0b06b8..a1abef5b 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -5,6 +5,9 @@ JAR_NAME=$(basename $BUILD_PATH) IDLE_APPLICATION_PATH=/home/ubuntu/app/${JAR_NAME} TARGET_PORT=8080 +CURRENT_PID=$(lsof -Fp -i TCP:${CURRENT_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') +sudo kill ${CURRENT_PID} + if [ "$DEPLOYMENT_GROUP_NAME" == "prod" ] then nohup java -jar -Duser.timezone=Asia/Seoul -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 & From cdc1774ff3395c75bfee721ff9bd2ae4453a1158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A3=BC=EC=98=81?= Date: Sat, 1 Jun 2024 18:58:09 +0900 Subject: [PATCH 06/15] =?UTF-8?q?fix:=20=EB=AA=A8=EB=93=A0=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=EB=AC=BC=20=EC=A1=B0=ED=9A=8C=EB=A1=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserServiceImpl.java | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java index fc829b20..872898dc 100644 --- a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java @@ -283,43 +283,35 @@ public WorkPortfolioGetResponseDTO getPortfolio(Long requestUserId, Long userId) public List getDiscoveryUsers(Long userId, int[] tags){ List users; - if (tags.length == 0) { + if (tags.length == 0) { // user 정보 조회 태그가 걸린 경우와 아닌 경우 users = userRepository.findAllDiscoveryUser(userId); //TODO - user 관련 쿼리 잡기 , 동적 쿼리 필요,, } else { users = userRepository.findAllDiscoveryUserWithTag(userId, tags); } - Map scrapMap = new HashMap(); + Map scrapMap = new HashMap(); // user 별 스크랩 한 경우와 아닌 경우 식별을 위한 map for (UserScrapUserQueryDto user:users) { scrapMap.put(user.user(), user.scrapStatus()); } List workAll = new LinkedList(); - for (UserScrapUserQueryDto user:users) { + for (UserScrapUserQueryDto user:users) { // 모든 work 가져오는 로직 -> 이 부분 어떻게 수정해야 할 지 고민을 해봐야 할 것 같아요 workAll.addAll(workRepository.findAllByUserId(user.user().getId())); } - workAll.stream().sorted(); - -// List userDiscoveryResponseDTOS = users.stream().map((dto) -> { -// val targetUserId = dto.user().getId(); -// List works = workRepository.findAllByUserId(targetUserId); -// -// val userScrap = dto.scrapStatus(); -// List responseDTOs = new ArrayList<>(); -// -// for (Work work : works) { -// if (Objects.isNull(userScrap)) { -// responseDTOs.add(UserDiscoveryResponseDTO.of(dto.user(), false, work)); -// } else { -// responseDTOs.add(UserDiscoveryResponseDTO.of(dto.user(), userScrap, work)); -// } -// } -// return responseDTOs; -// }).flatMap(Collection::stream).collect(Collectors.toList()); -// -// return userDiscoveryResponseDTOS; + + workAll = workAll.stream() // 최근 수정된 날짜 기준 정리 + .sorted(Comparator.comparing(Work::getModifiedAt).reversed()) + .collect(Collectors.toList()); + + return workAll.stream().map((work) -> { + val userScrap = scrapMap.get(work.getUser()); + if (Objects.isNull(userScrap)) { + return UserDiscoveryResponseDTO.of(work.getUser(), false, work); + } + return UserDiscoveryResponseDTO.of(work.getUser(), userScrap, work); + }).collect(Collectors.toList()); } From 657ff2713af494e70457295d244458c8112cdc7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A3=BC=EC=98=81?= Date: Sat, 1 Jun 2024 19:18:02 +0900 Subject: [PATCH 07/15] =?UTF-8?q?fix:=20=EC=BF=BC=EB=A6=AC=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94=20=ED=8A=9C=EB=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/gam/api/domain/user/entity/User.java | 1 + .../com/gam/api/domain/user/service/UserServiceImpl.java | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gam/api/domain/user/entity/User.java b/src/main/java/com/gam/api/domain/user/entity/User.java index 10206b8f..75ea5f00 100644 --- a/src/main/java/com/gam/api/domain/user/entity/User.java +++ b/src/main/java/com/gam/api/domain/user/entity/User.java @@ -99,6 +99,7 @@ public class User extends TimeStamped { @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) List magazineScraps = new ArrayList<>(); + @Where(clause = "is_active = true") @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) List works = new ArrayList<>(); diff --git a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java index 872898dc..3de8fc7a 100644 --- a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java @@ -297,10 +297,11 @@ public List getDiscoveryUsers(Long userId, int[] tags) List workAll = new LinkedList(); - for (UserScrapUserQueryDto user:users) { // 모든 work 가져오는 로직 -> 이 부분 어떻게 수정해야 할 지 고민을 해봐야 할 것 같아요 - workAll.addAll(workRepository.findAllByUserId(user.user().getId())); + for (UserScrapUserQueryDto dto:users) { // 모든 work 가져오는 로직 -> 이 부분 어떻게 수정해야 할 지 고민을 해봐야 할 것 같아요 + workAll.addAll(dto.user().getWorks()); } + workAll = workAll.stream() // 최근 수정된 날짜 기준 정리 .sorted(Comparator.comparing(Work::getModifiedAt).reversed()) .collect(Collectors.toList()); From ba7f008ad5a42e86b237ee4e37e1821eb5d5a394 Mon Sep 17 00:00:00 2001 From: kjy Date: Tue, 4 Jun 2024 13:32:46 +0900 Subject: [PATCH 08/15] =?UTF-8?q?feat:=20stream,=20flatMap=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/UserDiscoveryResponseDTO.java | 2 -- .../domain/user/service/UserServiceImpl.java | 22 ++++++------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/gam/api/domain/user/dto/response/UserDiscoveryResponseDTO.java b/src/main/java/com/gam/api/domain/user/dto/response/UserDiscoveryResponseDTO.java index e5d6ab90..96c006f0 100644 --- a/src/main/java/com/gam/api/domain/user/dto/response/UserDiscoveryResponseDTO.java +++ b/src/main/java/com/gam/api/domain/user/dto/response/UserDiscoveryResponseDTO.java @@ -5,8 +5,6 @@ import com.gam.api.domain.work.entity.Work; import lombok.Builder; -import java.time.LocalDateTime; - @Builder public record UserDiscoveryResponseDTO( UserInfoVO UserInfo, diff --git a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java index 3de8fc7a..9311f53b 100644 --- a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java @@ -290,24 +290,16 @@ public List getDiscoveryUsers(Long userId, int[] tags) users = userRepository.findAllDiscoveryUserWithTag(userId, tags); } - Map scrapMap = new HashMap(); // user 별 스크랩 한 경우와 아닌 경우 식별을 위한 map - for (UserScrapUserQueryDto user:users) { - scrapMap.put(user.user(), user.scrapStatus()); - } - - List workAll = new LinkedList(); - - for (UserScrapUserQueryDto dto:users) { // 모든 work 가져오는 로직 -> 이 부분 어떻게 수정해야 할 지 고민을 해봐야 할 것 같아요 - workAll.addAll(dto.user().getWorks()); - } - - - workAll = workAll.stream() // 최근 수정된 날짜 기준 정리 + Map scrapMap = users.stream() + .collect(Collectors.toMap(UserScrapUserQueryDto::user, UserScrapUserQueryDto::scrapStatus)); + // 모든 work를 가져와 최근 수정된 날짜 기준으로 정리 + List workAll = users.stream() + .flatMap(dto -> dto.user().getWorks().stream()) .sorted(Comparator.comparing(Work::getModifiedAt).reversed()) - .collect(Collectors.toList()); + .toList(); return workAll.stream().map((work) -> { - val userScrap = scrapMap.get(work.getUser()); + val userScrap = scrapMap.get(work.getUser().getId()); if (Objects.isNull(userScrap)) { return UserDiscoveryResponseDTO.of(work.getUser(), false, work); } From 81ddd5987944b60cfb2e2e19fc38b52409261d92 Mon Sep 17 00:00:00 2001 From: gahee99 Date: Tue, 4 Jun 2024 22:52:06 +0900 Subject: [PATCH 09/15] =?UTF-8?q?hotfix:=20=EB=A7=A4=EA=B1=B0=EC=A7=84=20-?= =?UTF-8?q?=20=EB=B0=9C=EA=B2=AC=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=20=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gam/api/domain/magazine/repository/MagazineRepository.java | 2 +- .../gam/api/domain/magazine/service/MagazineServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gam/api/domain/magazine/repository/MagazineRepository.java b/src/main/java/com/gam/api/domain/magazine/repository/MagazineRepository.java index 425226bc..8562a387 100644 --- a/src/main/java/com/gam/api/domain/magazine/repository/MagazineRepository.java +++ b/src/main/java/com/gam/api/domain/magazine/repository/MagazineRepository.java @@ -10,7 +10,7 @@ public interface MagazineRepository extends JpaRepository { Optional getMagazineById(Long magazineId); - List findMagazinesByOrderByViewCountDesc(); + List findMagazinesByOrderByCreatedAtDesc(); List findTop3ByOrderByViewCountDesc(); List findAllByOrderByModifiedAtDescCreatedAtDesc(); @Query("SELECT m FROM Magazine m WHERE LOWER(m.interviewPerson) LIKE LOWER(CONCAT('%', :interviewPersonKeyword, '%')) OR LOWER(m.magazineTitle) LIKE LOWER(CONCAT('%', :magazineTitleKeyword, '%')) ORDER BY m.createdAt DESC") diff --git a/src/main/java/com/gam/api/domain/magazine/service/MagazineServiceImpl.java b/src/main/java/com/gam/api/domain/magazine/service/MagazineServiceImpl.java index 8d28a4f5..2799a970 100644 --- a/src/main/java/com/gam/api/domain/magazine/service/MagazineServiceImpl.java +++ b/src/main/java/com/gam/api/domain/magazine/service/MagazineServiceImpl.java @@ -40,7 +40,7 @@ public class MagazineServiceImpl implements MagazineService { public MagazineResponseDTO getMagazines(Long userId) { val user = findUser(userId); val magazineScrapList = getMagazineScrapList(user); - val magazineList = magazineRepository.findMagazinesByOrderByViewCountDesc(); + val magazineList = magazineRepository.findMagazinesByOrderByCreatedAtDesc(); return MagazineResponseDTO.of(magazineList, magazineScrapList, gamConfig.getMagaineBaseUrl()); } From b73a76cfb6e2b3c74a0d0c99bf3f734212be02b2 Mon Sep 17 00:00:00 2001 From: GaHee99 <77230391+GaHee99@users.noreply.github.com> Date: Wed, 5 Jun 2024 00:28:32 +0900 Subject: [PATCH 10/15] =?UTF-8?q?hotfix:=20deploy.sh=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index a1abef5b..180a0fd9 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -4,6 +4,7 @@ BUILD_PATH=$(ls /home/ubuntu/app/*SNAPSHOT.jar) JAR_NAME=$(basename $BUILD_PATH) IDLE_APPLICATION_PATH=/home/ubuntu/app/${JAR_NAME} TARGET_PORT=8080 +CURRENT_PORT=8080 CURRENT_PID=$(lsof -Fp -i TCP:${CURRENT_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') sudo kill ${CURRENT_PID} From 5b7eb269ca8415a8bb4a8eae116f2d3df43b0683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A3=BC=EC=98=81?= <77871898+kjy-asl@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:48:16 +0900 Subject: [PATCH 11/15] Update README.md --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index e69de29b..4775935f 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,15 @@ +## ❤️ 기획 배경 + + +## 💻 주 기능 화면 + + +## ⚒️ Backend Introduction +### 📁 프로젝트 구조 +![KakaoTalk_20240605_104511643](https://github.com/Gam-develop/gam-server/assets/77871898/57b3e927-d73a-41dd-8c72-970b012147c7) + +### 📄 프로젝트 ERD + +### ⚒️ 사용 기술 스택 + +### 👨‍👦 백엔드 팀원 From 4665d9207723146577e7b52d4187d3d625510619 Mon Sep 17 00:00:00 2001 From: GaHee99 <77230391+GaHee99@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:25:45 +0900 Subject: [PATCH 12/15] Update README.md --- README.md | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4775935f..b25fccd1 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,61 @@ ## ❤️ 기획 배경 + 디자이너들의 '감'잡는 커뮤니티 플렛폼 `"GAM"`입니다.
+디자이너들이 모여, 크리에이티브한 작업물을 공유하고 소통하는 플렛폼 구축 을 목표로 하고 있습니다.
+디자이너 내 `'공유 문화'`를 확산하여, 디자인 커뮤니티의 성장과 발전을 촉진하며, 디자이너들의 위상과 가치를 높이고자 합니다.
+ +![image](https://github.com/Gam-develop/gam-server/assets/77230391/09393866-3c65-450b-ad8e-53e2ac486e5e) + +
+ +### ❕ 현재 진행상황 +2024년 6월 1차 릴리즈 준비중! +

-## 💻 주 기능 화면 ## ⚒️ Backend Introduction ### 📁 프로젝트 구조 ![KakaoTalk_20240605_104511643](https://github.com/Gam-develop/gam-server/assets/77871898/57b3e927-d73a-41dd-8c72-970b012147c7) +
+ ### 📄 프로젝트 ERD +![GAM_Erd](https://github.com/Gam-develop/gam-server/assets/77230391/a4c9f8ca-37ad-46f6-a722-8cab2be3a5bd) +
+ +
### ⚒️ 사용 기술 스택 +- Spring, Spring JPA, Spring Security, PostgreSQL, +- AWS - EC2, S3, RDS, Code Deploy, Presigned URL, ALB, WAF +- Nginx, Github Action, Swagger + +
### 👨‍👦 백엔드 팀원 + + + + + + +
+ + +
이용택(BE)

+
+ +
최가희(BE)

+
+ +
김주영(BE)

+
From 597afecc6d93ece6c8c717ac829a614ec5852ed3 Mon Sep 17 00:00:00 2001 From: GaHee99 Date: Wed, 5 Jun 2024 16:47:57 +0900 Subject: [PATCH 13/15] =?UTF-8?q?hotfix:=20=EC=9C=A0=EC=A0=80=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85=20-=20=EC=98=A8=EB=B3=B4=EB=94=A9?= =?UTF-8?q?=20=EC=A0=84=20=EA=B6=8C=ED=95=9C=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20:=20PERMITTED=20->=20NOT=5FPERMITTED?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gam/api/domain/social/service/SocialCommonServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gam/api/domain/social/service/SocialCommonServiceImpl.java b/src/main/java/com/gam/api/domain/social/service/SocialCommonServiceImpl.java index add6d837..9d8a57be 100644 --- a/src/main/java/com/gam/api/domain/social/service/SocialCommonServiceImpl.java +++ b/src/main/java/com/gam/api/domain/social/service/SocialCommonServiceImpl.java @@ -68,7 +68,7 @@ private SocialLoginResponseDTO SignUpAndLogin( ) { val user = userRepository.save(User.builder() .role(Role.USER) - .userStatus(UserStatus.PERMITTED) + .userStatus(UserStatus.NOT_PERMITTED) .build()); val userId = user.getId(); From 197cb98a80f8d684f2adba9a6e7a582f00166b97 Mon Sep 17 00:00:00 2001 From: GaHee99 Date: Wed, 5 Jun 2024 16:49:29 +0900 Subject: [PATCH 14/15] =?UTF-8?q?hotfix:=20=EC=9C=A0=EC=A0=80=20=EC=98=A8?= =?UTF-8?q?=EB=B3=B4=EB=94=A9=20=EA=B6=8C=ED=95=9C=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20:=20=EC=95=84=EB=AC=B4=EB=9F=B0=20?= =?UTF-8?q?=EC=9E=91=EC=97=85=20x=20->=20=EA=B6=8C=ED=95=9C=20PERMITTED?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gam/api/domain/user/service/UserServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java index 9311f53b..b0bcd46e 100644 --- a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java @@ -191,6 +191,7 @@ public void onboardUser(Long userId, UserOnboardRequestDTO userOnboardRequestDTO createUserTags(tags, user); user.onboardUser(userName, info, tags); + user.setUserStatus(UserStatus.PERMITTED); } @Override From a3df2f502dc4321f84c5097df1aa64c685aa30d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A3=BC=EC=98=81?= <77871898+kjy-asl@users.noreply.github.com> Date: Sat, 8 Jun 2024 14:28:05 +0900 Subject: [PATCH 15/15] =?UTF-8?q?fix:=20=EB=B0=9C=EA=B2=AC-=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20return=20=EA=B0=92=20=EB=A1=A4=EB=B0=B1=20(#184)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserServiceImpl.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java index b0bcd46e..e4735114 100644 --- a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java @@ -252,7 +252,7 @@ public List getPopularDesigners(Long userId) { //TODO - 쿼리 return UserResponseDTO.of(user, userScrap.isStatus()); } return UserResponseDTO.of(user, false); - }).collect(Collectors.toList()); + }).collect(Collectors.toList()); } @Override @@ -284,27 +284,38 @@ public WorkPortfolioGetResponseDTO getPortfolio(Long requestUserId, Long userId) public List getDiscoveryUsers(Long userId, int[] tags){ List users; - if (tags.length == 0) { // user 정보 조회 태그가 걸린 경우와 아닌 경우 + if (tags.length == 0) { users = userRepository.findAllDiscoveryUser(userId); //TODO - user 관련 쿼리 잡기 , 동적 쿼리 필요,, } else { users = userRepository.findAllDiscoveryUserWithTag(userId, tags); } - Map scrapMap = users.stream() - .collect(Collectors.toMap(UserScrapUserQueryDto::user, UserScrapUserQueryDto::scrapStatus)); - // 모든 work를 가져와 최근 수정된 날짜 기준으로 정리 - List workAll = users.stream() - .flatMap(dto -> dto.user().getWorks().stream()) - .sorted(Comparator.comparing(Work::getModifiedAt).reversed()) - .toList(); - return workAll.stream().map((work) -> { - val userScrap = scrapMap.get(work.getUser().getId()); + return users.stream().map((dto) -> { + val firstWorkId = dto.user().getFirstWorkId(); + Work firstWork; + + if (firstWorkId == null && !dto.user().getActiveWorks().isEmpty()) { // User 권한 에러 + firstWork = workRepository.findFirstByUserIdAndIsActiveOrderByCreatedAtDesc(dto.user().getId(), true) + .orElse(Work.builder() + .user(dto.user()) + .photoUrl("해당하는 작업물을 찾을 수 없습니다.") + .detail("해당하는 작업물을 찾을 수 없습니다.") + .title("해당하는 작업물을 찾을 수 없습니다.") + .build()); + dto.user().setUserStatus(UserStatus.NOT_PERMITTED); + } + else { + firstWork = dto.user().getActiveWorks().stream() + .filter(work -> dto.user().getFirstWorkId().equals(work.getId())) + .findFirst().get(); + } + val userScrap = dto.scrapStatus(); if (Objects.isNull(userScrap)) { - return UserDiscoveryResponseDTO.of(work.getUser(), false, work); + return UserDiscoveryResponseDTO.of(dto.user(), false, firstWork); } - return UserDiscoveryResponseDTO.of(work.getUser(), userScrap, work); + return UserDiscoveryResponseDTO.of(dto.user(), userScrap, firstWork); }).collect(Collectors.toList()); } @@ -328,7 +339,7 @@ public void deleteUserAccount(Long userId, UserDeleteAccountRequestDTO userDelet public UserStatusResponseDTO getUserStatus(Long userId) { val user = findUser(userId); return UserStatusResponseDTO.of(user); - } + } @Transactional @Override