From 7bb67a17a1bb65612e60e31a1d868fa631fad46d Mon Sep 17 00:00:00 2001 From: rladydgn <39542757+rladydgn@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:40:29 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=EB=AC=B8=EC=A0=9C=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/algo-with-me-api/package.json | 5 +- be/algo-with-me-api/pnpm-lock.yaml | 66 ++++++++++++++++--- .../src/app.controller.spec.ts | 23 ------- be/algo-with-me-api/src/app.controller.ts | 13 ---- be/algo-with-me-api/src/app.module.ts | 9 ++- be/algo-with-me-api/src/app.service.ts | 8 --- .../src/competition/competition.module.ts | 13 ++++ .../src/competition/dto/create-problem.dto.ts | 30 +++++++++ .../competition/entities/problem.entity.ts | 34 ++++++++++ .../src/competition/problem.controller.ts | 35 ++++++++++ .../src/competition/problem.service.ts | 35 ++++++++++ be/algo-with-me-api/tsconfig.json | 2 +- 12 files changed, 214 insertions(+), 59 deletions(-) delete mode 100644 be/algo-with-me-api/src/app.controller.spec.ts delete mode 100644 be/algo-with-me-api/src/app.controller.ts delete mode 100644 be/algo-with-me-api/src/app.service.ts create mode 100644 be/algo-with-me-api/src/competition/competition.module.ts create mode 100644 be/algo-with-me-api/src/competition/dto/create-problem.dto.ts create mode 100644 be/algo-with-me-api/src/competition/entities/problem.entity.ts create mode 100644 be/algo-with-me-api/src/competition/problem.controller.ts create mode 100644 be/algo-with-me-api/src/competition/problem.service.ts diff --git a/be/algo-with-me-api/package.json b/be/algo-with-me-api/package.json index eaeb6d6..cdfaf68 100644 --- a/be/algo-with-me-api/package.json +++ b/be/algo-with-me-api/package.json @@ -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", "pg": "^8.11.3", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1", diff --git a/be/algo-with-me-api/pnpm-lock.yaml b/be/algo-with-me-api/pnpm-lock.yaml index 737c168..2f37c20 100644 --- a/be/algo-with-me-api/pnpm-lock.yaml +++ b/be/algo-with-me-api/pnpm-lock.yaml @@ -6,20 +6,29 @@ settings: dependencies: '@nestjs/common': - specifier: ^10.0.0 - version: 10.2.8(reflect-metadata@0.1.13)(rxjs@7.8.1) + specifier: ^10.2.8 + version: 10.2.8(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) '@nestjs/config': specifier: ^3.1.1 version: 3.1.1(@nestjs/common@10.2.8)(reflect-metadata@0.1.13) '@nestjs/core': specifier: ^10.0.0 version: 10.2.8(@nestjs/common@10.2.8)(@nestjs/platform-express@10.2.8)(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/mapped-types': + specifier: '*' + version: 2.0.3(@nestjs/common@10.2.8)(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13) '@nestjs/platform-express': specifier: ^10.0.0 version: 10.2.8(@nestjs/common@10.2.8)(@nestjs/core@10.2.8) '@nestjs/typeorm': specifier: ^10.0.0 version: 10.0.0(@nestjs/common@10.2.8)(@nestjs/core@10.2.8)(reflect-metadata@0.1.13)(rxjs@7.8.1)(typeorm@0.3.17) + class-transformer: + specifier: ^0.5.1 + version: 0.5.1 + class-validator: + specifier: ^0.14.0 + version: 0.14.0 pg: specifier: ^8.11.3 version: 8.11.3 @@ -903,7 +912,7 @@ packages: - webpack-cli dev: true - /@nestjs/common@10.2.8(reflect-metadata@0.1.13)(rxjs@7.8.1): + /@nestjs/common@10.2.8(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1): resolution: {integrity: sha512-rmpwcdvq2IWMmsUVP8rsdKub6uDWk7dwCYo0aif50JTwcvcxzaP3iKVFKoSgvp0RKYu8h15+/AEOfaInmPpl0Q==} peerDependencies: class-transformer: '*' @@ -916,6 +925,8 @@ packages: class-validator: optional: true dependencies: + class-transformer: 0.5.1 + class-validator: 0.14.0 iterare: 1.2.1 reflect-metadata: 0.1.13 rxjs: 7.8.1 @@ -928,7 +939,7 @@ packages: '@nestjs/common': ^8.0.0 || ^9.0.0 || ^10.0.0 reflect-metadata: ^0.1.13 dependencies: - '@nestjs/common': 10.2.8(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/common': 10.2.8(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) dotenv: 16.3.1 dotenv-expand: 10.0.0 lodash: 4.17.21 @@ -954,7 +965,7 @@ packages: '@nestjs/websockets': optional: true dependencies: - '@nestjs/common': 10.2.8(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/common': 10.2.8(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) '@nestjs/platform-express': 10.2.8(@nestjs/common@10.2.8)(@nestjs/core@10.2.8) '@nuxtjs/opencollective': 0.3.2 fast-safe-stringify: 2.1.1 @@ -967,13 +978,32 @@ packages: transitivePeerDependencies: - encoding + /@nestjs/mapped-types@2.0.3(@nestjs/common@10.2.8)(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13): + resolution: {integrity: sha512-40Zdqg98lqoF0+7ThWIZFStxgzisK6GG22+1ABO4kZiGF/Tu2FE+DYLw+Q9D94vcFWizJ+MSjNN4ns9r6hIGxw==} + peerDependencies: + '@nestjs/common': ^8.0.0 || ^9.0.0 || ^10.0.0 + class-transformer: ^0.4.0 || ^0.5.0 + class-validator: ^0.13.0 || ^0.14.0 + reflect-metadata: ^0.1.12 + peerDependenciesMeta: + class-transformer: + optional: true + class-validator: + optional: true + dependencies: + '@nestjs/common': 10.2.8(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) + class-transformer: 0.5.1 + class-validator: 0.14.0 + reflect-metadata: 0.1.13 + dev: false + /@nestjs/platform-express@10.2.8(@nestjs/common@10.2.8)(@nestjs/core@10.2.8): resolution: {integrity: sha512-WoSSVtwIRc5AdGMHWVzWZK4JZLT0f4o2xW8P9gQvcX+omL8W1kXCfY8GQYXNBG84XmBNYH8r0FtC8oMe/lH5NQ==} peerDependencies: '@nestjs/common': ^10.0.0 '@nestjs/core': ^10.0.0 dependencies: - '@nestjs/common': 10.2.8(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/common': 10.2.8(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) '@nestjs/core': 10.2.8(@nestjs/common@10.2.8)(@nestjs/platform-express@10.2.8)(reflect-metadata@0.1.13)(rxjs@7.8.1) body-parser: 1.20.2 cors: 2.8.5 @@ -1011,7 +1041,7 @@ packages: '@nestjs/platform-express': optional: true dependencies: - '@nestjs/common': 10.2.8(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/common': 10.2.8(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) '@nestjs/core': 10.2.8(@nestjs/common@10.2.8)(@nestjs/platform-express@10.2.8)(reflect-metadata@0.1.13)(rxjs@7.8.1) '@nestjs/platform-express': 10.2.8(@nestjs/common@10.2.8)(@nestjs/core@10.2.8) tslib: 2.6.2 @@ -1026,7 +1056,7 @@ packages: rxjs: ^7.2.0 typeorm: ^0.3.0 dependencies: - '@nestjs/common': 10.2.8(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/common': 10.2.8(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) '@nestjs/core': 10.2.8(@nestjs/common@10.2.8)(@nestjs/platform-express@10.2.8)(reflect-metadata@0.1.13)(rxjs@7.8.1) reflect-metadata: 0.1.13 rxjs: 7.8.1 @@ -1297,6 +1327,9 @@ packages: '@types/superagent': 4.1.21 dev: true + /@types/validator@13.11.6: + resolution: {integrity: sha512-HUgHujPhKuNzgNXBRZKYexwoG+gHKU+tnfPqjWXFghZAnn73JElicMkuSKJyLGr9JgyA8IgK7fj88IyA9rwYeQ==} + /@types/yargs-parser@21.0.3: resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==} dev: true @@ -2092,6 +2125,16 @@ packages: resolution: {integrity: sha512-0TNiGstbQmCFwt4akjjBg5pLRTSyj/PkWQ1ZoO2zntmg9yLqSRxwEa4iCfQLGjqhiqBfOJa7W/E8wfGrTDmlZQ==} dev: true + /class-transformer@0.5.1: + resolution: {integrity: sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==} + + /class-validator@0.14.0: + resolution: {integrity: sha512-ct3ltplN8I9fOwUd8GrP8UQixwff129BkEtuWDKL5W45cQuLd19xqmTLu5ge78YDm/fdje6FMt0hGOhl0lii3A==} + dependencies: + '@types/validator': 13.11.6 + libphonenumber-js: 1.10.49 + validator: 13.11.0 + /cli-cursor@3.1.0: resolution: {integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==} engines: {node: '>=8'} @@ -4313,6 +4356,9 @@ packages: type-check: 0.4.0 dev: true + /libphonenumber-js@1.10.49: + resolution: {integrity: sha512-gvLtyC3tIuqfPzjvYLH9BmVdqzGDiSi4VjtWe2fAgSdBf0yt8yPmbNnRIHNbR5IdtVkm0ayGuzwQKTWmU0hdjQ==} + /lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} dev: true @@ -6065,6 +6111,10 @@ packages: convert-source-map: 2.0.0 dev: true + /validator@13.11.0: + resolution: {integrity: sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==} + engines: {node: '>= 0.10'} + /vary@1.1.2: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} diff --git a/be/algo-with-me-api/src/app.controller.spec.ts b/be/algo-with-me-api/src/app.controller.spec.ts deleted file mode 100644 index ccea57f..0000000 --- a/be/algo-with-me-api/src/app.controller.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; - -import { AppController } from './app.controller'; -import { AppService } from './app.service'; - -describe('AppController', () => { - let appController: AppController; - - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); - - appController = app.get(AppController); - }); - - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); - }); -}); diff --git a/be/algo-with-me-api/src/app.controller.ts b/be/algo-with-me-api/src/app.controller.ts deleted file mode 100644 index 0a8e973..0000000 --- a/be/algo-with-me-api/src/app.controller.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Controller, Get } from '@nestjs/common'; - -import { AppService } from '@src/app.service'; - -@Controller() -export class AppController { - constructor(private readonly appService: AppService) {} - - @Get() - getHello(): string { - return this.appService.getHello(); - } -} diff --git a/be/algo-with-me-api/src/app.module.ts b/be/algo-with-me-api/src/app.module.ts index b6a83c8..e4d68c9 100644 --- a/be/algo-with-me-api/src/app.module.ts +++ b/be/algo-with-me-api/src/app.module.ts @@ -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: [ @@ -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], }), + CompetitionModule, ], - controllers: [AppController], - providers: [AppService], }) export class AppModule {} diff --git a/be/algo-with-me-api/src/app.service.ts b/be/algo-with-me-api/src/app.service.ts deleted file mode 100644 index 8c5c12b..0000000 --- a/be/algo-with-me-api/src/app.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AppService { - getHello(): string { - return 'Hello api!'; - } -} diff --git a/be/algo-with-me-api/src/competition/competition.module.ts b/be/algo-with-me-api/src/competition/competition.module.ts new file mode 100644 index 0000000..e086641 --- /dev/null +++ b/be/algo-with-me-api/src/competition/competition.module.ts @@ -0,0 +1,13 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; + +import { Problem } from './entities/problem.entity'; +import { ProblemController } from './problem.controller'; +import { ProblemService } from './problem.service'; + +@Module({ + imports: [TypeOrmModule.forFeature([Problem])], + controllers: [ProblemController], + providers: [ProblemService], +}) +export class CompetitionModule {} diff --git a/be/algo-with-me-api/src/competition/dto/create-problem.dto.ts b/be/algo-with-me-api/src/competition/dto/create-problem.dto.ts new file mode 100644 index 0000000..eaaf82f --- /dev/null +++ b/be/algo-with-me-api/src/competition/dto/create-problem.dto.ts @@ -0,0 +1,30 @@ +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; + + 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; + return problem; + } +} diff --git a/be/algo-with-me-api/src/competition/entities/problem.entity.ts b/be/algo-with-me-api/src/competition/entities/problem.entity.ts new file mode 100644 index 0000000..f7fb770 --- /dev/null +++ b/be/algo-with-me-api/src/competition/entities/problem.entity.ts @@ -0,0 +1,34 @@ +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; + + @CreateDateColumn() + createdAt: Date; + + @UpdateDateColumn() + updatedAt: Date; +} diff --git a/be/algo-with-me-api/src/competition/problem.controller.ts b/be/algo-with-me-api/src/competition/problem.controller.ts new file mode 100644 index 0000000..a490606 --- /dev/null +++ b/be/algo-with-me-api/src/competition/problem.controller.ts @@ -0,0 +1,35 @@ +import { Controller, Get, Post, Body, UsePipes, ValidationPipe } from '@nestjs/common'; + +import { CreateProblemDto } from './dto/create-problem.dto'; +import { ProblemService } from './problem.service'; + +@Controller('competitions/problems') +export class ProblemController { + constructor(private readonly problemService: ProblemService) {} + + @Post() + @UsePipes(new ValidationPipe({ transform: true })) + create(@Body() createProblemDto: CreateProblemDto) { + return this.problemService.create(createProblemDto); + } + + @Get() + findAll() { + return this.problemService.findAll(); + } + + // @Get(':id') + // findOne(@Param('id') id: string) { + // return this.problemService.findOne(+id); + // } + + // @Patch(':id') + // update(@Param('id') id: string, @Body() updateCompetitionDto: UpdateCompetitionDto) { + // return this.competitionService.update(+id, updateCompetitionDto); + // } + + // @Delete(':id') + // remove(@Param('id') id: string) { + // return this.problemService.remove(+id); + // } +} diff --git a/be/algo-with-me-api/src/competition/problem.service.ts b/be/algo-with-me-api/src/competition/problem.service.ts new file mode 100644 index 0000000..2eeed86 --- /dev/null +++ b/be/algo-with-me-api/src/competition/problem.service.ts @@ -0,0 +1,35 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; + +import { CreateProblemDto } from './dto/create-problem.dto'; +import { Problem } from './entities/problem.entity'; + +@Injectable() +export class ProblemService { + constructor(@InjectRepository(Problem) private readonly problemRepository: Repository) {} + + create(createProblemDto: CreateProblemDto) { + console.log(createProblemDto.toEntity()); + const problem: Problem = createProblemDto.toEntity(); + + const savedProblem = this.problemRepository.save(problem); + return savedProblem; + } + + findAll() { + return this.problemRepository.find(); + } + + // findOne(id: number) { + // return `This action returns a #${id} competition`; + // } + + // update(id: number, updateCompetitionDto: UpdateCompetitionDto) { + // return `This action updates a #${id} competition`; + // } + + // remove(id: number) { + // return `This action removes a #${id} competition`; + // } +} diff --git a/be/algo-with-me-api/tsconfig.json b/be/algo-with-me-api/tsconfig.json index f52a0b1..5627a41 100644 --- a/be/algo-with-me-api/tsconfig.json +++ b/be/algo-with-me-api/tsconfig.json @@ -18,7 +18,7 @@ "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false, "paths": { - "@src/*": ["./src/*"], + "@src/*": ["./src/*"] } } } From 7e537ef1968df38f7c0cdec81f38f0f960e8cdba Mon Sep 17 00:00:00 2001 From: rladydgn <39542757+rladydgn@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:05:34 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=EB=AC=B8=EC=A0=9C=20=EB=8B=A8?= =?UTF-8?q?=EA=B1=B4=20=EC=A1=B0=ED=9A=8C,=20=EB=AA=A8=EB=91=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C,=20=EC=82=AD=EC=A0=9C=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/competition/problem.controller.ts | 27 ++++++++++++------- .../src/competition/problem.service.ts | 22 +++++++++------ 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/be/algo-with-me-api/src/competition/problem.controller.ts b/be/algo-with-me-api/src/competition/problem.controller.ts index a490606..95b9150 100644 --- a/be/algo-with-me-api/src/competition/problem.controller.ts +++ b/be/algo-with-me-api/src/competition/problem.controller.ts @@ -1,4 +1,13 @@ -import { Controller, Get, Post, Body, UsePipes, ValidationPipe } from '@nestjs/common'; +import { + Controller, + Get, + Post, + Body, + UsePipes, + ValidationPipe, + Param, + Delete, +} from '@nestjs/common'; import { CreateProblemDto } from './dto/create-problem.dto'; import { ProblemService } from './problem.service'; @@ -18,18 +27,18 @@ export class ProblemController { return this.problemService.findAll(); } - // @Get(':id') - // findOne(@Param('id') id: string) { - // return this.problemService.findOne(+id); - // } + @Get(':id') + findOne(@Param('id') id: number) { + return this.problemService.findOne(id); + } // @Patch(':id') // update(@Param('id') id: string, @Body() updateCompetitionDto: UpdateCompetitionDto) { // return this.competitionService.update(+id, updateCompetitionDto); // } - // @Delete(':id') - // remove(@Param('id') id: string) { - // return this.problemService.remove(+id); - // } + @Delete(':id') + remove(@Param('id') id: number) { + this.problemService.remove(id); + } } diff --git a/be/algo-with-me-api/src/competition/problem.service.ts b/be/algo-with-me-api/src/competition/problem.service.ts index 2eeed86..f158a52 100644 --- a/be/algo-with-me-api/src/competition/problem.service.ts +++ b/be/algo-with-me-api/src/competition/problem.service.ts @@ -17,19 +17,25 @@ export class ProblemService { return savedProblem; } - findAll() { - return this.problemRepository.find(); + async findAll() { + const problems = await this.problemRepository.find(); + return problems.map((problem: Problem) => { + return { + id: problem.id, + title: problem.title, + }; + }); } - // findOne(id: number) { - // return `This action returns a #${id} competition`; - // } + findOne(id: number) { + return this.problemRepository.findOneBy({ id }); + } // update(id: number, updateCompetitionDto: UpdateCompetitionDto) { // return `This action updates a #${id} competition`; // } - // remove(id: number) { - // return `This action removes a #${id} competition`; - // } + remove(id: number) { + this.problemRepository.delete({ id }); + } } From 7ac3e268a589d1e0926936f82fe7cfcec4b2a9ec Mon Sep 17 00:00:00 2001 From: rladydgn <39542757+rladydgn@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:18:36 +0900 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20path=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 대회 화면용 문제 api를 따로 만들 예정이라 수정했습니다 --- be/algo-with-me-api/src/competition/problem.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/algo-with-me-api/src/competition/problem.controller.ts b/be/algo-with-me-api/src/competition/problem.controller.ts index 95b9150..c926d12 100644 --- a/be/algo-with-me-api/src/competition/problem.controller.ts +++ b/be/algo-with-me-api/src/competition/problem.controller.ts @@ -12,7 +12,7 @@ import { import { CreateProblemDto } from './dto/create-problem.dto'; import { ProblemService } from './problem.service'; -@Controller('competitions/problems') +@Controller('problems') export class ProblemController { constructor(private readonly problemService: ProblemService) {} From 7a63337a8b667f675097b5d0e2ef324527c03339 Mon Sep 17 00:00:00 2001 From: rladydgn <39542757+rladydgn@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:29:33 +0900 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=EB=8B=A8=EA=B1=B4=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=EA=B0=92=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/competition/problem.service.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/be/algo-with-me-api/src/competition/problem.service.ts b/be/algo-with-me-api/src/competition/problem.service.ts index f158a52..0f6471e 100644 --- a/be/algo-with-me-api/src/competition/problem.service.ts +++ b/be/algo-with-me-api/src/competition/problem.service.ts @@ -27,8 +27,15 @@ export class ProblemService { }); } - findOne(id: number) { - return this.problemRepository.findOneBy({ id }); + async findOne(id: number) { + const problem = await this.problemRepository.findOneBy({ id }); + return { + id: problem.id, + title: problem.title, + timeLimit: problem.timeLimit, + memoryLimit: problem.memoryLimit, + createdAt: problem.createdAt, + }; } // update(id: number, updateCompetitionDto: UpdateCompetitionDto) { From ab5debb0f040c77c4955a49ef2599014a9e34d92 Mon Sep 17 00:00:00 2001 From: rladydgn <39542757+rladydgn@users.noreply.github.com> Date: Tue, 14 Nov 2023 17:03:58 +0900 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=EB=AC=B8=EC=A0=9C=20=ED=95=98?= =?UTF-8?q?=EB=82=98=20=EA=B0=80=EC=A0=B8=EC=98=AC=20=EB=95=8C=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EB=82=B4=EC=9A=A9=20=ED=8C=8C=EC=9D=BC=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=9D=BD=EC=96=B4=EC=98=A4=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/algo-with-me-api/src/competition/problem.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/be/algo-with-me-api/src/competition/problem.service.ts b/be/algo-with-me-api/src/competition/problem.service.ts index 0f6471e..bb6bfd3 100644 --- a/be/algo-with-me-api/src/competition/problem.service.ts +++ b/be/algo-with-me-api/src/competition/problem.service.ts @@ -2,6 +2,9 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; +import { readFileSync } from 'fs'; +import * as path from 'path'; + import { CreateProblemDto } from './dto/create-problem.dto'; import { Problem } from './entities/problem.entity'; @@ -29,11 +32,16 @@ export class ProblemService { async findOne(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); + console.log(paths); + const content = readFileSync(paths).toString(); return { id: problem.id, title: problem.title, timeLimit: problem.timeLimit, memoryLimit: problem.memoryLimit, + content: content, createdAt: problem.createdAt, }; } From b9c0207c16efd3efccdceb0607358c9d57d16e6c Mon Sep 17 00:00:00 2001 From: rladydgn <39542757+rladydgn@users.noreply.github.com> Date: Tue, 14 Nov 2023 17:46:50 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat:=20=EB=8C=80=ED=9A=8C=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=EC=9A=A9=20api=20=EA=B5=AC=ED=98=84,=20consle.log=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C,=20=ED=8C=8C=EC=9D=BC=20=EC=97=86=EC=9D=84?= =?UTF-8?q?=20=EC=8B=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC,=20solution?= =?UTF-8?q?Code=20=EC=BB=AC=EB=9F=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/competition/competition.controller.ts | 13 ++++++++ .../src/competition/competition.module.ts | 6 ++-- .../src/competition/competition.service.ts | 31 +++++++++++++++++++ .../src/competition/dto/create-problem.dto.ts | 4 +++ .../competition/entities/problem.entity.ts | 3 ++ .../src/competition/problem.service.ts | 7 ++--- 6 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 be/algo-with-me-api/src/competition/competition.controller.ts create mode 100644 be/algo-with-me-api/src/competition/competition.service.ts diff --git a/be/algo-with-me-api/src/competition/competition.controller.ts b/be/algo-with-me-api/src/competition/competition.controller.ts new file mode 100644 index 0000000..8dd928d --- /dev/null +++ b/be/algo-with-me-api/src/competition/competition.controller.ts @@ -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); + } +} diff --git a/be/algo-with-me-api/src/competition/competition.module.ts b/be/algo-with-me-api/src/competition/competition.module.ts index e086641..75197a5 100644 --- a/be/algo-with-me-api/src/competition/competition.module.ts +++ b/be/algo-with-me-api/src/competition/competition.module.ts @@ -1,13 +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], - providers: [ProblemService], + controllers: [ProblemController, CompetitionController], + providers: [ProblemService, CompetitionService], }) export class CompetitionModule {} diff --git a/be/algo-with-me-api/src/competition/competition.service.ts b/be/algo-with-me-api/src/competition/competition.service.ts new file mode 100644 index 0000000..8cc3d2a --- /dev/null +++ b/be/algo-with-me-api/src/competition/competition.service.ts @@ -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) {} + + 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, + }; + } +} diff --git a/be/algo-with-me-api/src/competition/dto/create-problem.dto.ts b/be/algo-with-me-api/src/competition/dto/create-problem.dto.ts index eaaf82f..76f2f8f 100644 --- a/be/algo-with-me-api/src/competition/dto/create-problem.dto.ts +++ b/be/algo-with-me-api/src/competition/dto/create-problem.dto.ts @@ -18,6 +18,9 @@ export class CreateProblemDto { @IsNotEmpty() frameCode: string; + @IsNotEmpty() + solutionCode: string; + toEntity(): Problem { const problem = new Problem(); problem.title = this.title; @@ -25,6 +28,7 @@ export class CreateProblemDto { problem.memoryLimit = this.memoryLimit; problem.testcaseNum = this.testcaseNum; problem.frameCode = this.frameCode; + problem.solutionCode = this.solutionCode; return problem; } } diff --git a/be/algo-with-me-api/src/competition/entities/problem.entity.ts b/be/algo-with-me-api/src/competition/entities/problem.entity.ts index f7fb770..381d293 100644 --- a/be/algo-with-me-api/src/competition/entities/problem.entity.ts +++ b/be/algo-with-me-api/src/competition/entities/problem.entity.ts @@ -26,6 +26,9 @@ export class Problem { @Column('text') frameCode: string; + @Column('text') + solutionCode: string; + @CreateDateColumn() createdAt: Date; diff --git a/be/algo-with-me-api/src/competition/problem.service.ts b/be/algo-with-me-api/src/competition/problem.service.ts index bb6bfd3..f4dfb8a 100644 --- a/be/algo-with-me-api/src/competition/problem.service.ts +++ b/be/algo-with-me-api/src/competition/problem.service.ts @@ -1,8 +1,8 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; -import { readFileSync } from 'fs'; +import { existsSync, readFileSync } from 'fs'; import * as path from 'path'; import { CreateProblemDto } from './dto/create-problem.dto'; @@ -13,7 +13,6 @@ export class ProblemService { constructor(@InjectRepository(Problem) private readonly problemRepository: Repository) {} create(createProblemDto: CreateProblemDto) { - console.log(createProblemDto.toEntity()); const problem: Problem = createProblemDto.toEntity(); const savedProblem = this.problemRepository.save(problem); @@ -34,7 +33,7 @@ export class ProblemService { const problem = await this.problemRepository.findOneBy({ id }); const fileName = id.toString() + '.md'; const paths = path.join(process.env.PROBLEM_PATH, id.toString(), fileName); - console.log(paths); + if (!existsSync(paths)) throw new NotFoundException('문제 파일을 찾을 수 없습니다.'); const content = readFileSync(paths).toString(); return { id: problem.id,