Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prod 서버 CD 파이프라인 구축 #78

Merged
merged 105 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
8a1c3e5
chore: github actions test workflow 추가
yujamint Jun 1, 2024
8712e91
test: 실패 테스트 임시 주석 처리
yujamint Jun 1, 2024
ed52fd3
Update test.yaml
yujamint Jun 1, 2024
d8959ec
chore: 테스트 환경에서의 환경 변수 설정
yujamint Jun 1, 2024
2edb62d
test: 사용하지 않는 테스트 파일 삭제
yujamint Jun 1, 2024
4f91d3f
chore: github actions deploy workflow 추가
yujamint Jun 1, 2024
321653d
fix: region 문자열로 처리
yujamint Jun 1, 2024
b07ca80
fix: env 제거
yujamint Jun 1, 2024
6515214
fix: yaml multiline strings 문법 적용
yujamint Jun 1, 2024
64a6f38
fix: remove space
yujamint Jun 1, 2024
2396246
fix: 잘못된 code deploy 옵션 수정
yujamint Jun 1, 2024
e23d05f
fix: 잘못된 code deploy 옵션 수정
yujamint Jun 1, 2024
d7a39aa
fix: codedeploy hooks lifecycle 변경
yujamint Jun 1, 2024
7c96d06
fix: codedeploy hooks lifecycle 변경
yujamint Jun 1, 2024
797862f
fix: script가 종료되지 않는 문제점 해결
yujamint Jun 1, 2024
e83d67b
fix: script가 종료되지 않는 문제점 해결
yujamint Jun 1, 2024
8d32b1c
Update README.md
googoo9918 Jun 4, 2024
b6df367
Update README.md
googoo9918 Jun 4, 2024
5e5e33d
Update README.md
googoo9918 Jun 4, 2024
b9640da
test: 테스트 환경에서의 인증(JWT 토큰 발급)을 위한 fake 엔드포인트 구성
yujamint Jun 15, 2024
2bf66f6
test: 카테고리 생성/조회 테스트 작성
yujamint Jun 15, 2024
cc26f73
Fix: "@DiscriminatorValue 오류 수정"
googoo9918 Jun 2, 2024
ff556b9
Fix: "형변환 에러 수정"
googoo9918 Jun 2, 2024
cc8fdaa
Fix: "형변환 에러 수정"
googoo9918 Jun 2, 2024
8549c3a
Fix: "카테고리별 문제/요약 응답 필드 수정"
googoo9918 Jun 2, 2024
80493d4
Fix: "AI 서버 IP 주소 변경"
googoo9918 Jun 3, 2024
57a8960
Fix: "프록시 객체 확인 문제 해결"
googoo9918 Jun 5, 2024
28bcf50
Update README.md
googoo9918 Jun 4, 2024
48aa473
Update README.md
googoo9918 Jun 4, 2024
f6adec6
Update README.md
googoo9918 Jun 4, 2024
556ff7a
chore: cd 대상으로 불필요한 브랜치 제거
yujamint Jun 15, 2024
ee20625
Merge pull request #67 from capstone-five-ai/feat/cicd
yujamint Jun 15, 2024
629abc8
chore: github actions test workflow 추가
yujamint Jun 1, 2024
5660bec
test: 실패 테스트 임시 주석 처리
yujamint Jun 1, 2024
e4d5ad0
Update test.yaml
yujamint Jun 1, 2024
16839f8
chore: 테스트 환경에서의 환경 변수 설정
yujamint Jun 1, 2024
0caa370
test: 사용하지 않는 테스트 파일 삭제
yujamint Jun 1, 2024
6566d8c
chore: github actions deploy workflow 추가
yujamint Jun 1, 2024
6a08d40
fix: region 문자열로 처리
yujamint Jun 1, 2024
1fc9a89
fix: env 제거
yujamint Jun 1, 2024
a694832
fix: yaml multiline strings 문법 적용
yujamint Jun 1, 2024
f6823c5
fix: remove space
yujamint Jun 1, 2024
1ff0b54
fix: 잘못된 code deploy 옵션 수정
yujamint Jun 1, 2024
c87b1f9
fix: 잘못된 code deploy 옵션 수정
yujamint Jun 1, 2024
f1e7929
fix: codedeploy hooks lifecycle 변경
yujamint Jun 1, 2024
de24032
fix: codedeploy hooks lifecycle 변경
yujamint Jun 1, 2024
55fd1c9
fix: script가 종료되지 않는 문제점 해결
yujamint Jun 1, 2024
f249a3e
fix: script가 종료되지 않는 문제점 해결
yujamint Jun 1, 2024
116b447
chore: cd 대상으로 불필요한 브랜치 제거
yujamint Jun 15, 2024
5af41ee
fix: test profile 추가
yujamint Jun 16, 2024
518d028
Feat: "사용자 생성 문제 CRUD 테스트 작성"
googoo9918 Jun 16, 2024
1307004
Feat: "사용자 생성 요약 문제 CRUD 테스트 작성"
googoo9918 Jun 16, 2024
8bc1902
Merge branch 'dev' into test/authentication
googoo9918 Jun 16, 2024
6932391
Merge pull request #66 from capstone-five-ai/test/authentication
googoo9918 Jun 16, 2024
91f1cb5
Fix: "지연로딩 적용 안되어 있는 연관관계 수정"
googoo9918 Jun 16, 2024
a449e1e
Chore: 테스트용 이미지 추가
tioon Jun 16, 2024
aac6814
Test: AiGeneratedProblem 통합테스트 개발
tioon Jun 16, 2024
be4eb2b
Test: AiGeneratedSummary 통합테스트 개발
tioon Jun 16, 2024
e88f92e
Test: File 통합테스트 개발
tioon Jun 16, 2024
e6e3412
Test: ProblemFile 통합테스트 개발
tioon Jun 16, 2024
c834a60
Test: SummaryFile 통합테스트 개발
tioon Jun 16, 2024
826f0a4
Feat: "Cache 설정 파일 구현"
googoo9918 Jun 16, 2024
7894ea9
Refactor: "Cache 구현"
googoo9918 Jun 16, 2024
2670b69
Refactor: "Cache 구현"
googoo9918 Jun 16, 2024
0fd9a0f
Refactor: "Fetch join 구현"
googoo9918 Jun 16, 2024
67e7749
Refactor: "Fetch join 구현"
googoo9918 Jun 16, 2024
799c359
Feat: "카테고리 CRUD 테스트 작성"
googoo9918 Jun 16, 2024
93320a2
Merge pull request #68 from capstone-five-ai/test/ai-problem
yujamint Jun 16, 2024
093ec44
Merge pull request #69 from capstone-five-ai/refactor/member-saved-pr…
yujamint Jun 16, 2024
b7a5d0f
Revert "Merge pull request #69 from capstone-five-ai/refactor/member-…
yujamint Jun 16, 2024
6494039
Merge pull request #70 from capstone-five-ai/revert/performance-approve
yujamint Jun 16, 2024
92c360f
Feat: "CategorizedProblemDto CRUD 테스트 작성"
googoo9918 Jun 16, 2024
7ef92b8
Feat: "CategorizedProblem CRUD 테스트 작성"
googoo9918 Jun 16, 2024
58aeeae
Feat: "CategorizedSummary CRUD 테스트 작성"
googoo9918 Jun 16, 2024
9168087
Revert "Merge pull request #70 from capstone-five-ai/revert/performan…
yujamint Jun 16, 2024
36f4c3c
Merge pull request #72 from capstone-five-ai/refactor/performance-app…
yujamint Jun 16, 2024
bdc1179
test: "PR Synchronize를 위한 커밋"
googoo9918 Jun 16, 2024
413d26a
Merge pull request #71 from capstone-five-ai/test/authentication
googoo9918 Jun 16, 2024
627c362
feat: submodule checkout 추가
yujamint Jun 27, 2024
600e8bb
feat: S3 + CodeDeploy 배포 방식에서 Docker 사용하는 것으로 스크립트 수정
yujamint Jun 27, 2024
4f2c72f
Merge pull request #73 from capstone-five-ai/refactor/cd-flow
yujamint Jun 27, 2024
ff7e7e9
fix: yaml syntax 오류 수정
yujamint Jun 27, 2024
54f34b8
Merge pull request #74 from capstone-five-ai/refactor/cd-flow
yujamint Jun 27, 2024
da8bd0c
fix: docker build tag 수정
yujamint Jun 27, 2024
19060a6
fix: docker build tag 수정
yujamint Jun 27, 2024
84fe8b9
fix: docker build tag 수정
yujamint Jun 27, 2024
0236cee
feat: Dockerfile 추가
yujamint Jun 27, 2024
0474bb7
feat: pull 태그 추가
yujamint Jun 27, 2024
2fcbf1a
fix: docker build tag 수정
yujamint Jun 27, 2024
07872c5
fix: 잘못된 secrets variable 수정
yujamint Jun 28, 2024
86bb357
fix: docker container 삭제 커맨드 추가
yujamint Jun 28, 2024
2987003
fix: trigger 브랜치 수정
yujamint Jun 28, 2024
cfadaf4
Merge pull request #75 from capstone-five-ai/refactor/cd-flow
yujamint Jun 28, 2024
5d42033
fix: submodule 업데이트 실패하는 문제 수정
yujamint Jun 28, 2024
1431e9f
fix: 불필요한 tab 제거
yujamint Jun 28, 2024
1298937
fix: application.yml 수정
yujamint Jun 28, 2024
5304abb
feat: copySecretToBuild task 추가
yujamint Jun 29, 2024
fce200a
fix: yml file config 제거
yujamint Jun 29, 2024
0cecc2b
chore: submodule update
yujamint Jun 29, 2024
a0f0825
chore: docker 실행 시에 host 네트워크 사용하도록 옵션 추가
yujamint Jun 29, 2024
41093db
chore: prod 서버 자동 배포 스크립트 작성
yujamint Jun 29, 2024
9d84162
Merge pull request #76 from capstone-five-ai/feat/prod-cd
yujamint Jun 29, 2024
2f3f7de
fix: Dockerfile path 수정
yujamint Jun 29, 2024
503c029
fix: Dockerfile context 수정
yujamint Jun 29, 2024
532df83
feat: CD 스크립트 트리거 브랜치 수정
yujamint Jun 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/deploy-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: deploy on prod server

on:
push:
branches: [main]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- name: 체크아웃
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

- name: 서브모듈 업데이트
run: |
git submodule update --remote

- name: JDK 11 설치
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '11'
cache: 'gradle'

- name: Gradle에 실행 권한 부여
run: chmod +x gradlew

- name: 빌드
run: ./gradlew build -x test

- name: DockerHub 로그인
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker 이미지 빌드 & DockerHub에 Push
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile-prod
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/qtudy-server:prod

- name: EC2 서버에 배포
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_SERVER_HOST }}
username: ${{ secrets.PROD_SERVER_USERNAME }}
key: ${{ secrets.PROD_SERVER_PEM_KEY }}
envs: GITHUB_SHA
script: |
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server:prod
sudo docker run -d -p 8080:8080 --name qtudy-server-container ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server:prod
sudo docker image prune -f
62 changes: 62 additions & 0 deletions .github/workflows/deploy-stg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: deploy on stage server

on:
push:
branches: [dev]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- name: 체크아웃
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

- name: 서브모듈 업데이트
run: |
git submodule update --remote

- name: JDK 11 설치
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '11'
cache: 'gradle'

- name: Gradle에 실행 권한 부여
run: chmod +x gradlew

- name: 빌드
run: ./gradlew build -x test

- name: DockerHub 로그인
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker 이미지 빌드 & DockerHub에 Push
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile-stg
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/qtudy-server:latest

- name: EC2 서버에 배포
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.STG_SERVER_HOST }}
username: ${{ secrets.STG_SERVER_USERNAME }}
key: ${{ secrets.STG_SERVER_PEM_KEY }}
envs: GITHUB_SHA
script: |
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server
sudo docker run -d -p 8080:8080 --network="host" --name qtudy-server-container ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server
sudo docker image prune -f
38 changes: 38 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: run test

on:
pull_request:
branches: [main, dev]
types: [opened, synchronize, reopened]

permissions:
checks: write
pull-requests: write

jobs:
test:

runs-on: ubuntu-latest

steps:
- name: 체크아웃
uses: actions/checkout@v4

- name: JDK 11 설치
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '11'
cache: 'gradle'

- name: Gradle에 실행 권한 부여
run: chmod +x gradlew

- name: Test 실행
run: ./gradlew clean test

- name: Test 결과를 PR에 코멘트로 등록
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# 큐터디
![image](https://github.com/googoo9918/TIL/assets/102513932/b86bc53f-3182-41b0-b975-264cdb8a64dd)
![Qtudy_image](https://github.com/googoo9918/TIL/assets/102513932/87e0447f-3430-4a94-8f07-19fe536c1527)
![KakaoTalk_20240521_211608567](https://github.com/googoo9918/TIL/assets/102513932/4e44a605-5df8-4480-aa0d-e16be990fb3c)
![KakaoTalk_20240604_212902262](https://github.com/capstone-five-ai/Qtudy-BE/assets/102513932/c65eb1f1-4c16-4d64-8806-66ea2c2b53ef)
![KakaoTalk_20240604_212902262_01](https://github.com/capstone-five-ai/Qtudy-BE/assets/102513932/209a7e74-7f27-4239-91b4-c8f6dda58558)
![KakaoTalk_20240604_212902262_02](https://github.com/capstone-five-ai/Qtudy-BE/assets/102513932/c7f4e20b-eb0e-49d1-8f5a-4f24641c9898)
![KakaoTalk_20240604_212902262_03](https://github.com/capstone-five-ai/Qtudy-BE/assets/102513932/d1fe6d08-6a6e-48bd-b0b8-b96bda0143db)
![KakaoTalk_20240604_212902262_04](https://github.com/capstone-five-ai/Qtudy-BE/assets/102513932/e150be69-f40c-4ad9-b30c-757d818e5937)
![KakaoTalk_20240604_212902262_05](https://github.com/capstone-five-ai/Qtudy-BE/assets/102513932/31460b8b-a42a-48f7-9914-b30ccdc9b3a1)
![KakaoTalk_20240604_212902262_06](https://github.com/capstone-five-ai/Qtudy-BE/assets/102513932/362be302-461a-450e-97af-291481289a41)
![KakaoTalk_20240604_212902262_07](https://github.com/capstone-five-ai/Qtudy-BE/assets/102513932/0db18fae-24d7-444a-858f-a4d43c2a1e36)


**"큐터디"는 강력한 학습 도구 서비스입니다**
- 배포링크 : [큐터디](https://www.qtudy.com)

Expand Down Expand Up @@ -76,5 +84,4 @@
### Software Architecture
- ![소프트웨어 아키텍쳐 drawio](https://github.com/googoo9918/TIL/assets/102513932/6c6eb670-226f-4ec0-9550-c990b8c8292d)
### API 명세
- [API 명세서1](https://documenter.getpostman.com/view/23682054/2s9YeD8t2S)
- [API 명세서2](https://documenter.getpostman.com/view/31108336/2s9YeEaroJ)
- [API 명세](https://api.qtudy.com/swagger-ui/index.html)
23 changes: 23 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu
overwrite: yes

permissions:
- object: /home/ubuntu
pattern: "**"
owner: ubuntu
group: ubuntu

hooks:
AfterInstall:
- location: scripts/shutdown-prev-application.sh
timeout: 120
runas: ubuntu

ApplicationStart:
- location: scripts/build-and-run-new-application.sh
timeout: 120
runas: ubuntu
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ dependencies {
testImplementation 'com.theokanning.openai-gpt3-java:service:0.18.2'
testImplementation 'com.knuddels:jtokkit:1.0.0'
testImplementation 'com.fasterxml.jackson.module:jackson-module-jsonSchema-jakarta:2.15.0'

// Rest Assured
testImplementation 'io.rest-assured:rest-assured:4.5.1'
}

dependencyManagement {
Expand All @@ -67,9 +70,16 @@ tasks.named('test') {
}

processResources.dependsOn('copySecret')
processResources.dependsOn('copySecretToBuild')

tasks.register('copySecret', Copy) {
from './BE_config' // 서브 모듈 디렉토리 경로
include "*.yml" // 설정 파일 복사
into 'src/main/resources' // 붙여넣을 위치
}

tasks.register('copySecretToBuild', Copy) {
from './BE_config' // 서브 모듈 디렉토리 경로
include "*.yml" // 설정 파일 복사
into '$buildDir/resources/main' // 붙여넣을 위치
}
4 changes: 4 additions & 0 deletions docker/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM amazoncorretto:11-alpine-jdk
EXPOSE 8080
COPY ./build/libs/Qtudy-server-0.0.1-SNAPSHOT.jar /app.jar
CMD ["java", "-jar", "app.jar", "--spring.profiles.active=deploy"]
4 changes: 4 additions & 0 deletions docker/Dockerfile-stg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM amazoncorretto:11-alpine-jdk
EXPOSE 8080
COPY ./build/libs/Qtudy-server-0.0.1-SNAPSHOT.jar /app.jar
CMD ["java", "-jar", "app.jar", "--spring.profiles.active=stage"]
5 changes: 5 additions & 0 deletions scripts/build-and-run-new-application.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PROJECT_PATH=/home/ubuntu/Qtudy-BE
BUILD_PATH=$PROJECT_PATH/build/libs
BUILD_JAR=$BUILD_PATH/Qtudy-server-0.0.1-SNAPSHOT.jar

nohup java -jar $BUILD_JAR --spring.profiles.active=stage > $PROJECT_PATH/nohup.out 2>&1 &
7 changes: 7 additions & 0 deletions scripts/shutdown-prev-application.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
JAVA_PID=`sudo lsof -i :8080 -t`
if [ -z $JAVA_PID ]
then echo "실행되고 있는 애플리케이션이 없습니다."
else
sudo kill -9 $JAVA_PID
echo "기존에 실행되고 있던 애플리케이션을 종료했습니다."
fi
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CategorizedProblemDto {

@Getter
@Schema(name = "CategorizedProblemPost", description = "새 카테고리화 문제 생성 요청 DTO")
@AllArgsConstructor
public static class Post {

@Schema(description = "카테고리 ID 목록", example = "[1, 2]")
Expand All @@ -31,6 +32,7 @@ public static class Post {

@Getter
@Schema(name = "CategorizedProblemPatch", description = "카테고리화 문제 수정 요청 DTO")
@AllArgsConstructor
public static class Patch{
@Schema(description = "문제 이름", example = "수정된 문제 이름")
private String problemName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.app.domain.categorizedproblem.repository;

import com.app.domain.categorizedproblem.entity.CategorizedProblem;
import feign.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import org.springframework.data.jpa.repository.Query;

public interface CategorizedProblemRepository extends JpaRepository<CategorizedProblem, Long> {
boolean existsByCategoryCategoryIdAndProblemProblemId(Long categoryId, Long problemId);

boolean existsByProblemProblemId(Long problemId);

Page<CategorizedProblem> findByCategoryCategoryId(Long categoryId, Pageable pageable);
@Query(value = "SELECT cp FROM CategorizedProblem cp JOIN FETCH cp.problem p JOIN FETCH cp.category c WHERE c.categoryId = :categoryId",
countQuery = "SELECT count(cp) FROM CategorizedProblem cp WHERE cp.category.categoryId = :categoryId")
Page<CategorizedProblem> findByCategoryCategoryId(@Param("categoryId") Long categoryId, Pageable pageable);

List<CategorizedProblem> findByCategoryCategoryId(Long categoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -244,6 +245,7 @@ public CategorizedProblem updateCategorizedProblem(Long categorizedProblemId, Me
}

@Transactional(readOnly = true)
@Cacheable(value = "categorizedProblem", key = "#categoryId")
public Page<CategorizedProblem> findCategorizedProblemsByCategoryId(Long categoryId, int page, int size) {
PageRequest pageRequest = PageRequest.of(page, size);
return categorizedProblemRepository.findByCategoryCategoryId(categoryId, pageRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CategorizedSummaryDto {

@Getter
@Schema(name = "CategorizedSummaryPost", description = "새 카테고리화 요약 생성 요청 DTO")
@AllArgsConstructor
public static class Post {
@Schema(description = "카테고리 ID 목록", example = "[1, 2]")
private List<Long> categoryIdList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.app.domain.categorizedsummary.repository;

import com.app.domain.categorizedsummary.entity.CategorizedSummary;
import feign.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface CategorizedSummaryRepository extends JpaRepository<CategorizedSummary, Long> {
boolean existsByCategoryCategoryIdAndSummarySummaryId(Long categoryId, Long summaryId);

boolean existsBySummarySummaryId(Long summaryId);

Page<CategorizedSummary> findByCategoryCategoryId(Long categoryId, Pageable pageable);
@Query(value = "SELECT cs FROM CategorizedSummary cs JOIN FETCH cs.summary s JOIN FETCH cs.category c WHERE c.categoryId = :categoryId",
countQuery = "SELECT count(cs) FROM CategorizedSummary cs WHERE cs.category.categoryId = :categoryId")
Page<CategorizedSummary> findByCategoryCategoryId(@Param("categoryId") Long categoryId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -104,6 +105,8 @@ public CategorizedSummary findVerifiedCategorizedSummaryByCategorizedSummaryId(L
.orElseThrow(() -> new EntityNotFoundException(ErrorCode.CATEGORIZED_SUMMARY_NOT_EXISTS));
}

@Transactional(readOnly = true)
@Cacheable(value = "categorizedSummary", key = "#categoryId")
public Page<CategorizedSummary> findCategorziedSummarysByCategoryId(Long categoryId, int page, int size) {
PageRequest pageRequest = PageRequest.of(page, size);
return categorizedSummaryRepository.findByCategoryCategoryId(categoryId, pageRequest);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/app/domain/category/dto/CategoryDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class CategoryDto {

@Getter
@AllArgsConstructor
@Schema(name = "CategoryRequestDto", description = "카테고리 요청 DTO")
public static class RequestDto {
@NotBlank
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/app/domain/category/entity/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class Category extends BaseEntity {
@Column(nullable = false, length = 10)
private CategoryType categoryType;

@OneToMany(mappedBy = "category")
@OneToMany(mappedBy = "category", fetch = FetchType.LAZY)
private List<CategorizedSummary> categorizedSummaries;

@OneToMany(mappedBy = "category")
@OneToMany(mappedBy = "category", fetch = FetchType.LAZY)
private List<CategorizedProblem> categorizedProblems;

public void updateMember(Member member) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/app/domain/file/entity/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class File extends BaseEntity {
//@Column(name = "MEMBER_ID") //추후에 Members 엔티티와 연결
//private String memberId;
@JsonIgnore
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MEMBER_ID")
private Member member;

Expand Down
Loading
Loading