Skip to content

Commit

Permalink
[backend] Add swagger description and entity to user controller
Browse files Browse the repository at this point in the history
  • Loading branch information
usatie committed Nov 4, 2023
1 parent 135f888 commit 435d6ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 16 additions & 1 deletion backend/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,36 @@ 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<UserModel> {
return this.userService.create(createUserDto);
}

@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,
Expand All @@ -42,6 +49,7 @@ export class UserController {
}

@Delete(':id')
@ApiNoContentResponse()
remove(@Param('id') id: string) {
return this.userService.remove(+id);
}
Expand Down

0 comments on commit 435d6ef

Please sign in to comment.