Skip to content

Commit 7962430

Browse files
Merge pull request #58 from DevBadgers/develop
메인 반영
2 parents 74aaa85 + be92a42 commit 7962430

117 files changed

Lines changed: 4763 additions & 414 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Deploy on Merge to main
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- main
9+
10+
jobs:
11+
deploy:
12+
name: Deploy to EC2
13+
if: github.event.pull_request.merged == true # PR이 머지된 경우만 실행
14+
runs-on: ubuntu-latest
15+
concurrency:
16+
group: deploy
17+
cancel-in-progress: true # 이전 실행 중인 워크플로를 취소
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up SSH
24+
run: |
25+
mkdir -p ~/.ssh
26+
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
27+
chmod 600 ~/.ssh/id_rsa
28+
ssh-keyscan -H "${{ vars.EC2_HOST }}" >> ~/.ssh/known_hosts
29+
30+
- name: Execute Deployment Script on EC2
31+
run: |
32+
ssh ec2-user@${{ vars.EC2_HOST }} << 'EOF'
33+
cd /home/ec2-user/starchive/scripts
34+
35+
git checkout main
36+
# 스프링 배포 스크립트 실행
37+
./spring-deploy.sh
38+
39+
# nestjs 배포 스크립트 실행
40+
./nestjs-deploy.sh
41+
42+
EOF
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: NestJS Deploy on Merge to develop
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- main
9+
paths:
10+
- 'BACK/nest-app/**'
11+
12+
jobs:
13+
deploy:
14+
name: Deploy to EC2
15+
if: github.event.pull_request.merged == true # PR이 머지된 경우만 실행
16+
runs-on: ubuntu-latest
17+
concurrency:
18+
group: deploy-nestjs
19+
cancel-in-progress: true # 이전 실행 중인 워크플로를 취소
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up SSH
26+
run: |
27+
mkdir -p ~/.ssh
28+
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
29+
chmod 600 ~/.ssh/id_rsa
30+
ssh-keyscan -H "${{ vars.EC2_HOST }}" >> ~/.ssh/known_hosts
31+
32+
- name: Execute Deployment Script on EC2
33+
run: |
34+
ssh ec2-user@${{ vars.EC2_HOST }} << 'EOF'
35+
cd /home/ec2-user/starchive/scripts
36+
37+
git checkout develop
38+
39+
# nestjs 배포 스크립트 실행
40+
./nestjs-deploy.sh
41+
42+
EOF

.github/workflows/nestjs.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: NestJS CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
paths:
8+
- 'BACK/nest-app/**'
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
17+
steps:
18+
# 1. 코드 체크아웃
19+
- uses: actions/checkout@v4
20+
21+
# 2. Node.js 설정
22+
- name: Set up Node.js
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: '22' # 사용하려는 Node.js 버전
26+
cache: 'npm'
27+
cache-dependency-path: 'BACK/nest-app/package-lock.json'
28+
29+
# 3. 의존성 설치
30+
- name: Install dependencies
31+
run: |
32+
cd BACK/nest-app/
33+
npm install
34+
35+
# 4. NestJS 빌드
36+
- name: Build the project
37+
run: |
38+
cd BACK/nest-app/
39+
npm run build
40+
41+
# 5. 테스트 실행
42+
#- name: Run tests
43+
# run: |
44+
# cd BACK/nest-app/
45+
# npm run test
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Spring Deploy on Merge to develop
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- develop
9+
paths:
10+
- 'BACK/spring-app/**'
11+
12+
jobs:
13+
deploy:
14+
name: Deploy to EC2
15+
if: github.event.pull_request.merged == true # PR이 머지된 경우만 실행
16+
runs-on: ubuntu-latest
17+
concurrency:
18+
group: deploy-spring
19+
cancel-in-progress: true # 이전 실행 중인 워크플로를 취소
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Create application properties files
26+
run: |
27+
mkdir -p BACK/spring-app/src/main/resources
28+
echo "${{ secrets.APPLICATION_PROPERTIES_FOR_TEST }}" > BACK/spring-app/src/main/resources/application-test.properties
29+
echo "${{ secrets.APPLICATION_PROPERTIES_FOR_PROD }}" > BACK/spring-app/src/main/resources/application-prod.properties
30+
31+
- name: Set up SSH
32+
run: |
33+
mkdir -p ~/.ssh
34+
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
35+
chmod 600 ~/.ssh/id_rsa
36+
ssh-keyscan -H "${{ vars.EC2_HOST }}" >> ~/.ssh/known_hosts
37+
38+
- name: Transfer properties files to EC2
39+
run: |
40+
scp BACK/spring-app/src/main/resources/application-test.properties ec2-user@${{ vars.EC2_HOST }}:/home/ec2-user/starchive/BACK/spring-app/src/main/resources/
41+
scp BACK/spring-app/src/main/resources/application-prod.properties ec2-user@${{ vars.EC2_HOST }}:/home/ec2-user/starchive/BACK/spring-app/src/main/resources/
42+
43+
44+
- name: Execute Deployment Script on EC2
45+
run: |
46+
ssh ec2-user@${{ vars.EC2_HOST }} << 'EOF'
47+
cd /home/ec2-user/starchive/scripts
48+
49+
git checkout develop
50+
# 스프링 배포 스크립트 실행
51+
./spring-deploy.sh
52+
53+
EOF
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Spring CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
paths:
8+
- 'BACK/spring-app/**'
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up JDK 21
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '21'
23+
distribution: 'temurin'
24+
25+
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
26+
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
27+
- name: Setup Gradle
28+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
29+
30+
- name: Set application-test.properties
31+
run: |
32+
mkdir -p BACK/spring-app/src/main/resources
33+
cat <<EOF > BACK/spring-app/src/main/resources/application-test.properties
34+
${{ secrets.APPLICATION_PROPERTIES_FOR_TEST }}
35+
EOF
36+
37+
- name: Build with Gradle
38+
run: |
39+
cd BACK/spring-app/
40+
chmod +x ./gradlew
41+
./gradlew build

BACK/nest-app/prisma/schema.prisma

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,46 @@ datasource db {
1414
}
1515

1616
model Category {
17-
categoryId BigInt @id @default(autoincrement()) // 기본 키
17+
categoryId BigInt @id @default(autoincrement())
1818
name String @db.VarChar(100)
19-
parentId BigInt? // 상위 카테고리 (nullable)
19+
parentId BigInt?
2020
21-
@@map("Categories") // 실제 테이블 이름과 매핑
21+
posts Post[]
22+
23+
@@map("Categorys")
2224
}
2325

2426
model Post {
25-
postId BigInt @id @default(autoincrement()) // 기본 키
27+
postId BigInt @id @default(autoincrement())
2628
categoryId BigInt
2729
title String @db.VarChar(64)
2830
content String @db.Text
2931
author String @db.VarChar(32)
3032
password String @db.VarChar(128)
3133
createAt DateTime
3234
33-
@@map("Posts") // 실제 테이블 이름과 매핑
35+
category Category @relation(fields: [categoryId], references: [categoryId])
36+
postHashTags PostHashTag[]
37+
38+
@@map("Posts")
39+
}
40+
41+
model PostHashTag {
42+
postHashTagId BigInt @id @default(autoincrement())
43+
postId BigInt
44+
hashTagId BigInt
45+
46+
post Post @relation(fields: [postId], references: [postId])
47+
hashTag HashTag @relation(fields: [hashTagId], references: [hashTagId])
48+
49+
@@map("PostHashTag")
50+
}
51+
52+
model HashTag {
53+
hashTagId BigInt @id @default(autoincrement())
54+
name String @db.VarChar(32)
55+
56+
postHashTags PostHashTag[]
57+
58+
@@map("HashTags")
3459
}
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
import { Controller, Get, Param, ParseIntPipe, Query } from '@nestjs/common';
1+
import { Controller, Get, Query } from '@nestjs/common';
22
import { PostService } from './post.service';
33

44
@Controller('posts')
55
export class PostController {
66
constructor(private readonly postService: PostService) {}
77

88
@Get()
9-
async getPostsByCategory(@Query('category') categoryId: string) {
10-
// 카테고리 ID가 전달되지 않은 경우 전체 조회
11-
if (!categoryId) {
12-
return this.postService.getAllPosts();
13-
}
14-
15-
return this.postService.getPostsByCategory(BigInt(categoryId));
9+
async getPostsByCategory(
10+
@Query('category') categoryId: string,
11+
@Query('tag') hashTagId: string,
12+
@Query('page') page: string = '1',
13+
@Query('pageSize') pageSize: string = '10',
14+
) {
15+
return this.postService.getPosts(
16+
categoryId ? BigInt(categoryId) : null,
17+
hashTagId ? BigInt(hashTagId) : null,
18+
parseInt(page, 10),
19+
parseInt(pageSize, 10),
20+
);
1621
}
1722
}

0 commit comments

Comments
 (0)