Skip to content

Commit

Permalink
Merge pull request #335 from boostcampwm2023/BE-fix/delete-tmp-db
Browse files Browse the repository at this point in the history
temporary database 제거
  • Loading branch information
Conut-1 authored May 20, 2024
2 parents 9b4316e + 3c62c58 commit 07834f5
Show file tree
Hide file tree
Showing 38 changed files with 571 additions and 942 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/BE-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
echo "BASE_IMAGE_URL=$BASE_IMAGE_URL" >> ./nestjs-BE/server/.env
echo "BUCKET_NAME=$BUCKET_NAME" >> ./nestjs-BE/server/.env
echo "APP_ICON_URL=$APP_ICON_URL" >> ./nestjs-BE/server/.env
echo "CSV_FOLDER=$CSV_FOLDER" >> ./nestjs-BE/server/.env
docker build -t ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync ./nestjs-BE/server
docker push ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync:latest
env:
Expand All @@ -49,7 +48,6 @@ jobs:
BASE_IMAGE_URL: ${{ secrets.BASE_IMAGE_URL }}
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
APP_ICON_URL: ${{ secrets.APP_ICON_URL }}
CSV_FOLDER: ${{ secrets.CSV_FOLDER }}

deploy:
needs: build
Expand All @@ -70,6 +68,5 @@ jobs:
sudo docker run -d \
--name mindsync_server \
-p ${{ secrets.SERVER_PORT }}:${{ secrets.CONTAINER_PORT }} \
-v temporary-volume:${{ secrets.CSV_FOLDER }} \
--net mybridge \
ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync
3 changes: 1 addition & 2 deletions nestjs-BE/server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
'max-depth': ['error', 3],
'no-magic-numbers': ['error', { ignore: [-1, 0, 1] }],
'curly': ['error', 'multi-line', 'consistent'],
'max-params': ['error', 3],
curly: ['error', 'multi-line', 'consistent'],
},
};
4 changes: 0 additions & 4 deletions nestjs-BE/server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,3 @@ lerna-debug.log*

# Environment Variable File
.env

# csv, prisma
/operations
/prisma/generated
4 changes: 1 addition & 3 deletions nestjs-BE/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ RUN npm ci

COPY ./ ./

RUN npx prisma generate --schema=./prisma/mysql.schema.prisma

RUN npx prisma generate --schema=./prisma/mongodb.schema.prisma
RUN npx prisma migrate dev

EXPOSE 3000

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- You are about to alter the column `nickname` on the `PROFILE_TB` table. The data in that column could be lost. The data in that column will be cast from `VarChar(191)` to `VarChar(20)`.
- You are about to alter the column `name` on the `SPACE_TB` table. The data in that column could be lost. The data in that column will be cast from `VarChar(191)` to `VarChar(20)`.
*/
-- AlterTable
ALTER TABLE `PROFILE_TB` MODIFY `nickname` VARCHAR(20) NOT NULL;

-- AlterTable
ALTER TABLE `SPACE_TB` MODIFY `name` VARCHAR(20) NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- RenameIndex
ALTER TABLE `USER_TB` RENAME INDEX `USER_TB_email_provider_key` TO `User_email_provider_key`;

-- RenameTable
ALTER TABLE `USER_TB` RENAME `User`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE `PROFILE_TB` DROP FOREIGN KEY `PROFILE_TB_user_id_fkey`;

-- RenameIndex
ALTER TABLE `PROFILE_TB` RENAME INDEX `PROFILE_TB_user_id_key` TO `Profile_user_id_key`;

-- RenameTable
ALTER TABLE `PROFILE_TB` RENAME `Profile`;

-- AddForeignKey
ALTER TABLE `Profile` ADD CONSTRAINT `Profile_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- DropForeignKey
ALTER TABLE `INVITE_CODE_TB` DROP FOREIGN KEY `INVITE_CODE_TB_space_uuid_fkey`;

-- DropForeignKey
ALTER TABLE `PROFILE_SPACE_TB` DROP FOREIGN KEY `PROFILE_SPACE_TB_profile_uuid_fkey`;

-- DropForeignKey
ALTER TABLE `PROFILE_SPACE_TB` DROP FOREIGN KEY `PROFILE_SPACE_TB_space_uuid_fkey`;

-- RenameIndex
ALTER TABLE `PROFILE_SPACE_TB` RENAME INDEX `PROFILE_SPACE_TB_space_uuid_profile_uuid_key` TO `Profile_space_space_uuid_profile_uuid_key`;

-- RenameTable
ALTER TABLE `PROFILE_SPACE_TB` RENAME `Profile_space`;

-- RenameTable
ALTER TABLE `SPACE_TB` RENAME `Space`;

-- AddForeignKey
ALTER TABLE `Profile_space` ADD CONSTRAINT `Profile_space_space_uuid_fkey` FOREIGN KEY (`space_uuid`) REFERENCES `Space`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Profile_space` ADD CONSTRAINT `Profile_space_profile_uuid_fkey` FOREIGN KEY (`profile_uuid`) REFERENCES `Profile`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `INVITE_CODE_TB` ADD CONSTRAINT `INVITE_CODE_TB_space_uuid_fkey` FOREIGN KEY (`space_uuid`) REFERENCES `Space`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- DropForeignKey
ALTER TABLE `INVITE_CODE_TB` DROP FOREIGN KEY `INVITE_CODE_TB_space_uuid_fkey`;

-- DropForeignKey
ALTER TABLE `REFRESH_TOKEN_TB` DROP FOREIGN KEY `REFRESH_TOKEN_TB_user_id_fkey`;

-- RenameIndex
ALTER TABLE `INVITE_CODE_TB` RENAME INDEX `INVITE_CODE_TB_invite_code_key` TO `InviteCode_invite_code_key`;

-- RenameTable
ALTER TABLE `INVITE_CODE_TB` RENAME `InviteCode`;

-- RenameTable
ALTER TABLE `REFRESH_TOKEN_TB` RENAME `RefreshToken`;

-- AddForeignKey
ALTER TABLE `RefreshToken` ADD CONSTRAINT `RefreshToken_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `InviteCode` ADD CONSTRAINT `InviteCode_space_uuid_fkey` FOREIGN KEY (`space_uuid`) REFERENCES `Space`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Warnings:
- The primary key for the `RefreshToken` table will be changed. If it partially fails, the table could be left without primary key constraint.
- Added the required column `id` to the `RefreshToken` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `RefreshToken` DROP PRIMARY KEY,
ADD COLUMN `id` INTEGER NOT NULL AUTO_INCREMENT,
RENAME COLUMN `uuid` TO `token`,
ADD PRIMARY KEY (`id`);

ALTER TABLE `RefreshToken` MODIFY `token` VARCHAR(210) NOT NULL;

-- CreateIndex
CREATE INDEX `RefreshToken_token_idx` ON `RefreshToken`(`token`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:
- A unique constraint covering the columns `[token]` on the table `RefreshToken` will be added. If there are existing duplicate values, this will fail.
*/
-- DropIndex
DROP INDEX `RefreshToken_token_idx` ON `RefreshToken`;

-- CreateIndex
CREATE UNIQUE INDEX `RefreshToken_token_key` ON `RefreshToken`(`token`);
14 changes: 0 additions & 14 deletions nestjs-BE/server/prisma/mongodb.schema.prisma

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
generator client {
provider = "prisma-client-js"
output = "./generated/mysql"
}

datasource db {
provider = "mysql"
url = env("MYSQL_DATABASE_URL")
}

model USER_TB {
model User {
uuid String @id @db.VarChar(32)
email String
provider String
profiles PROFILE_TB[]
refresh_tokens REFRESH_TOKEN_TB[]
profiles Profile[]
refresh_tokens RefreshToken[]
@@unique([email, provider])
}

model REFRESH_TOKEN_TB {
uuid String @id @db.VarChar(32)
model RefreshToken {
id Int @id @default(autoincrement())
token String @db.VarChar(210)
expiry_date DateTime
user_id String
user USER_TB @relation(fields: [user_id], references: [uuid], onDelete: Cascade)
user User @relation(fields: [user_id], references: [uuid], onDelete: Cascade)
@@unique([token])
}

model PROFILE_TB {
model Profile {
uuid String @id @db.VarChar(32)
user_id String @unique @db.VarChar(32)
image String
nickname String @db.VarChar(20)
user USER_TB @relation(fields: [user_id], references: [uuid], onDelete: Cascade)
spaces PROFILE_SPACE_TB[]
user User @relation(fields: [user_id], references: [uuid], onDelete: Cascade)
spaces Profile_space[]
}

model SPACE_TB {
model Space {
uuid String @id @db.VarChar(32)
name String @db.VarChar(20)
icon String
profiles PROFILE_SPACE_TB[]
invite_codes INVITE_CODE_TB[]
profiles Profile_space[]
invite_codes InviteCode[]
}

model PROFILE_SPACE_TB {
model Profile_space {
space_uuid String @db.VarChar(32)
profile_uuid String @db.VarChar(32)
space SPACE_TB @relation(fields: [space_uuid], references: [uuid], onDelete: Cascade)
profile PROFILE_TB @relation(fields: [profile_uuid], references: [uuid], onDelete: Cascade)
space Space @relation(fields: [space_uuid], references: [uuid], onDelete: Cascade)
profile Profile @relation(fields: [profile_uuid], references: [uuid], onDelete: Cascade)
@@unique([space_uuid, profile_uuid])
}

model INVITE_CODE_TB {
model InviteCode {
uuid String @id @db.VarChar(32)
invite_code String @unique @db.VarChar(10)
space_uuid String @db.VarChar(32)
expiry_date DateTime
space SPACE_TB @relation(fields: [space_uuid], references: [uuid], onDelete: Cascade)
space Space @relation(fields: [space_uuid], references: [uuid], onDelete: Cascade)
}

2 changes: 0 additions & 2 deletions nestjs-BE/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
import { PrismaModule } from './prisma/prisma.module';
import { TemporaryDatabaseModule } from './temporary-database/temporary-database.module';
import { ProfilesModule } from './profiles/profiles.module';
import { SpacesModule } from './spaces/spaces.module';
import { BoardsModule } from './boards/boards.module';
Expand All @@ -21,7 +20,6 @@ import customEnv from './config/env';
AuthModule,
UsersModule,
PrismaModule,
TemporaryDatabaseModule,
ScheduleModule.forRoot(),
ProfilesModule,
SpacesModule,
Expand Down
47 changes: 34 additions & 13 deletions nestjs-BE/server/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { Controller, Post, Body, NotFoundException } from '@nestjs/common';
import {
Controller,
Post,
Body,
NotFoundException,
BadRequestException,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { Public } from './public.decorator';
import { KakaoUserDto } from './dto/kakao-user.dto';
import { UsersService } from 'src/users/users.service';
import { RefreshTokenDto } from './dto/refresh-token.dto';
import { ProfilesService } from 'src/profiles/profiles.service';
import { ApiTags, ApiResponse, ApiOperation } from '@nestjs/swagger';
import customEnv from 'src/config/env';
import { RefreshTokensService } from './refresh-tokens.service';

@Controller('auth')
@ApiTags('auth')
Expand All @@ -14,6 +22,7 @@ export class AuthController {
private authService: AuthService,
private usersService: UsersService,
private profilesService: ProfilesService,
private refreshTokensService: RefreshTokensService,
) {}

@Post('kakao-oauth')
Expand All @@ -33,20 +42,24 @@ export class AuthController {
);
if (!kakaoUserAccount) throw new NotFoundException();
const email = kakaoUserAccount.email;
let userUuid = await this.authService.findUser(
this.usersService,
const user = await this.usersService.findUserByEmailAndProvider(
email,
'kakao',
);
let userUuid = user?.uuid;
if (!userUuid) {
const data = { email, provider: 'kakao' };
userUuid = await this.authService.createUser(
data,
this.usersService,
this.profilesService,
);
const createdUser = await this.usersService.createUser(data);
userUuid = createdUser.uuid;
const profileData = {
user_id: createdUser.uuid,
image: customEnv.BASE_IMAGE_URL,
nickname: '익명의 사용자',
};
await this.profilesService.createProfile(profileData);
}
return this.authService.login(userUuid);
const tokenData = await this.authService.login(userUuid);
return { statusCode: 200, message: 'Success', data: tokenData };
}

@Post('token')
Expand All @@ -60,15 +73,23 @@ export class AuthController {
status: 401,
description: 'Refresh token expired. Please log in again.',
})
renewAccessToken(@Body() refreshTokenDto: RefreshTokenDto) {
async renewAccessToken(@Body() refreshTokenDto: RefreshTokenDto) {
const refreshToken = refreshTokenDto.refresh_token;
return this.authService.renewAccessToken(refreshToken);
const accessToken = await this.authService.renewAccessToken(refreshToken);
return {
statusCode: 200,
message: 'Success',
data: { access_token: accessToken },
};
}

@Post('logout')
@Public()
logout(@Body() refreshTokenDto: RefreshTokenDto) {
async logout(@Body() refreshTokenDto: RefreshTokenDto) {
const refreshToken = refreshTokenDto.refresh_token;
return this.authService.remove(refreshToken);
const token =
await this.refreshTokensService.deleteRefreshToken(refreshToken);
if (!token) throw new BadRequestException();
return { statusCode: 204, message: 'No Content' };
}
}
2 changes: 2 additions & 0 deletions nestjs-BE/server/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JwtStrategy } from './jwt.strategy';
import { APP_GUARD } from '@nestjs/core';
import { JwtAuthGuard } from './jwt-auth.guard';
import { ProfilesModule } from 'src/profiles/profiles.module';
import { RefreshTokensService } from './refresh-tokens.service';

@Module({
imports: [UsersModule, PassportModule, JwtModule, ProfilesModule],
Expand All @@ -16,6 +17,7 @@ import { ProfilesModule } from 'src/profiles/profiles.module';
AuthService,
JwtStrategy,
{ provide: APP_GUARD, useClass: JwtAuthGuard },
RefreshTokensService,
],
exports: [AuthService],
})
Expand Down
Loading

0 comments on commit 07834f5

Please sign in to comment.