[b3f2adb] | 1 | package com.example.eatys_app.controller;
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | import com.example.eatys_app.model.Korisnik;
|
---|
| 5 | import com.example.eatys_app.service.SeSostoiOdService;
|
---|
| 6 | import jakarta.servlet.http.HttpServletRequest;
|
---|
| 7 | import org.springframework.security.core.Authentication;
|
---|
| 8 | import org.springframework.stereotype.Controller;
|
---|
| 9 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
| 10 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 11 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
| 12 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 13 |
|
---|
| 14 | @Controller
|
---|
| 15 | @RequestMapping("/se-sostoi-od")
|
---|
| 16 | public class SeSostoiOdController {
|
---|
| 17 |
|
---|
| 18 | private final SeSostoiOdService seSostoiOdService;
|
---|
| 19 |
|
---|
| 20 | public SeSostoiOdController(SeSostoiOdService seSostoiOdService) {
|
---|
| 21 | this.seSostoiOdService = seSostoiOdService;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | @PostMapping("/add-obrok/{id}")
|
---|
| 25 | public String addObrokToShoppingCart(@PathVariable Integer id,@RequestParam Integer kolicina, Authentication authentication, HttpServletRequest req) {
|
---|
| 26 | try {
|
---|
| 27 | String username = req.getRemoteUser();
|
---|
| 28 | this.seSostoiOdService.create(username, id, kolicina);
|
---|
| 29 | return "redirect:/shopping-cart";
|
---|
| 30 | } catch (RuntimeException exception) {
|
---|
| 31 | return "redirect:/shopping-cart?error=" + exception.getMessage();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | @PostMapping("/delete-obrok/{id}")
|
---|
| 38 | public String deleteObrokFromShoppingCart(@PathVariable Integer id, Authentication authentication, HttpServletRequest req) {
|
---|
| 39 | try {
|
---|
| 40 | String username = req.getRemoteUser();
|
---|
| 41 | this.seSostoiOdService.delete(username, id);
|
---|
| 42 | return "redirect:/shopping-cart";
|
---|
| 43 | } catch (RuntimeException exception) {
|
---|
| 44 | return "redirect:/shopping-cart?error=" + exception.getMessage();
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | @PostMapping("/payment")
|
---|
| 50 | public String paymentFromShoppingCart(Authentication authentication, HttpServletRequest req) {
|
---|
| 51 | try {
|
---|
| 52 | String username = req.getRemoteUser();
|
---|
| 53 | this.seSostoiOdService.payment(username);
|
---|
| 54 | return "naplata.html";
|
---|
| 55 | } catch (RuntimeException exception) {
|
---|
| 56 | return "redirect:/shopping-cart?error=" + exception.getMessage();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | }
|
---|