-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/be-dev' into be-dev
- Loading branch information
Showing
14 changed files
with
296 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
be/algo-with-me-api/src/competition/competition.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
be/algo-with-me-api/src/competition/competition.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
be/algo-with-me-api/src/competition/dto/create-problem.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
be/algo-with-me-api/src/competition/entities/problem.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.
์ด๊ฑฐ ์ ๊ฐ ์ฌ๋ ธ๋๊ฑฐ ์๋๊ฐ์? ใ ใ ใ