source: src/main/java/com/example/eatys_app/controller/SeSostoiOdController.java

Last change on this file was b3f2adb, checked in by Aleksandar Siljanoski <acewow3@…>, 14 months ago

Adding project to repo

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[b3f2adb]1package com.example.eatys_app.controller;
2
3
4import com.example.eatys_app.model.Korisnik;
5import com.example.eatys_app.service.SeSostoiOdService;
6import jakarta.servlet.http.HttpServletRequest;
7import org.springframework.security.core.Authentication;
8import org.springframework.stereotype.Controller;
9import org.springframework.web.bind.annotation.PathVariable;
10import org.springframework.web.bind.annotation.PostMapping;
11import org.springframework.web.bind.annotation.RequestMapping;
12import org.springframework.web.bind.annotation.RequestParam;
13
14@Controller
15@RequestMapping("/se-sostoi-od")
16public 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}
Note: See TracBrowser for help on using the repository browser.