From 435d6efb31a087524d25b49aebd23a57eca5f40a Mon Sep 17 00:00:00 2001 From: Shun Usami Date: Sat, 4 Nov 2023 18:57:15 +0900 Subject: [PATCH] [backend] Add swagger description and entity to user controller --- backend/src/user/entities/user.entity.ts | 17 ++++++++++++++++- backend/src/user/user.controller.ts | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/backend/src/user/entities/user.entity.ts b/backend/src/user/entities/user.entity.ts index 4f82c145..3d87a751 100644 --- a/backend/src/user/entities/user.entity.ts +++ b/backend/src/user/entities/user.entity.ts @@ -1 +1,16 @@ -export class User {} +import { User } from '@prisma/client'; +import { ApiProperty } from '@nestjs/swagger'; + +export class UserEntity implements User { + @ApiProperty() + id: number; + + @ApiProperty() + email: string; + + @ApiProperty({ required: false, nullable: true }) + name: string | null; + + @ApiProperty() + password: string; +} diff --git a/backend/src/user/user.controller.ts b/backend/src/user/user.controller.ts index edd6b0a1..bcac2795 100644 --- a/backend/src/user/user.controller.ts +++ b/backend/src/user/user.controller.ts @@ -11,12 +11,16 @@ import { UserService } from './user.service'; import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; import { User as UserModel } from '@prisma/client'; +import { ApiCreatedResponse, ApiOkResponse, ApiNoContentResponse, ApiTags } from '@nestjs/swagger'; +import { UserEntity } from './entities/user.entity'; @Controller('user') +@ApiTags('user') export class UserController { constructor(private readonly userService: UserService) {} @Post() + @ApiCreatedResponse({ type: UserEntity }) create( @Body() createUserDto: CreateUserDto, ): Promise { @@ -24,16 +28,19 @@ export class UserController { } @Get() + @ApiOkResponse({ type: [UserEntity] }) findAll() { return this.userService.findAll(); } @Get(':id') + @ApiOkResponse({ type: UserEntity }) findOne(@Param('id') id: string) { return this.userService.findOne(+id); } @Patch(':id') + @ApiOkResponse({ type: UserEntity }) update( @Param('id') id: string, @Body() updateUserDto: UpdateUserDto, @@ -42,6 +49,7 @@ export class UserController { } @Delete(':id') + @ApiNoContentResponse() remove(@Param('id') id: string) { return this.userService.remove(+id); }