save enchere

This commit is contained in:
Parpaillax
2024-04-25 15:39:50 +02:00
parent 8ebddc6d18
commit a898b160b7
6 changed files with 97 additions and 12 deletions

View File

@@ -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;
}
}