Skip to content

Commit

Permalink
Merge pull request #48 from SKKU-EJS/feature/repoDetail
Browse files Browse the repository at this point in the history
getRepoInfos 메소드 구현
  • Loading branch information
Hanjunhee-1 authored Aug 18, 2023
2 parents 00282c7 + 33897de commit 21233c0
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
76 changes: 76 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions src/repos/repos.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import {
Body,
Controller,
Get,
Param,
ParseIntPipe,
Post,
Put,
Req,
UploadedFile,
UseGuards,
UseInterceptors
} from '@nestjs/common'
import { ReposService } from './repos.service'
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/repos/repos.module.ts
Original file line number Diff line number Diff line change
@@ -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]
})
Expand Down
15 changes: 15 additions & 0 deletions src/repos/repos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 21233c0

Please sign in to comment.