Ajout des endpoints API User

This commit is contained in:
Emmy D'Anello 2024-12-07 11:05:32 +01:00
parent 9b3fe93f4f
commit 4486e99225
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
8 changed files with 105 additions and 2 deletions

View File

@ -1,9 +1,10 @@
import { Module } from '@nestjs/common' import { Module } from '@nestjs/common'
import { PrismaService } from './prisma/prisma.service' import { PrismaService } from './prisma/prisma.service'
import { PrismaModule } from './prisma/prisma.module' import { PrismaModule } from './prisma/prisma.module'
import { UsersModule } from './users/users.module'
@Module({ @Module({
imports: [PrismaModule], imports: [PrismaModule, UsersModule],
providers: [PrismaService], providers: [PrismaService],
}) })
export class AppModule {} export class AppModule {}

View File

@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common' import { Injectable } from '@nestjs/common'
import { PrismaClient } from '@prisma/client'
@Injectable() @Injectable()
export class PrismaService {} export class PrismaService extends PrismaClient {}

View File

@ -0,0 +1,16 @@
import { ApiProperty } from "@nestjs/swagger";
import { User } from "@prisma/client";
export class UserEntity implements User {
@ApiProperty({description: "Identifiant unique"})
id: number
@ApiProperty({description: "Nom de læ joueur⋅se"})
name: string
@ApiProperty({description: "Nombre de jetons dont dispose actuellement læ joueur⋅se"})
money: number
@ApiProperty({description: "Est-ce que cet⋅te joueur⋅se est cellui actuellement en course"})
currentRunner: boolean
}

View File

@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
describe('UsersController', () => {
let controller: UsersController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
providers: [UsersService],
}).compile();
controller = module.get<UsersController>(UsersController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -0,0 +1,21 @@
import { Controller, Get, Param } from '@nestjs/common'
import { UsersService } from './users.service'
import { ApiOkResponse } from '@nestjs/swagger'
import { UserEntity } from './entities/user.entity'
@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {}
@Get()
@ApiOkResponse({ type: UserEntity, isArray: true })
findAll() {
return this.usersService.findAll()
}
@Get(':id')
@ApiOkResponse({ type: UserEntity })
findOne(@Param('id') id: string) {
return this.usersService.findOne(+id)
}
}

View File

@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'
import { UsersService } from './users.service'
import { UsersController } from './users.controller'
import { PrismaModule } from 'src/prisma/prisma.module'
@Module({
controllers: [UsersController],
providers: [UsersService],
imports: [PrismaModule],
})
export class UsersModule {}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing'
import { UsersService } from './users.service'
describe('UsersService', () => {
let service: UsersService
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UsersService],
}).compile()
service = module.get<UsersService>(UsersService)
})
it('should be defined', () => {
expect(service).toBeDefined()
})
})

View File

@ -0,0 +1,15 @@
import { Injectable } from '@nestjs/common'
import { PrismaService } from 'src/prisma/prisma.service'
@Injectable()
export class UsersService {
constructor(private prisma: PrismaService) {}
findAll() {
return this.prisma.user.findMany()
}
findOne(id: number) {
return this.prisma.user.findUnique({ where: { id } })
}
}