Готовые таблицы services, components + триггер удаления клиента

This commit is contained in:
DyCTaTOR 2024-05-13 21:48:14 +04:00
parent aa2d317abb
commit d753a61cc1
21 changed files with 692 additions and 31 deletions

View File

@ -1,9 +1,6 @@
package com.example.autoservice.cars.api;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.modelmapper.ModelMapper;
import org.modelmapper.TypeToken;
@ -20,7 +17,6 @@ import com.example.autoservice.cars.model.CarsEntity;
import com.example.autoservice.cars.model.CarsGrouped;
import com.example.autoservice.cars.service.CarsService;
import com.example.autoservice.clients.api.ClientsDto;
import com.example.autoservice.clients.model.ClientsEntity;
import com.example.autoservice.core.configuration.Constants;
import jakarta.validation.Valid;
@ -41,18 +37,10 @@ public class CarsController {
this.modelMapper = modelMapper;
}
private CarsDto toDto(CarsEntity entity) {
return modelMapper.map(entity, CarsDto.class);
}
private CarsGroupedDto toGroupedDto(CarsGrouped entity){
private CarsGroupedDto toDto(CarsGrouped entity){
return modelMapper.map(entity, CarsGroupedDto.class);
}
private CarsEntity toEntity(CarsDto dto) {
return modelMapper.map(dto, CarsEntity.class);
}
private CarsEntity toEntity(CarsGroupedDto dto){
return modelMapper.map(dto, CarsEntity.class);
}
@ -63,7 +51,7 @@ public class CarsController {
@GetMapping
public String getAll(Model model){
List<CarsGroupedDto> cars = carsService.getAllCarsWithClients().stream().map(this::toGroupedDto).toList();
List<CarsGroupedDto> cars = carsService.getAllCarsWithClients().stream().map(this::toDto).toList();
model.addAttribute("cars",
cars);
return CARS_VIEW;
@ -95,7 +83,7 @@ public class CarsController {
if (id <= 0) {
throw new IllegalArgumentException();
}
model.addAttribute(CARS_ATTRIBUTE, toGroupedDto(carsService.getCarWithClient(id)));
model.addAttribute(CARS_ATTRIBUTE, toDto(carsService.getCarWithClient(id)));
model.addAttribute(CLIENTS_ATTRIBUTE, getClients());
return CARS_EDIT_VIEW;
}

View File

@ -14,7 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import com.example.autoservice.clients.service.ClientsService;
import com.example.autoservice.core.configuration.Constants;
import com.example.autoservice.cars.model.CarsEntity;
import com.example.autoservice.clients.model.ClientsEntity;
import com.example.autoservice.cars.service.CarsService;
import jakarta.validation.Valid;
@ -27,10 +29,12 @@ public class ClientsController {
private static final String CLIENTS_EDIT_VIEW = "client-edit";
private final ClientsService clientsService;
private final ModelMapper modelMapper;
private final CarsService carsService;
public ClientsController(ClientsService clientsService, ModelMapper modelMapper) {
public ClientsController(ClientsService clientsService, ModelMapper modelMapper, CarsService carsService) {
this.clientsService = clientsService;
this.modelMapper = modelMapper;
this.carsService = carsService;
}
private ClientsDto toDto(ClientsEntity entity) {
@ -98,6 +102,10 @@ public class ClientsController {
@PostMapping("/delete/{id}")
public String delete(
@PathVariable(name = "id") Long id) {
List<Long> cars = clientsService.getAllCarsForClient(id);
for (Long carId : cars){
carsService.delete(carId);
}
clientsService.delete(id);
return Constants.REDIRECT_VIEW + URL;
}

View File

@ -1,8 +1,16 @@
package com.example.autoservice.clients.repository;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import com.example.autoservice.cars.model.CarsEntity;
import com.example.autoservice.clients.model.ClientsEntity;
public interface ClientsRepository extends CrudRepository<ClientsEntity, Long> {
@Query("select c.id as id " +
"from CarsEntity c " +
"where c.client.id = :clientId")
public List<Long> findAllCarsForClient(Long clientId);
}

View File

@ -6,6 +6,7 @@ import java.util.stream.StreamSupport;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.example.autoservice.cars.model.CarsEntity;
import com.example.autoservice.clients.model.ClientsEntity;
import com.example.autoservice.clients.repository.ClientsRepository;
import com.example.autoservice.core.error.NotFoundException;
@ -54,4 +55,9 @@ public class ClientsService {
repository.delete(existsEntity);
return existsEntity;
}
@Transactional
public List<Long> getAllCarsForClient(Long clientId){
return repository.findAllCarsForClient(clientId);
}
}

View File

@ -0,0 +1,104 @@
package com.example.autoservice.components.api;
import java.util.List;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.autoservice.components.model.ComponentsEntity;
import com.example.autoservice.components.service.ComponentsService;
import com.example.autoservice.core.configuration.Constants;
import jakarta.validation.Valid;
@Controller
@RequestMapping(ComponentsController.URL)
public class ComponentsController {
public static final String URL = "/components";
private static final String COMPONENTS_VIEW = "components";
private static final String COMPONENTS_ATTRIBUTE = "components";
private static final String COMPONENTS_EDIT_VIEW = "component-edit";
private final ComponentsService componentsService;
private final ModelMapper modelMapper;
public ComponentsController(ComponentsService componentsService, ModelMapper modelMapper) {
this.componentsService = componentsService;
this.modelMapper = modelMapper;
}
private ComponentsDto toDto(ComponentsEntity entity) {
return modelMapper.map(entity, ComponentsDto.class);
}
private ComponentsEntity toEntity(ComponentsDto dto) {
return modelMapper.map(dto, ComponentsEntity.class);
}
@GetMapping
public String getAll(Model model){
List<ComponentsDto> components = componentsService.getAll().stream()
.map(this::toDto)
.toList();
model.addAttribute(COMPONENTS_ATTRIBUTE,
components);
return COMPONENTS_VIEW;
}
@GetMapping("/edit/")
public String create(Model model){
model.addAttribute(COMPONENTS_ATTRIBUTE, new ComponentsDto());
return COMPONENTS_EDIT_VIEW;
}
@PostMapping("/edit/")
public String create(
@ModelAttribute(name = COMPONENTS_ATTRIBUTE) @Valid ComponentsDto component,
BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
return COMPONENTS_EDIT_VIEW;
}
componentsService.create(toEntity(component));
return Constants.REDIRECT_VIEW + URL;
}
@GetMapping("/edit/{id}")
public String update(
@PathVariable(name = "id") Long id,
Model model) {
if (id <= 0) {
throw new IllegalArgumentException();
}
model.addAttribute(COMPONENTS_ATTRIBUTE, toDto(componentsService.get(id)));
return COMPONENTS_EDIT_VIEW;
}
@PostMapping("/edit/{id}")
public String update(
@PathVariable(name = "id") Long id,
@ModelAttribute(name = COMPONENTS_ATTRIBUTE) @Valid ComponentsDto component,
BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
return COMPONENTS_EDIT_VIEW;
}
if (id <= 0) {
throw new IllegalArgumentException();
}
componentsService.update(id, toEntity(component));
return Constants.REDIRECT_VIEW + URL;
}
@PostMapping("/delete/{id}")
public String delete(
@PathVariable(name = "id") Long id) {
componentsService.delete(id);
return Constants.REDIRECT_VIEW + URL;
}
}

View File

@ -0,0 +1,38 @@
package com.example.autoservice.components.api;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
public class ComponentsDto {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long id;
@NotNull
private String name;
@NotNull
private double price;
public Long getId(){
return id;
}
public void setId(Long id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price = price;
}
}

View File

@ -0,0 +1,38 @@
package com.example.autoservice.components.model;
import com.example.autoservice.core.model.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
@Entity
@Table(name = "components")
public class ComponentsEntity extends BaseEntity {
@Column(nullable = false, unique = false, length = 80)
private String name;
@Column(nullable = false, unique = false, length = 10)
private double price;
public ComponentsEntity(){}
public ComponentsEntity(String name, double price){
this.name = name;
this.price = price;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price = price;
}
}

View File

@ -0,0 +1,8 @@
package com.example.autoservice.components.repository;
import org.springframework.data.repository.CrudRepository;
import com.example.autoservice.components.model.ComponentsEntity;
public interface ComponentsRepository extends CrudRepository<ComponentsEntity, Long> {
}

View File

@ -0,0 +1,53 @@
package com.example.autoservice.components.service;
import java.util.List;
import java.util.stream.StreamSupport;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.example.autoservice.components.model.ComponentsEntity;
import com.example.autoservice.components.repository.ComponentsRepository;
import com.example.autoservice.core.error.NotFoundException;
@Service
public class ComponentsService {
private final ComponentsRepository repository;
public ComponentsService(ComponentsRepository repository) {
this.repository = repository;
}
@Transactional(readOnly = true)
public List<ComponentsEntity> getAll() {
return StreamSupport.stream(repository.findAll().spliterator(), false).toList();
}
@Transactional(readOnly = true)
public ComponentsEntity get(Long id) {
return repository.findById(id)
.orElseThrow(() -> new NotFoundException(ComponentsEntity.class, id));
}
@Transactional
public ComponentsEntity create(ComponentsEntity entity) {
if (entity == null) {
throw new IllegalArgumentException("Entity is null");
}
return repository.save(entity);
}
@Transactional
public ComponentsEntity update(Long id, ComponentsEntity entity) {
final ComponentsEntity existsEntity = get(id);
existsEntity.setName(entity.getName());
existsEntity.setPrice(entity.getPrice());
return repository.save(existsEntity);
}
@Transactional
public ComponentsEntity delete(Long id) {
final ComponentsEntity existsEntity = get(id);
repository.delete(existsEntity);
return existsEntity;
}
}

View File

@ -0,0 +1,104 @@
package com.example.autoservice.services.api;
import java.util.List;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.autoservice.services.model.ServicesEntity;
import com.example.autoservice.services.service.ServicesService;
import com.example.autoservice.core.configuration.Constants;
import jakarta.validation.Valid;
@Controller
@RequestMapping(ServicesController.URL)
public class ServicesController {
public static final String URL = "/services";
private static final String SERVICES_VIEW = "services";
private static final String SERVICES_ATTRIBUTE = "services";
private static final String SERVICES_EDIT_VIEW = "service-edit";
private final ServicesService servicesService;
private final ModelMapper modelMapper;
public ServicesController(ServicesService servicesService, ModelMapper modelMapper) {
this.servicesService = servicesService;
this.modelMapper = modelMapper;
}
private ServicesDto toDto(ServicesEntity entity) {
return modelMapper.map(entity, ServicesDto.class);
}
private ServicesEntity toEntity(ServicesDto dto) {
return modelMapper.map(dto, ServicesEntity.class);
}
@GetMapping
public String getAll(Model model){
List<ServicesDto> services = servicesService.getAll().stream()
.map(this::toDto)
.toList();
model.addAttribute(SERVICES_ATTRIBUTE,
services);
return SERVICES_VIEW;
}
@GetMapping("/edit/")
public String create(Model model){
model.addAttribute(SERVICES_ATTRIBUTE, new ServicesDto());
return SERVICES_EDIT_VIEW;
}
@PostMapping("/edit/")
public String create(
@ModelAttribute(name = SERVICES_ATTRIBUTE) @Valid ServicesDto service,
BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
return SERVICES_EDIT_VIEW;
}
servicesService.create(toEntity(service));
return Constants.REDIRECT_VIEW + URL;
}
@GetMapping("/edit/{id}")
public String update(
@PathVariable(name = "id") Long id,
Model model) {
if (id <= 0) {
throw new IllegalArgumentException();
}
model.addAttribute(SERVICES_ATTRIBUTE, toDto(servicesService.get(id)));
return SERVICES_EDIT_VIEW;
}
@PostMapping("/edit/{id}")
public String update(
@PathVariable(name = "id") Long id,
@ModelAttribute(name = SERVICES_ATTRIBUTE) @Valid ServicesDto service,
BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
return SERVICES_EDIT_VIEW;
}
if (id <= 0) {
throw new IllegalArgumentException();
}
servicesService.update(id, toEntity(service));
return Constants.REDIRECT_VIEW + URL;
}
@PostMapping("/delete/{id}")
public String delete(
@PathVariable(name = "id") Long id) {
servicesService.delete(id);
return Constants.REDIRECT_VIEW + URL;
}
}

View File

@ -0,0 +1,38 @@
package com.example.autoservice.services.api;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
public class ServicesDto {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long id;
@NotNull
private String name;
@NotNull
private double price;
public Long getId(){
return id;
}
public void setId(Long id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price = price;
}
}

View File

@ -0,0 +1,38 @@
package com.example.autoservice.services.model;
import com.example.autoservice.core.model.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
@Entity
@Table(name = "services")
public class ServicesEntity extends BaseEntity {
@Column(nullable = false, unique = false, length = 80)
private String name;
@Column(nullable = false, unique = false, length = 10)
private double price;
public ServicesEntity(){}
public ServicesEntity(String name, double price){
this.name = name;
this.price = price;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price = price;
}
}

View File

@ -0,0 +1,8 @@
package com.example.autoservice.services.repository;
import org.springframework.data.repository.CrudRepository;
import com.example.autoservice.services.model.ServicesEntity;
public interface ServicesRepository extends CrudRepository<ServicesEntity, Long> {
}

View File

@ -0,0 +1,53 @@
package com.example.autoservice.services.service;
import java.util.List;
import java.util.stream.StreamSupport;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.example.autoservice.services.model.ServicesEntity;
import com.example.autoservice.services.repository.ServicesRepository;
import com.example.autoservice.core.error.NotFoundException;
@Service
public class ServicesService {
private final ServicesRepository repository;
public ServicesService(ServicesRepository repository) {
this.repository = repository;
}
@Transactional(readOnly = true)
public List<ServicesEntity> getAll() {
return StreamSupport.stream(repository.findAll().spliterator(), false).toList();
}
@Transactional(readOnly = true)
public ServicesEntity get(Long id) {
return repository.findById(id)
.orElseThrow(() -> new NotFoundException(ServicesEntity.class, id));
}
@Transactional
public ServicesEntity create(ServicesEntity entity) {
if (entity == null) {
throw new IllegalArgumentException("Entity is null");
}
return repository.save(entity);
}
@Transactional
public ServicesEntity update(Long id, ServicesEntity entity) {
final ServicesEntity existsEntity = get(id);
existsEntity.setName(entity.getName());
existsEntity.setPrice(entity.getPrice());
return repository.save(existsEntity);
}
@Transactional
public ServicesEntity delete(Long id) {
final ServicesEntity existsEntity = get(id);
repository.delete(existsEntity);
return existsEntity;
}
}

View File

@ -14,14 +14,14 @@
<table class="table">
<thead>
<tr>
<th scope = "col" class="w-25">ID</th>
<th scope = "col" class="w-10">ID</th>
<th scope = "col" class="w-25">Марка автомобиля</th>
<th scope = "col" class="w-10">Модель</th>
<th scope = "col" class="w-10">Серийный номер</th>
<th scope = "col" class="w-10">Имя владельца</th>
<th scope = "col" class="w-10">Фамилия владельца</th>
<th scope = "col"></th>
<th scope = "col"></th>
<th scope = "col" class="w-25">Модель</th>
<th scope = "col" class="w-25">Серийный номер</th>
<th scope = "col" class="w-20">Имя владельца</th>
<th scope = "col" class="w-20">Фамилия владельца</th>
<th scope = "col" class="w-10"></th>
<th scope = "col" class="w-10"></th>
</tr>
</thead>
<tbody>

View File

@ -15,13 +15,13 @@
<thead>
<tr>
<th scope = "col" class="w-10">ID</th>
<th scope = "col" class="w-10">Имя</th>
<th scope = "col" class="w-10">Фамилия</th>
<th scope = "col" class="w-25">Имя</th>
<th scope = "col" class="w-25">Фамилия</th>
<th scope = "col" class="w-10">Отчество</th>
<th scope = "col" class="w-10">Дата рождения</th>
<th scope = "col" class="w-10">Номер телефона</th>
<th scope = "col"></th>
<th scope = "col"></th>
<th scope = "col" class="w-25">Дата рождения</th>
<th scope = "col" class="w-25">Номер телефона</th>
<th scope = "col" class="w-10"></th>
<th scope = "col" class="w-10"></th>
</tr>
</thead>
<tbody>

View File

@ -0,0 +1,37 @@
<!DOCTYPE HTML>
<html lang="ru" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title>Редактировать компонент</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/css/style.css" />
</head>
<body>
<main>
<form action="#" th:action="@{/components/edit/{id}(id=${components.id})}" th:object="${components}" method="post">
<div class="mb-3">
<label for="id" class="form-label">ID</label>
<input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
</div>
<div class="mb-3">
<label for="name" class="form-label">Название</label>
<input type="text" th:field="*{name}" id="name" class="form-control">
<div th:if="${#fields.hasErrors('name')}" th:errors="*{name}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="price" class="form-label">Цена</label>
<input type="number" th:field="*{price}" id="price" class="form-control">
<div th:if="${#fields.hasErrors('price')}" th:errors="*{price}" class="invalid-feedback"></div>
</div>
<div class="mb-3 d-flex flex-row">
<button class="btn btn-primary me-2 button-fixed-width" type="submit">Сохранить</button>
<a class="btn btn-secondary button-fixed-width" href="/components">Отмена</a>
</div>
</form>
</main>
</body>
</html>

View File

@ -0,0 +1,45 @@
<!DOCTYPE HTML>
<html lang="ru"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Компоненты</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<main layout:fragment="content">
<form th:action="@{/components/edit/}" method="get" class="mb-3">
<button type="submit" class="btn btn-primary">Добавить компонент</button>
</form>
<table class="table">
<thead>
<tr>
<th scope = "col" class="w-10">ID</th>
<th scope = "col" class="w-25">Название</th>
<th scope = "col" class="w-10">Цена</th>
<th scope = "col" class="w-10"></th>
<th scope = "col" class="w-10"></th>
</tr>
</thead>
<tbody>
<tr th:each="component : ${components}">
<th scope="row" th:text="${component.id}"></th>
<td th:text="${component.name}"></td>
<td th:text="${component.price}"></td>
<td>
<form th:action="@{/components/edit/{id}(id=${component.id})}" method = "get">
<button type="submit" class="btn btn-link button-link">Редактировать</button>
</form>
</td>
<td>
<form th:action="@{/components/delete/{id}(id=${component.id})}" method="post">
<button type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">Удалить</button>
</form>
</td>
</tr>
</tbody>
</table>
</main>
</body>
</html>

View File

@ -28,7 +28,12 @@
<a class="nav-link" href="/cars">
Автомобили
</a>
<a class="nav-link" href="/h2-console/" target="_blank">Консоль H2</a>
<a class="nav-link" href="/components">
Компоненты
</a>
<a class="nav-link" href="/services">
Услуги
</a>
</ul>
</div>
</div>

View File

@ -0,0 +1,37 @@
<!DOCTYPE HTML>
<html lang="ru" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title>Редактировать услугу</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/css/style.css" />
</head>
<body>
<main>
<form action="#" th:action="@{/services/edit/{id}(id=${services.id})}" th:object="${services}" method="post">
<div class="mb-3">
<label for="id" class="form-label">ID</label>
<input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
</div>
<div class="mb-3">
<label for="name" class="form-label">Название</label>
<input type="text" th:field="*{name}" id="name" class="form-control">
<div th:if="${#fields.hasErrors('name')}" th:errors="*{name}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="price" class="form-label">Цена</label>
<input type="number" th:field="*{price}" id="price" class="form-control">
<div th:if="${#fields.hasErrors('price')}" th:errors="*{price}" class="invalid-feedback"></div>
</div>
<div class="mb-3 d-flex flex-row">
<button class="btn btn-primary me-2 button-fixed-width" type="submit">Сохранить</button>
<a class="btn btn-secondary button-fixed-width" href="/services">Отмена</a>
</div>
</form>
</main>
</body>
</html>

View File

@ -0,0 +1,45 @@
<!DOCTYPE HTML>
<html lang="ru"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Услуги</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<main layout:fragment="content">
<form th:action="@{/services/edit/}" method="get" class="mb-3">
<button type="submit" class="btn btn-primary">Добавить услугу</button>
</form>
<table class="table">
<thead>
<tr>
<th scope = "col" class="w-10">ID</th>
<th scope = "col" class="w-25">Название</th>
<th scope = "col" class="w-10">Цена</th>
<th scope = "col" class="w-10"></th>
<th scope = "col" class="w-10"></th>
</tr>
</thead>
<tbody>
<tr th:each="service : ${services}">
<th scope="row" th:text="${service.id}"></th>
<td th:text="${service.name}"></td>
<td th:text="${service.price}"></td>
<td>
<form th:action="@{/services/edit/{id}(id=${service.id})}" method = "get">
<button type="submit" class="btn btn-link button-link">Редактировать</button>
</form>
</td>
<td>
<form th:action="@{/services/delete/{id}(id=${service.id})}" method="post">
<button type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">Удалить</button>
</form>
</td>
</tr>
</tbody>
</table>
</main>
</body>
</html>