Готовая таблица clients

This commit is contained in:
DyCTaTOR 2024-04-30 14:51:24 +04:00
parent ab60694642
commit afd48943a0
9 changed files with 140 additions and 75 deletions

View File

@ -35,6 +35,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0'
implementation 'org.postgresql:postgresql'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

View File

@ -3,6 +3,7 @@ package com.example.autoservice.clients.api;
import java.util.List;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@ -11,18 +12,17 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.autoservice.core.configuration.Constants;
import com.example.autoservice.clients.service.ClientsService;
import com.example.autoservice.clients.model.ClientsEntity;
import jakarta.validation.Valid;
@RestController
@RequestMapping(Constants.API_URL + "/clients")
@Controller
@RequestMapping(ClientsController.URL)
public class ClientsController {
public static final String URL = "/clients";
private static final String CLIENTS_VIEW = "clients";
private final ClientsService clientsService;
private final ModelMapper modelMapper;
@ -38,20 +38,20 @@ public class ClientsController {
private ClientsEntity toEntity(ClientsDto dto) {
return modelMapper.map(dto, ClientsEntity.class);
}
@GetMapping("/page1")
public String handlePage1(){
return "page1";
@GetMapping()
public String getAll(Model model){
List<ClientsDto> lines = clientsService.getAll().stream()
.map(this::toDto)
.toList();
model.addAttribute("clients",
lines);
return CLIENTS_VIEW;
}
@GetMapping("/error")
public String handleError() {
return "error";
}
@GetMapping
public List<ClientsDto> getAll() {
return clientsService.getAll().stream().map(this::toDto).toList();
}
// @GetMapping
// public List<ClientsDto> getAll() {
// return clientsService.getAll().stream().map(this::toDto).toList();
// }
@GetMapping("/{id}")
public ClientsDto get(@PathVariable(name = "id") Long id) {

View File

@ -26,43 +26,43 @@ public class ClientsDto{
this.id = id;
}
public String getFirst_Name(){
public String getFirst_name(){
return first_name;
}
public void setFirst_Name(String first_name){
this.first_name = first_name;
public void setFirst_name(String firstname){
this.first_name = firstname;
}
public String getLast_Name(){
public String getLast_name(){
return last_name;
}
public void setLast_Name(String last_name){
this.last_name = last_name;
public void setLast_name(String lastname){
this.last_name = lastname;
}
public String getMiddle_Name(){
public String getMiddle_name(){
return middle_name;
}
public void setMiddle_Name(String middle_name){
this.middle_name = middle_name;
public void setMiddle_name(String middlename){
this.middle_name = middlename;
}
public Date getDate_Birthday(){
public Date getDate_birthday(){
return date_birthday;
}
public void setDate_Birthday(Date date_birthday){
this.date_birthday = date_birthday;
public void setDate_birthday(Date datebirthday){
this.date_birthday = datebirthday;
}
public String getPhone_Number(){
public String getPhone_number(){
return phone_number;
}
public void setPhone_Number(String phone_number){
this.phone_number = phone_number;
public void setPhone_number(String phonenumber){
this.phone_number = phonenumber;
}
}

View File

@ -0,0 +1,67 @@
html,
body {
height: 100%;
}
h1 {
font-size: 1.5em;
}
h2 {
font-size: 1.25em;
}
h3 {
font-size: 1.1em;
}
td form {
margin: 0;
padding: 0;
margin-top: -.25em;
}
.button-fixed-width {
width: 150px;
}
.button-link {
padding: 0;
}
.invalid-feedback {
display: block;
}
.w-10 {
width: 10% !important;
}
.my-navbar {
background-color: #3c3c3c !important;
}
.my-navbar .link a:hover {
text-decoration: underline;
}
.my-navbar .logo {
width: 26px;
height: 26px;
}
.my-footer {
background-color: #2c2c2c;
height: 32px;
color: rgba(255, 255, 255, 0.5);
}
.cart-image {
width: 3.1rem;
padding: 0.25rem;
border-radius: 0.5rem;
}
.cart-item {
height: auto;
}

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cart2" viewBox="0 0 16 16">
<path d="M0 2.5A.5.5 0 0 1 .5 2H2a.5.5 0 0 1 .485.379L2.89 4H14.5a.5.5 0 0 1 .485.621l-1.5 6A.5.5 0 0 1 13 11H4a.5.5 0 0 1-.485-.379L1.61 3H.5a.5.5 0 0 1-.5-.5zM3.14 5l1.25 5h8.22l1.25-5H3.14zM5 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0zm9-1a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0z"/>
</svg>

After

Width:  |  Height:  |  Size: 465 B

View File

@ -0,0 +1,36 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity6">
<head>
<title>Getting Started: Serving Web Content</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<main class="container-fluid p-2">
<table>
<thead>
<tr>
<th scope = "col" class="w-10">ID</th>
<th scope = "col" class="w-10">First Name</th>
<th scope = "col" class="w-10">Last Name</th>
<th scope = "col" class="w-10">Middle Name</th>
<th scope = "col" class="w-10">Date of Birth</th>
<th scope = "col" class="w-10">Phone Number</th>
</tr>
</thead>
<tbody>
<tr th:each="c : ${clients}">
<th scope="row" th:text="${c.id}"></th>
<td th:text="${c.first_name}"></td>
<td th:text="${c.last_name}"></td>
<td th:text="${c.middle_name}"></td>
<td th:text="${c.date_birthday}"></td>
<td th:text="${c.phone_number}"></td>
</tr>
</tbody>
</table>
</main>
</body>
</html>

View File

@ -1,11 +0,0 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Error</h1>
<p>An unexpected error occurred. Please try again later.</p>
</body>
</html>

View File

@ -5,6 +5,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p>Get your clients <a href="/page1">here</a></p>
<p>Get your clients <a href="/clients">here</a></p>
</body>
</html>

View File

@ -1,31 +0,0 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<table>
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Middle Name</th>
<th>Date of Birth</th>
<th>Phone Number</th>
</tr>
</thead>
<tbody>
<tr th:each="client : ${clients}">
<td th:text="${client.id}"></td>
<td th:text="${client.firstName}"></td>
<td th:text="${client.lastName}"></td>
<td th:text="${client.middleName}"></td>
<td th:text="${client.dateOfBirth}"></td>
<td th:text="${client.phoneNumber}"></td>
</tr>
</tbody>
</table>
</body>
</html>