import { Body, Controller, Delete, Get, Injectable, Param, Patch, Post, Put } from '@nestjs/common';
import { UserService } from 'src/users/users.service';
import { Users } from '../entity/user.entity';

@Controller('users')
export class UserController {
    constructor(private readonly userService: UserService) { }

    @Get("/findAll")
    async findAll(): Promise<Users[]> {
        return await this.userService.findAll();
    }

    @Get("/findById/:id")
    async findById(@Param('id') id: number): Promise<Users> {
        return await this.userService.findOne(id);
    }

    @Delete("/remove/:id")
    async remove(@Param('id') id: number): Promise<void> {
        await this.userService.remove(id);
    }

    @Post("/save")
    async save(@Body() user: Users): Promise<Users> {
        return await this.userService.save(user)
    }

    @Put("/update")
    async update(@Param('id') id: number, @Body() user: Users): Promise<void> {
        this.userService.update(id, user);
    }
}