Полностью готовые круды clients

This commit is contained in:
DyCTaTOR 2024-05-03 15:13:00 +04:00
parent 8ba82c3ff6
commit 21cb55f3e3
3 changed files with 12 additions and 37 deletions

View File

@ -6,13 +6,10 @@ 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.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.autoservice.clients.service.ClientsService;
@ -98,28 +95,10 @@ public class ClientsController {
return Constants.REDIRECT_VIEW + URL;
}
// @GetMapping
// public List<ClientsDto> getAll() {
// return clientsService.getAll().stream().map(this::toDto).toList();
// }
@GetMapping("/{id}")
public ClientsDto get(@PathVariable(name = "id") Long id) {
return toDto(clientsService.get(id));
}
@PostMapping
public ClientsDto create(@RequestBody @Valid ClientsDto dto) {
return toDto(clientsService.create(toEntity(dto)));
}
@PutMapping("/{id}")
public ClientsDto update(@PathVariable(name = "id") Long id, @RequestBody ClientsDto dto) {
return toDto(clientsService.update(id, toEntity(dto)));
}
@DeleteMapping("/{id}")
public ClientsDto delete(@PathVariable(name = "id") Long id) {
return toDto(clientsService.delete(id));
@PostMapping("/delete/{id}")
public String delete(
@PathVariable(name = "id") Long id) {
clientsService.delete(id);
return Constants.REDIRECT_VIEW + URL;
}
}

View File

@ -1,6 +1,5 @@
package com.example.autoservice.clients.api;
import java.time.ZoneId;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -55,9 +54,8 @@ public class ClientsDto{
return date_birthday;
}
public void setDate_birthday(Date datebirthday){
this.date_birthday = datebirthday.toInstant().
atZone(ZoneId.systemDefault()).toLocalDate().toString();
public void setDate_birthday(String datebirthday){
date_birthday = datebirthday;
}
public String getPhone_number(){

View File

@ -1,7 +1,5 @@
package com.example.autoservice.clients.model;
import java.util.Date;
import com.example.autoservice.core.model.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@ -10,14 +8,14 @@ import jakarta.persistence.Table;
@Entity
@Table(name = "clients")
public class ClientsEntity extends BaseEntity{
@Column(nullable = false, unique = true, length = 30)
@Column(nullable = false, unique = false, length = 30)
private String first_name;
@Column(nullable = false, unique = false, length = 25)
private String last_name;
@Column(nullable = true, unique = false, length = 10)
private String middle_name;
@Column(nullable = true, unique = false)
private Date date_birthday;
private String date_birthday;
@Column(nullable = false, unique = true, length = 12)
private String phone_number;
@ -25,7 +23,7 @@ public class ClientsEntity extends BaseEntity{
}
public ClientsEntity(String first_name, String last_name, String middle_name, Date date_birthday, String phone_number){
public ClientsEntity(String first_name, String last_name, String middle_name, String date_birthday, String phone_number){
this.first_name = first_name;
this.last_name = last_name;
this.middle_name = middle_name;
@ -57,11 +55,11 @@ public class ClientsEntity extends BaseEntity{
this.middle_name = middle_name;
}
public Date getDate_Birthday(){
public String getDate_Birthday(){
return date_birthday;
}
public void setDate_Birthday(Date date_birthday){
public void setDate_Birthday(String date_birthday){
this.date_birthday = date_birthday;
}