From 0476e4bbc077b3a0247a08b720e48f7466a3d114 Mon Sep 17 00:00:00 2001 From: Hanjunhee-1 Date: Fri, 18 Aug 2023 06:51:41 +0000 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20seed.ts=20=EB=82=B4=EC=9A=A9=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prisma/seed.ts | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/prisma/seed.ts b/prisma/seed.ts index 8b0f8ea..2048fdc 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -11,6 +11,12 @@ async function seed() { password: await hash('1234'), role: Role.Tutor }, + { + username: 'tutor02', + nickname: 'tutor02', + password: await hash('1234'), + role: Role.Tutor + }, { username: 'student01', nickname: 'student01', @@ -22,12 +28,82 @@ async function seed() { nickname: 'student02', password: await hash('1234'), role: Role.Student + }, + { + username: 'student03', + nickname: 'student03', + password: await hash('1234'), + role: Role.Student } ] await prisma.user.createMany({ data: users }) + + const repos: Prisma.RepoCreateManyInput[] = [ + { + name: "tutor01's repo1" + }, + { + name: "tutor01's repo2" + }, + { + name: "tutor02's repo1" + } + ] + + await prisma.repo.createMany({ + data: repos + }) + + const userRepos: Prisma.UserRepoCreateManyInput[] = [ + { + userId: 1, + repoId: 1 + }, + { + userId: 1, + repoId: 2 + }, + { + userId: 2, + repoId: 3 + }, + { + userId: 3, + repoId: 1 + }, + { + userId: 4, + repoId: 2 + }, + { + userId: 5, + repoId: 3 + } + ] + + await prisma.userRepo.createMany({ + data: userRepos + }) + + const problems: Prisma.ProblemCreateManyInput[] = [ + { + repoId: 1, + title: '첫번째 문제입니다.', + text: 'BubbleSort 를 구현하세요' + }, + { + repoId: 1, + title: '두번째 문제입니다.', + text: 'Binary Search 를 구현하세요' + } + ] + + await prisma.problem.createMany({ + data: problems + }) } seed() From 2914267f4c0b1dd366f938030a82bf87373f9079 Mon Sep 17 00:00:00 2001 From: Hanjunhee-1 Date: Fri, 18 Aug 2023 06:51:56 +0000 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20getRepoInfos=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/repos/repos.controller.ts | 10 ++++++++++ src/repos/repos.module.ts | 2 ++ src/repos/repos.service.ts | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/repos/repos.controller.ts b/src/repos/repos.controller.ts index 2e297fd..e93b7f6 100644 --- a/src/repos/repos.controller.ts +++ b/src/repos/repos.controller.ts @@ -2,10 +2,13 @@ import { Body, Controller, Get, + Param, + ParseIntPipe, Post, Put, Req, UploadedFile, + UseGuards, UseInterceptors } from '@nestjs/common' import { ReposService } from './repos.service' @@ -20,10 +23,17 @@ import { AuthenticatedRequest } from 'src/common/interface/authenticated-request import { Express } from 'express' import { FileInterceptor } from '@nestjs/platform-express' import { FileDto } from './dtos/file.dto' +import { RepoGuard } from 'src/problem/guards/repo.guard' @Controller('repos') export class ReposController { constructor(private readonly reposService: ReposService) {} + @Get(':repoId') + @UseGuards(RepoGuard) + async getRepoInfos(@Param('repoId', ParseIntPipe) repoId: number) { + return await this.reposService.getRepoInfos(repoId) + } + @Roles(Role.Tutor) @Post() async createRepo(@Body() createRepoDto: CreateRepoDto) { diff --git a/src/repos/repos.module.ts b/src/repos/repos.module.ts index 986e642..48524cd 100644 --- a/src/repos/repos.module.ts +++ b/src/repos/repos.module.ts @@ -1,8 +1,10 @@ import { Module } from '@nestjs/common' import { ReposController } from './repos.controller' import { ReposService } from './repos.service' +import { ProblemModule } from 'src/problem/problem.module' @Module({ + imports: [ProblemModule], controllers: [ReposController], providers: [ReposService] }) diff --git a/src/repos/repos.service.ts b/src/repos/repos.service.ts index c23bebf..86da3c3 100644 --- a/src/repos/repos.service.ts +++ b/src/repos/repos.service.ts @@ -18,6 +18,21 @@ export class ReposService { private readonly minio: MinioClientService ) {} + async getRepoInfos(repoId: number) { + return await this.prismaService.repo.findUnique({ + where: { + id: repoId + }, + include: { + Problem: { + include: { + testCase: true + } + } + } + }) + } + async createNewRepo(createRepoDto: CreateRepoDto) { const repoName = createRepoDto.repoName.toLowerCase() const repoExist = await this.prismaService.repo.findFirst({