import { Request, Response } from "express";

import { UserService } from "./user.service";

const userService = new UserService();

export class UserController {

    async getAll(
        req:Request,
        res:Response
    ) {
        const users = 
        await userService.getAll();

        res.json(users);
    }

    async getById(
        req:Request,
        res:Response
    ){
        const user =
        await userService.getById(
            req.params.id as string
        );

        res.json(user);
    }

    async create (
        req:Request,
        res:Response
    ) {
        const user =
        await userService.create(
            req.body
        );
        res.status(201).json(user);
    }

    async update(
        req:Request,
        res:Response
    ){
        const user =
        await userService.update(
            req.params.id as string,
            req.body
        );

        res.json(user);
    }

    async detele (
        req:Request,
        res:Response
    ) {
        await userService.delete(
            req.params.id as string
        );

        res.json({message: "Usuario eliminado"});
    }
    
}