Skip to content

Commit 5245cc1

Browse files
committed
feat: 머지 및 수정 완료
1 parent fd62ff0 commit 5245cc1

40 files changed

+488
-40
lines changed

.github/workflows/dev.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: create env file
3232
working-directory: ./
3333
run: |
34-
echo "DB_HOST=${{secrets.DEV_DB_HOST}}" >> .env
34+
echo "DB_HOST=${{secrets.DB_HOST}}" >> .env
3535
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
3636
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
3737
echo "DB_DATABASE=${{ secrets.DEV_DB_DATABASE }}" >> .env

.github/workflows/prod.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: prod-deploy
5+
6+
on:
7+
push:
8+
branches: ['main']
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [20.16.0]
17+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
18+
19+
steps:
20+
- name: Checkout source code.
21+
uses: actions/checkout@v2
22+
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v2
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
28+
- name: Check Npm -v
29+
run: npm -v
30+
31+
- name: create env file
32+
working-directory: ./
33+
run: |
34+
echo "DB_HOST=${{secrets.DB_HOST}}" >> .env
35+
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
36+
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
37+
echo "DB_DATABASE=${{ secrets.PROD_DB_DATABASE }}" >> .env
38+
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
39+
echo "JWT_EXPIRATION=${{ secrets.JWT_EXPIRATION }}" >> .env
40+
echo "KAKAO_ID=${{ secrets.KAKAO_ID }}" >> .env
41+
echo "KAKAO_SECRET=${{ secrets.KAKAO_SECRET }}" >> .env
42+
echo "KAKAO_REDIRECT=${{ secrets.PROD_KAKAO_REDIRECT }}" >> .env
43+
echo "NAVER_ID=${{ secrets.NAVER_ID }}" >> .env
44+
echo "NAVER_SECRET=${{ secrets.NAVER_SECRET }}" >> .env
45+
echo "NAVER_REDIRECT=${{ secrets.PROD_NAVER_REDIRECT }}" >> .env
46+
echo "PORT"=${{ secrets.PROD_PORT }} >> .env
47+
48+
- name: copy appspec.yml
49+
run: cp appspec/appspec-prod.yml appspec.yml
50+
51+
- name: copy scripts
52+
run: mkdir -p scripts && cp prod-scripts/after-deploy.sh scripts/after-deploy.sh
53+
54+
- name: build server files
55+
working-directory: ./
56+
run: |
57+
yarn install
58+
yarn run build
59+
60+
- name: zip file
61+
run: zip -r build.zip ./dist ./scripts ./appspec.yml ./.env ./package.json ./node_modules ./yarn.lock
62+
63+
- name: AWS configure credentials
64+
uses: aws-actions/configure-aws-credentials@v1
65+
with:
66+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
67+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
68+
aws-region: ap-northeast-2
69+
70+
- name: upload to S3
71+
run: aws s3 cp --region ap-northeast-2 ./build.zip s3://oodd-prod-api-bucket/
72+
73+
- name: deploy with AWS codeDeploy
74+
run: aws deploy create-deployment
75+
--application-name nestjs-app-prod
76+
--deployment-config-name CodeDeployDefault.OneAtATime
77+
--deployment-group-name nestjs-app-prod-group
78+
--s3-location bucket=oodd-prod-api-bucket,bundleType=zip,key=build.zip

appspec/appspec-dev.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 0.0
2+
os: linux
3+
files:
4+
- source: /
5+
destination: /home/ubuntu/build-dev
6+
overwrite: yes
7+
file_exists_behavior: OVERWRITE
8+
permissions:
9+
- object: /home/ubuntu
10+
pattern: '**'
11+
owner: ubuntu
12+
group: ubuntu
13+
14+
hooks:
15+
AfterInstall:
16+
- location: scripts/after-deploy.sh
17+
timeout: 60
18+
runas: ubuntu

appspec/appspec-prod.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 0.0
2+
os: linux
3+
files:
4+
- source: /
5+
destination: /home/ubuntu/build
6+
overwrite: yes
7+
file_exists_behavior: OVERWRITE
8+
permissions:
9+
- object: /home/ubuntu
10+
pattern: '**'
11+
owner: ubuntu
12+
group: ubuntu
13+
14+
hooks:
15+
AfterInstall:
16+
- location: scripts/after-deploy.sh
17+
timeout: 60
18+
runas: ubuntu

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"@nestjs/common": "^10.4.5",
2323
"@nestjs/config": "^3.2.3",
2424
"@nestjs/core": "^10.3.2",
25+
"@nestjs/jwt": "^10.2.0",
26+
"@nestjs/passport": "^10.0.3",
2527
"@nestjs/platform-express": "^10.3.2",
2628
"@nestjs/platform-socket.io": "^10.4.7",
2729
"@nestjs/swagger": "^7.4.2",
@@ -34,6 +36,10 @@
3436
"dayjs": "^1.11.13",
3537
"mysql2": "^3.11.0",
3638
"nestjs-swagger-decorator": "^1.2.0",
39+
"passport": "^0.7.0",
40+
"passport-jwt": "^4.0.1",
41+
"passport-kakao": "^1.0.1",
42+
"passport-naver": "^1.0.6",
3743
"reflect-metadata": "^0.2.1",
3844
"rxjs": "^7.8.1",
3945
"socket.io": "^4.8.1",

src/app.module.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { StyletagModule } from './styletag/styletag.module';
1919
import { UserBlockModule } from './user-block/user-block.module';
2020
import { UserReportModule } from './user-report/user-report.module';
2121
import { AuthModule } from './auth/auth.module';
22-
import { DayjsModule } from './common/dayjs/dayjs.module';
22+
import { DayjsModule } from './common/dayjs/dayjs.module'; // DayjsModule 추가
2323
import { EventsGateway } from './eventGateway';
2424

2525
@Module({
@@ -51,6 +51,7 @@ import { EventsGateway } from './eventGateway';
5151
ChatRoomModule,
5252
ClothingModule,
5353
MatchingModule,
54+
DayjsModule, // DayjsModule 추가
5455
PostClothingModule,
5556
PostCommentModule,
5657
PostImageModule,
@@ -62,6 +63,9 @@ import { EventsGateway } from './eventGateway';
6263
UserBlockModule,
6364
UserReportModule,
6465
AuthModule,
66+
ConfigModule.forRoot({
67+
isGlobal: true,
68+
}),
6569
],
6670
controllers: [AppController],
6771
providers: [AppService, EventsGateway],

src/auth/auth.controller.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ import dayjs from 'dayjs';
1818
@Controller('auth')
1919
@ApiTags('[서비스] Auth 관련')
2020
export class AuthController {
21-
constructor(private readonly userService: UserService) {}
21+
constructor(
22+
private readonly userService: UserService,
23+
private readonly authService: AuthService,
24+
) {}
2225

23-
@Post()
26+
@Get('/login/kakao')
2427
@KakaoLoginSwagger('kakao 로그인 API')
2528
@UseGuards(KakaoAuthGuard)
2629
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -39,7 +42,7 @@ export class AuthController {
3942
return res.redirect(url + '?token=' + jwtToken);
4043
}
4144

42-
@Post()
45+
@Get('/login/naver')
4346
@NaverLoginSwagger('naver 로그인 API')
4447
@UseGuards(NaverAuthGuard)
4548
// eslint-disable-next-line @typescript-eslint/no-unused-vars

src/auth/auth.module.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { Module } from '@nestjs/common';
1+
import { forwardRef, Module } from '@nestjs/common';
22
import { AuthController } from './auth.controller';
33
import { AuthService } from './auth.service';
4-
import { UserService } from 'src/user/user.service';
4+
import { PassportModule } from '@nestjs/passport';
5+
import { JwtModule } from '@nestjs/jwt';
6+
import { UserModule } from 'src/user/user.module';
7+
import { JwtKakaoStrategy } from './strategies/kakao.strategy';
8+
import { ConfigModule, ConfigService } from '@nestjs/config';
9+
import { NaverStrategy } from './strategies/naver.strategy';
10+
import { JwtStrategy } from './strategies/jwt.strategy';
511

612
@Module({
713
controllers: [AuthController],

src/auth/auth.service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { Injectable } from '@nestjs/common';
1+
import { forwardRef, Inject, Injectable } from '@nestjs/common';
2+
import { UserService } from 'src/user/user.service';
3+
import { JwtPayload, SocialUser } from './dto/auth.dto';
4+
import { JwtService } from '@nestjs/jwt';
25

36
@Injectable()
47
export class AuthService {

src/auth/guards/jwt.auth.guard.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ExecutionContext, Injectable } from '@nestjs/common';
2+
import { AuthGuard as NestAuthGuard } from '@nestjs/passport';
3+
import { Observable } from 'rxjs';
4+
5+
@Injectable()
6+
export class AuthGuard extends NestAuthGuard('jwt') {
7+
canActivate(
8+
context: ExecutionContext,
9+
): boolean | Promise<boolean> | Observable<boolean> {
10+
return super.canActivate(context);
11+
}
12+
}

src/auth/guards/kakao.auth.guard.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ExecutionContext, Injectable } from '@nestjs/common';
2+
import { AuthGuard } from '@nestjs/passport';
3+
4+
@Injectable()
5+
export class KakaoAuthGuard extends AuthGuard('kakao') {
6+
handleRequest(err, user, info, context: ExecutionContext) {
7+
const req = context.switchToHttp().getRequest();
8+
9+
// 인증된 사용자를 req.kakaoUser에 저장
10+
req.socialUser = user;
11+
12+
return user; // req.user에는 여전히 사용자가 저장되긴 하지만, req.kakaoUser로도 접근 가능
13+
}
14+
}

src/auth/guards/naver.auth.guard.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ExecutionContext, Injectable } from '@nestjs/common';
2+
import { AuthGuard } from '@nestjs/passport';
3+
4+
@Injectable()
5+
export class NaverAuthGuard extends AuthGuard('naver') {
6+
handleRequest(err, user, info, context: ExecutionContext) {
7+
const req = context.switchToHttp().getRequest();
8+
9+
// 인증된 사용자를 req.kakaoUser에 저장
10+
req.socialUser = user;
11+
12+
return user; // req.user에는 여전히 사용자가 저장되긴 하지만, req.kakaoUser로도 접근 가능
13+
}
14+
}

src/common/constant.response.ts

-7
This file was deleted.

src/common/dayjs/dayjs.module.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Global, Module } from '@nestjs/common';
2+
import dayjs from 'dayjs';
3+
4+
@Global() // 전역 모듈로 설정
5+
@Module({
6+
providers: [
7+
{
8+
provide: 'DAYJS', // DI 토큰으로 'DAYJS' 사용
9+
useValue: dayjs, // day.js 인스턴스를 제공
10+
},
11+
],
12+
exports: ['DAYJS'], // 다른 모듈에서 사용할 수 있도록 export
13+
})
14+
export class DayjsModule {}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import dayjs from 'dayjs';
12
import {
23
PrimaryGeneratedColumn,
34
CreateDateColumn,
45
UpdateDateColumn,
56
Column,
6-
BeforeUpdate,
77
DeleteDateColumn,
8+
BeforeUpdate,
89
} from 'typeorm';
910

1011
export abstract class BaseEntity {
@@ -14,12 +15,25 @@ export abstract class BaseEntity {
1415
@Column({ default: 'activated' })
1516
status!: 'activated' | 'deactivated';
1617

17-
@CreateDateColumn({ type: 'datetime' })
18+
@CreateDateColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
1819
createdAt!: Date;
1920

2021
@UpdateDateColumn({ type: 'datetime', nullable: true })
2122
updatedAt!: Date | null;
2223

2324
@DeleteDateColumn({ type: 'datetime', nullable: true })
2425
deletedAt!: Date | null;
26+
27+
@BeforeUpdate()
28+
setUpdatedAt() {
29+
this.updatedAt = dayjs().toDate(); // 업데이트 시 현재 날짜로 설정
30+
}
31+
32+
softDelete() {
33+
this.deletedAt = dayjs().toDate(); // 삭제 시 현재 날짜로 설정
34+
}
35+
36+
restore() {
37+
this.deletedAt = null; // 복원 시 deletedAt을 null로 설정
38+
}
2539
}

src/common/entities/chat-message.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm';
22
import { User } from './user.entity';
33
import { ChatRoom } from './chat-room.entity';
4-
import { BaseEntity } from '../base.entity';
4+
import { BaseEntity } from './base.entity';
55

66
@Entity('ChatMessage')
77
export class ChatMessage extends BaseEntity {

src/common/entities/chat-room.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
2-
import { BaseEntity } from '../base.entity';
2+
import { BaseEntity } from './base.entity';
33
import { User } from './user.entity';
44
import { ChatMessage } from './chat-message.entity';
55
import { Matching } from './matching.entity';

src/common/entities/clothing.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Entity, Column, OneToMany } from 'typeorm';
2-
import { BaseEntity } from '../base.entity';
2+
import { BaseEntity } from './base.entity';
33
import { PostClothing } from './post-clothing.entity';
44

55
@Entity('Clothing')

src/common/entities/matching.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
2-
import { BaseEntity } from '../base.entity';
2+
import { BaseEntity } from './base.entity';
33
import { User } from './user.entity';
44
import { ChatRoom } from './chat-room.entity';
55
import { ApiProperty } from '@nestjs/swagger';

src/common/entities/post-clothing.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Entity, JoinColumn, ManyToOne } from 'typeorm';
22
import { Post } from './post.entity';
33
import { Clothing } from './clothing.entity';
4-
import { BaseEntity } from '../base.entity';
4+
import { BaseEntity } from './base.entity';
55

66
@Entity('PostClothing')
77
export class PostClothing extends BaseEntity {

src/common/entities/post-comment.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm';
22
import { User } from './user.entity';
33
import { Post } from './post.entity';
4-
import { BaseEntity } from '../base.entity';
4+
import { BaseEntity } from './base.entity';
55

66
@Entity('PostComment')
77
export class PostComment extends BaseEntity {

src/common/entities/post-image.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm';
2-
import { BaseEntity } from '../base.entity';
2+
import { BaseEntity } from './base.entity';
33
import { Post } from './post.entity';
44

55
@Entity('PostImage')

src/common/entities/post-like.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Entity, JoinColumn, ManyToOne } from 'typeorm';
2-
import { BaseEntity } from '../base.entity';
2+
import { BaseEntity } from './base.entity';
33
import { User } from './user.entity';
44
import { Post } from './post.entity';
55

src/common/entities/post-report.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm';
22
import { User } from './user.entity';
3-
import { BaseEntity } from '../base.entity';
3+
import { BaseEntity } from './base.entity';
44
import { Post } from './post.entity';
55

66
@Entity('PostReport')

0 commit comments

Comments
 (0)