Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/be-dev' into be-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yechan2468 committed Nov 15, 2023
2 parents acb5197 + b9c0207 commit 0604701
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 59 deletions.
5 changes: 4 additions & 1 deletion be/algo-with-me-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/common": "^10.2.8",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",

This comment has been minimized.

Copy link
@rladydgn

rladydgn Nov 15, 2023

Collaborator

์ด๊ฑฐ ์ œ๊ฐ€ ์˜ฌ๋ ธ๋˜๊ฑฐ ์•„๋‹Œ๊ฐ€์š”? ใ…‹ใ…‹ใ…‹

"pg": "^8.11.3",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
Expand Down
66 changes: 58 additions & 8 deletions be/algo-with-me-api/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions be/algo-with-me-api/src/app.controller.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions be/algo-with-me-api/src/app.controller.ts

This file was deleted.

9 changes: 4 additions & 5 deletions be/algo-with-me-api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';

import { AppController } from '@src/app.controller';
import { AppService } from '@src/app.service';
import { CompetitionModule } from './competition/competition.module';
import { Problem } from './competition/entities/problem.entity';

@Module({
imports: [
Expand All @@ -19,10 +19,9 @@ import { AppService } from '@src/app.service';
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
synchronize: true,
entities: [],
entities: [Problem],

This comment has been minimized.

Copy link
@rladydgn

rladydgn Nov 15, 2023

Collaborator

์ด๊ฒƒ๋„,,? ์Œ ๋ญ์ฃ  ์ด๊ฑฐ?

}),
CompetitionModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
8 changes: 0 additions & 8 deletions be/algo-with-me-api/src/app.service.ts

This file was deleted.

13 changes: 13 additions & 0 deletions be/algo-with-me-api/src/competition/competition.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Get, Param } from '@nestjs/common';

import { CompetitionService } from './competition.service';

@Controller('competitions')
export class CompetitionController {
constructor(private readonly competitionService: CompetitionService) {}

@Get('problems/:id')
findOne(@Param('id') id: number) {
return this.competitionService.findOneProblem(id);
}
}
15 changes: 15 additions & 0 deletions be/algo-with-me-api/src/competition/competition.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { CompetitionController } from './competition.controller';
import { CompetitionService } from './competition.service';
import { Problem } from './entities/problem.entity';
import { ProblemController } from './problem.controller';
import { ProblemService } from './problem.service';

@Module({
imports: [TypeOrmModule.forFeature([Problem])],
controllers: [ProblemController, CompetitionController],
providers: [ProblemService, CompetitionService],
})
export class CompetitionModule {}
31 changes: 31 additions & 0 deletions be/algo-with-me-api/src/competition/competition.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

import { existsSync, readFileSync } from 'fs';
import * as path from 'path';

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

@Injectable()
export class CompetitionService {
constructor(@InjectRepository(Problem) private readonly problemRepository: Repository<Problem>) {}

async findOneProblem(id: number) {
const problem = await this.problemRepository.findOneBy({ id });
const fileName = id.toString() + '.md';
const paths = path.join(process.env.PROBLEM_PATH, id.toString(), fileName);
if (!existsSync(paths)) throw new NotFoundException('๋ฌธ์ œ ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.');
const content = readFileSync(paths).toString();
return {
id: problem.id,
title: problem.title,
timeLimit: problem.timeLimit,
memoryLimit: problem.memoryLimit,
content: content,
solutionCode: problem.solutionCode,
testcases: '์ž„์‹œ',
createdAt: problem.createdAt,
};
}
}
34 changes: 34 additions & 0 deletions be/algo-with-me-api/src/competition/dto/create-problem.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { IsNotEmpty } from 'class-validator';

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

export class CreateProblemDto {
@IsNotEmpty()
title: string;

@IsNotEmpty()
timeLimit: number;

@IsNotEmpty()
memoryLimit: number;

@IsNotEmpty()
testcaseNum: number;

@IsNotEmpty()
frameCode: string;

@IsNotEmpty()
solutionCode: string;

toEntity(): Problem {
const problem = new Problem();
problem.title = this.title;
problem.timeLimit = this.timeLimit;
problem.memoryLimit = this.memoryLimit;
problem.testcaseNum = this.testcaseNum;
problem.frameCode = this.frameCode;
problem.solutionCode = this.solutionCode;
return problem;
}
}
37 changes: 37 additions & 0 deletions be/algo-with-me-api/src/competition/entities/problem.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';

@Entity()
export class Problem {
@PrimaryGeneratedColumn()
id: number;

@Column()
title: string;

@Column()
timeLimit: number;

@Column()
memoryLimit: number;

@Column()
testcaseNum: number;

@Column('text')
frameCode: string;

@Column('text')
solutionCode: string;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
Loading

0 comments on commit 0604701

Please sign in to comment.