34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { Controller, Get, Param } from '@nestjs/common';
|
|
import { UsersService } from './users.service';
|
|
import { User } from './user.entity';
|
|
import { ApiTags, ApiOperation, ApiParam, ApiResponse } from '@nestjs/swagger';
|
|
|
|
@ApiTags('Users')
|
|
@Controller('users')
|
|
export class UsersController {
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
@ApiOperation({ summary: 'Get user by username' })
|
|
@ApiParam({ name: 'username', type: 'string', description: 'The username to look up' })
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'User found',
|
|
type: User,
|
|
})
|
|
@ApiResponse({
|
|
status: 404,
|
|
description: 'User not found',
|
|
})
|
|
@Get(':username')
|
|
async getUser(@Param('username') username: string): Promise<User | null> {
|
|
return this.usersService.findOneByUsername(username);
|
|
}
|
|
|
|
@ApiOperation({ summary: 'Get all users' })
|
|
@ApiResponse({ status: 200, description: 'List of users', type: User, isArray: true})
|
|
@Get()
|
|
async findAll(): Promise<User[]> {
|
|
return this.usersService.findAll();
|
|
}
|
|
}
|