diff --git a/data.mv.db b/data.mv.db new file mode 100644 index 0000000..768a936 Binary files /dev/null and b/data.mv.db differ diff --git a/src/main/java/com/webproglabs/lab1/SecurityConfiguration.java b/src/main/java/com/webproglabs/lab1/SecurityConfiguration.java index 307682f..87d3bc4 100644 --- a/src/main/java/com/webproglabs/lab1/SecurityConfiguration.java +++ b/src/main/java/com/webproglabs/lab1/SecurityConfiguration.java @@ -53,7 +53,6 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { - http.exceptionHandling().authenticationEntryPoint(delegatingEntryPoint()); http.headers().frameOptions().sameOrigin().and() .cors().and() diff --git a/src/main/java/com/webproglabs/lab1/lab34/dto/ShopDto.java b/src/main/java/com/webproglabs/lab1/lab34/dto/ShopDto.java index 0c27ba5..0bd54e5 100644 --- a/src/main/java/com/webproglabs/lab1/lab34/dto/ShopDto.java +++ b/src/main/java/com/webproglabs/lab1/lab34/dto/ShopDto.java @@ -29,7 +29,9 @@ public class ShopDto { public String getName() { return Name; } - + public void setName(String name) { + this.Name = name; + } public List getProducts() { return Products; } diff --git a/src/main/java/com/webproglabs/lab1/lab34/mvc/ShopMvcController.java b/src/main/java/com/webproglabs/lab1/lab34/mvc/ShopMvcController.java new file mode 100644 index 0000000..e6f078f --- /dev/null +++ b/src/main/java/com/webproglabs/lab1/lab34/mvc/ShopMvcController.java @@ -0,0 +1,57 @@ +package com.webproglabs.lab1.lab34.mvc; + +import com.webproglabs.lab1.lab34.dto.ShopDto; +import com.webproglabs.lab1.lab34.model.Shop; +import com.webproglabs.lab1.lab34.model.enums.UserRole; +import com.webproglabs.lab1.lab34.services.ShopService; +import org.springframework.security.access.annotation.Secured; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +@Controller +@RequestMapping("/shops") +public class ShopMvcController { + private final ShopService shopService; + + public ShopMvcController(ShopService shopService) { + this.shopService = shopService; + } + + @GetMapping + @Secured({UserRole.AsString.ADMIN}) + public String getShops(Model model) { + model.addAttribute("shops", shopService.findAllShops().stream().map(ShopDto::new).toList()); + model.addAttribute("shopDto", new ShopDto()); + return "shops"; + } + + @GetMapping(value = {"/edit/{Id}"}) + @Secured({UserRole.AsString.ADMIN}) + public String getShopEdit(@PathVariable Long Id, Model model) { + model.addAttribute("shop", shopService.findShopById(Id)); + model.addAttribute("shopDto", new ShopDto()); + return "shopEdit"; + } + + @PostMapping(value = {"/edit/{Id}"}) + @Secured({UserRole.AsString.ADMIN}) + public String editShop(@PathVariable Long Id, @ModelAttribute ShopDto shopDto) { + shopService.updateShop(Id, shopDto.getName()); + return "redirect:/shops"; + } + + @PostMapping(value = {"/create"}) + @Secured({UserRole.AsString.ADMIN}) + public String createShop(@ModelAttribute ShopDto shopDto) { + shopService.addShop(shopDto.getName()); + return "redirect:/shops"; + } + + @PostMapping(value = {"/delete/{Id}"}) + @Secured({UserRole.AsString.ADMIN}) + public String deleteShop(@PathVariable Long Id) { + shopService.deleteShop(Id); + return "redirect:/shops"; + } +} diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index cf4fb2d..8cc278c 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -22,8 +22,6 @@

- Профили - Лента Выход diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 0000000..509d6ac --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,13 @@ + + + +

+ + \ No newline at end of file diff --git a/src/main/resources/templates/shopEdit.html b/src/main/resources/templates/shopEdit.html new file mode 100644 index 0000000..81b24f4 --- /dev/null +++ b/src/main/resources/templates/shopEdit.html @@ -0,0 +1,21 @@ + + + +
+
Name
+
+
+

New Name:

+ + +
+
+

+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/shops.html b/src/main/resources/templates/shops.html new file mode 100644 index 0000000..b73a7a1 --- /dev/null +++ b/src/main/resources/templates/shops.html @@ -0,0 +1,27 @@ + + + +
+ +
+
+
+ +
+
+ +
+
+ +
+

Name:

+ + +
+ +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/signup.html b/src/main/resources/templates/signup.html index b511ffa..ccdec60 100644 --- a/src/main/resources/templates/signup.html +++ b/src/main/resources/templates/signup.html @@ -1,7 +1,8 @@ + layout:decorate="~{default}" +>