package fr.eni.enchere.controllers;

import fr.eni.enchere.bll.UserService;
import fr.eni.enchere.bo.UserProfil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/inscription")
public class InscriptionController {

    private final UserService userService;

    public InscriptionController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping
    public String viewInscription(Model model) {
        model.addAttribute("user", new UserProfil());
        return "inscription";
    }

    @PostMapping("/newUser")
    public String setUser(@ModelAttribute UserProfil user) {
        userService.setUtilisateur(user);
        return "redirect:/accueil";
    }

}
