Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
17 changes: 5 additions & 12 deletions .github/workflows/publish-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,13 @@ jobs:
steps:
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@v1.0.3
env:
PORT: ${{ secrets.ENV_PORT }}
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
IMAGE_ID=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[:upper:]' '[:lower:]')
CONTAINER_ID=${{ env.IMAGE_NAME }}
CONTAINER_ID=$(echo "CONTAINER_ID=Code-Poker/CodePoker-be" | sed -E 's#.*/##' | tr '[:upper:]' '[:lower:]')
docker pull $IMAGE_ID:main
docker stop $CONTAINER_ID
docker rm $CONTAINER_ID
docker run -d --name $CONTAINER_ID \
-p 6370:6370 \
--restart=always \
$IMAGE_ID:main
docker-compose pull
docker-compose up -d
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ COPY . .
RUN npm install
RUN npm run build

EXPOSE $PORT

CMD [ "npm", "run", "start" ]
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
backend:
image: ghcr.io/code-poker/codepoker-be:main
# build: .
container_name: codepoker-be
restart: unless-stopped
ports:
- ${PORT}:${PORT}
depends_on:
- mongodb

mongodb:
image: mongo
container_name: mongodb
restart: unless-stopped
volumes:
- ./mongo_data:/data/db
healthcheck:
test: echo 'db.stats().ok' | mongosh localhost:27017/test --quiet
interval: 10s
timeout: 10s
retries: 5
4 changes: 2 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default tseslint.config(
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-call': 'off',
// '@typescript-eslint/no-unsafe-member-access': 'off',
// '@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
},
},
);
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^@database/(.*)$": "<rootDir>/database/$1",
"^@entities/(.*)$": "<rootDir>/entities/$1",
"^@modules/(.*)$": "<rootDir>/modules/$1"
}
}
}
17 changes: 8 additions & 9 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { DatabaseModule } from '@database/database.module';
import { BojModule } from '@modules/boj/module';
import { GroupModule } from '@modules/group/module';
import { PokerModule } from '@modules/poker/module';
import { ProblemModule } from '@modules/problem/module';
import { SolvedModule } from '@modules/solved/module';
import { SsuModule } from '@modules/ssu/module';
import { UserModule } from '@modules/user/module';
import { CacheInterceptor, CacheModule } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';

import { BojModule } from './boj/boj.module';
import { DatabaseModule } from './database/database.module';
import { GroupModule } from './group/group.module';
import { PokerModule } from './poker/poker.module';
import { ProblemModule } from './problem/problem.module';
import { SolvedModule } from './solved/solved.module';
import { SsuModule } from './ssu/ssu.module';
import { UserModule } from './user/user.module';

@Module({
imports: [
CacheModule.register({
Expand Down
6 changes: 6 additions & 0 deletions src/common/decorators/solved.decorators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { applyDecorators } from '@nestjs/common';
import { ApiQuery } from '@nestjs/swagger';

export function SolvedSearchQuery() {
return applyDecorators(ApiQuery({}), ApiQuery({}), ApiQuery({}));
}
17 changes: 8 additions & 9 deletions src/config.swagger.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { BojModule } from '@modules/boj/module';
import { GroupModule } from '@modules/group/module';
import { PokerModule } from '@modules/poker/module';
import { SolvedModule } from '@modules/solved/module';
import { SsuModule } from '@modules/ssu/module';
import { INestApplication } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

import { BojModule } from './boj/boj.module';
import { GroupModule } from './group/group.module';
import { PokerModule } from './poker/poker.module';
import { SolvedModule } from './solved/solved.module';
import { SsuModule } from './ssu/ssu.module';

export const configSwagger = (app: INestApplication<any>) => {
export const configSwagger = (app: INestApplication) => {
configCodePoker(app);
configSSUJoon(app);
configSolved(app);
};

const configCodePoker = (app: INestApplication<any>) => {
const configCodePoker = (app: INestApplication) => {
const options = new DocumentBuilder()
.setTitle('코드포커 API')
.setVersion('1.0')
Expand All @@ -28,7 +27,7 @@ const configCodePoker = (app: INestApplication<any>) => {
SwaggerModule.setup('api', app, document);
};

const configSSUJoon = (app: INestApplication<any>) => {
const configSSUJoon = (app: INestApplication) => {
const options = new DocumentBuilder()
.setTitle('BaekSSU API')
.setVersion('1.0')
Expand Down
2 changes: 1 addition & 1 deletion src/database/database.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export const databaseProviders = [
{
provide: 'MONGODB',
useFactory: (): Promise<typeof mongoose> =>
mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/codepoker'),
mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017'),
},
];
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SchemaFactory } from '@nestjs/mongoose';

import { Problem } from '../../problem/entities/problem.entity';
import { Problem } from './problem.entity';

export class Participant {
handle: string;
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions src/entities/problem.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { SchemaFactory } from '@nestjs/mongoose';

export class Problem {
problemId: number;
titleKo: string;
level: number;

constructor(problem: { problemId: number; titleKo: string; level: number }) {
this.problemId = problem.problemId;
this.titleKo = problem.titleKo;
this.level = problem.level;
}
}

export const ProblemSchema = SchemaFactory.createForClass(Problem);
15 changes: 0 additions & 15 deletions src/group/group.module.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/group/interfaces/group.interface.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/group/schemas/group.schema.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { NestFactory } from '@nestjs/core';
import * as process from 'node:process';

import { AppModule } from './app.module';
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
import { configSwagger } from './config.swagger';
import { HttpExceptionFilter } from './http-exception.filter';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get, Param } from '@nestjs/common';
import { ApiParam, ApiTags } from '@nestjs/swagger';

import { BojService } from './boj.service';
import { BojService } from './service';

@ApiTags('BOJ')
@Controller('boj')
Expand Down
6 changes: 3 additions & 3 deletions src/boj/boj.module.ts → src/modules/boj/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';

import { BojController } from './boj.controller';
import { BojRepository } from './boj.repository';
import { BojService } from './boj.service';
import { BojController } from './controller';
import { BojRepository } from './repository';
import { BojService } from './service';

@Module({
imports: [ConfigModule.forRoot(), HttpModule],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Contest } from '@entities/contest.entity';
import { HttpModule } from '@nestjs/axios';
import { ConfigModule } from '@nestjs/config';
import { Test } from '@nestjs/testing';

import { BojRepository } from './boj.repository';
import { Contest } from './entities/contest.entity';
import { BojRepository } from './repository';

describe('BojRepository', () => {
let repository: BojRepository;
Expand Down
3 changes: 1 addition & 2 deletions src/boj/boj.repository.ts → src/modules/boj/repository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Contest } from '@entities/contest.entity';
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
Expand All @@ -6,8 +7,6 @@ import { Cheerio } from 'cheerio';
import { AnyNode } from 'domhandler';
import * as process from 'node:process';

import { Contest } from './entities/contest.entity';

@Injectable()
export class BojRepository {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/boj/boj.service.ts → src/modules/boj/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ContestList } from '@entities/contest.entity';
import { Injectable } from '@nestjs/common';

import { BojRepository } from './boj.repository';
import { ContestList } from './entities/contest.entity';
import { BojRepository } from './repository';

@Injectable()
export class BojService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import { CreateGroupDto } from './dto/create-group.dto';
import { GroupService } from './group.service';
import { GroupService } from './service';

@ApiTags('Group')
@Controller('group')
Expand Down
15 changes: 15 additions & 0 deletions src/modules/group/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DatabaseModule } from '@database/database.module';
import { Module } from '@nestjs/common';

import { GroupController } from './controller';
import { groupProviders } from './providers';
import { GroupRepository } from './repository';
import { GroupService } from './service';

@Module({
imports: [DatabaseModule],
controllers: [GroupController],
providers: [GroupService, ...groupProviders, GroupRepository],
exports: [GroupService],
})
export class GroupModule {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GroupSchema } from '@entities/group.entity';
import { Connection } from 'mongoose';

import { GroupSchema } from './schemas/group.schema';

export const groupProviders = [
{
provide: 'GROUP_MODEL',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Group } from '@entities/group.entity';
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
import { Model } from 'mongoose';

import { CreateGroupDto } from './dto/create-group.dto';
import { Group } from './entities/group.entity';

@Injectable()
export class GroupRepository {
Expand Down
10 changes: 5 additions & 5 deletions src/group/group.service.ts → src/modules/group/service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Group } from '@entities/group.entity';
import { Injectable } from '@nestjs/common';

import { CreateGroupDto } from './dto/create-group.dto';
import { Group } from './entities/group.entity';
import { GroupRepository } from './group.repository';
import { GroupRepository } from './repository';

@Injectable()
export class GroupService {
constructor(private readonly groupRepository: GroupRepository) {}

async create(createGroupDto: CreateGroupDto): Promise<Group> {
return (await this.groupRepository.create(createGroupDto)) as Group;
return await this.groupRepository.create(createGroupDto);
}

async getAll(): Promise<Group[]> {
return (await this.groupRepository.getAll()) as Group[];
return await this.groupRepository.getAll();
}

async get(groupId: string): Promise<Group> {
return (await this.groupRepository.get(groupId)) as Group;
return await this.groupRepository.get(groupId);
}

deleteAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Body, Controller, Delete, Get, Param, Post, Query } from '@nestjs/commo
import { ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';

import { CreatePokerDto } from './dto/create-poker.dto';
import { PokerService } from './poker.service';
import { PokerService } from './service';

@Controller('poker')
@ApiTags('Poker')
Expand Down
29 changes: 29 additions & 0 deletions src/modules/poker/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DatabaseModule } from '@database/database.module';
import { ProblemService } from '@modules/problem/service';
import { UserService } from '@modules/user/service';
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';

import { groupProviders } from '../group/providers';
import { GroupRepository } from '../group/repository';
import { PokerController } from './controller';
import { pokerProviders } from './providers';
import { PokerRepository } from './repository';
import { PokerService } from './service';

@Module({
controllers: [PokerController],
exports: [PokerService],
imports: [DatabaseModule, HttpModule, ScheduleModule.forRoot()],
providers: [
PokerService,
UserService,
...pokerProviders,
PokerRepository,
...groupProviders,
GroupRepository,
ProblemService,
],
})
export class PokerModule {}
Loading