save enchere
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.EnchereService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.Enchere;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Controller()
|
||||
@RequestMapping("/enchere")
|
||||
public class EnchereController {
|
||||
|
||||
@Autowired
|
||||
private EnchereService enchereService;
|
||||
private UserService userService;
|
||||
|
||||
public EnchereController(EnchereService enchereService, UserService userService) {
|
||||
this.enchereService = enchereService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@PostMapping("/incEnchere")
|
||||
public String incEnchere(@ModelAttribute("enchere") Enchere enchere, @RequestParam("articleId") int articleId) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
enchere.setNoArticle(articleId);
|
||||
enchere.setNoUtilisateur(this.userService.utilisateurByName(authentication.getName()).getId());
|
||||
enchere.setDateEnchere(new Date());
|
||||
enchere.setMontantEnchere(enchere.getMontantEnchere());
|
||||
this.enchereService.setEnchere(enchere);
|
||||
return "redirect:/article/show?id=" + articleId;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user