From ec87eb9ab4d286b6b8547dfed345ada18e77d7f5 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Sun, 28 Apr 2024 18:14:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F,=20=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=20=D0=B8=D1=81=D1=80=D0=BF=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 19 +++++++++++++++++-- .../autoservice/AutoserviceApplication.java | 19 +++++++++++++++++-- .../clients/api/ClientsController.java | 8 ++++++-- .../autoservice/clients/api/ClientsDto.java | 6 ++++++ .../clients/repository/ClientsRepository.java | 2 +- .../clients/service/ClientsService.java | 12 ++++++------ src/main/resources/application.properties | 17 ++++++++++++++--- 7 files changed, 67 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index 00d4f38..51565ac 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,18 @@ plugins { group = 'com.example' version = '0.0.1-SNAPSHOT' +defaultTasks 'bootRun' + +jar { + enabled = false +} + +bootJar { + archiveFileName = String.format('%s-%s.jar', rootProject.name, version) +} + +assert System.properties['java.specification.version'] == '17' || '21' || '19' + java { sourceCompatibility = '17' } @@ -16,13 +28,16 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter:2.4.5' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' implementation 'org.modelmapper:modelmapper:3.2.0' - implementation 'org.postgresql-postgresql-runtime' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.postgresql:postgresql' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' } tasks.named('test') { diff --git a/src/main/java/com/example/autoservice/AutoserviceApplication.java b/src/main/java/com/example/autoservice/AutoserviceApplication.java index e6557e8..96adbbd 100644 --- a/src/main/java/com/example/autoservice/AutoserviceApplication.java +++ b/src/main/java/com/example/autoservice/AutoserviceApplication.java @@ -1,14 +1,29 @@ package com.example.autoservice; +import java.util.Objects; + import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication -public class AutoserviceApplication implements CommandLineRunner{ +import com.example.autoservice.clients.service.ClientsService; +@SpringBootApplication +public class AutoserviceApplication implements CommandLineRunner { + + private final ClientsService clientsService; + public AutoserviceApplication(ClientsService clientsService) { + this.clientsService = clientsService; + } public static void main(String[] args) { SpringApplication.run(AutoserviceApplication.class, args); } + @Override + public void run(String... args) throws Exception { + if (args.length > 0 && Objects.equals("--populate", args[0])) { + + } + } + } diff --git a/src/main/java/com/example/autoservice/clients/api/ClientsController.java b/src/main/java/com/example/autoservice/clients/api/ClientsController.java index 70bcecc..c25f256 100644 --- a/src/main/java/com/example/autoservice/clients/api/ClientsController.java +++ b/src/main/java/com/example/autoservice/clients/api/ClientsController.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.example.demo.core.configuration.Constants; +import com.example.autoservice.core.configuration.Constants; import com.example.autoservice.clients.service.ClientsService; import com.example.autoservice.clients.model.ClientsEntity; @@ -24,11 +24,15 @@ public class ClientsController { private final ClientsService clientsService; private final ModelMapper modelMapper; - public DepartmentController(ClientsService clientsService, ModelMapper modelMapper) { + public ClientsController(ClientsService clientsService, ModelMapper modelMapper) { this.clientsService = clientsService; this.modelMapper = modelMapper; } + public String showClientsPage(){ + return "clients"; + } + private ClientsDto toDto(ClientsEntity entity) { return modelMapper.map(entity, ClientsDto.class); } diff --git a/src/main/java/com/example/autoservice/clients/api/ClientsDto.java b/src/main/java/com/example/autoservice/clients/api/ClientsDto.java index 21bec1c..366620f 100644 --- a/src/main/java/com/example/autoservice/clients/api/ClientsDto.java +++ b/src/main/java/com/example/autoservice/clients/api/ClientsDto.java @@ -1,5 +1,11 @@ package com.example.autoservice.clients.api; +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import jakarta.validation.constraints.NotNull; + public class ClientsDto{ @JsonProperty(access = JsonProperty.Access.READ_ONLY) private Long id; diff --git a/src/main/java/com/example/autoservice/clients/repository/ClientsRepository.java b/src/main/java/com/example/autoservice/clients/repository/ClientsRepository.java index 35bed82..e72456a 100644 --- a/src/main/java/com/example/autoservice/clients/repository/ClientsRepository.java +++ b/src/main/java/com/example/autoservice/clients/repository/ClientsRepository.java @@ -4,7 +4,7 @@ import java.util.Optional; import org.springframework.data.repository.CrudRepository; -import com.example.autoservice.clients.model.ClientEntity; +import com.example.autoservice.clients.model.ClientsEntity; public interface ClientsRepository extends CrudRepository { } diff --git a/src/main/java/com/example/autoservice/clients/service/ClientsService.java b/src/main/java/com/example/autoservice/clients/service/ClientsService.java index 6a29be3..025cfd6 100644 --- a/src/main/java/com/example/autoservice/clients/service/ClientsService.java +++ b/src/main/java/com/example/autoservice/clients/service/ClientsService.java @@ -8,13 +8,13 @@ import org.springframework.transaction.annotation.Transactional; import com.example.autoservice.clients.model.ClientsEntity; import com.example.autoservice.clients.repository.ClientsRepository; -import com.example.demo.core.error.NotFoundException; +import com.example.autoservice.core.error.NotFoundException; @Service public class ClientsService { private final ClientsRepository repository; - public DepartmentService(ClientsRepository repository) { + public ClientsService(ClientsRepository repository) { this.repository = repository; } @@ -41,10 +41,10 @@ public class ClientsService { public ClientsEntity update(Long id, ClientsEntity entity) { final ClientsEntity existsEntity = get(id); existsEntity.setFirst_Name(entity.getFirst_Name()); - existsEntity.setLast_Name(entity.setLast_Name()); - existsEntity.setMiddle_Name(entity.setMiddle_Name()); - existsEntity.setDate_Birthday(entity.setDate_Birthday()); - existsEntity.setPhone_Number(entity.setPhone_Number()); + existsEntity.setLast_Name(entity.getLast_Name()); + existsEntity.setMiddle_Name(entity.getMiddle_Name()); + existsEntity.setDate_Birthday(entity.getDate_Birthday()); + existsEntity.setPhone_Number(entity.getPhone_Number()); return repository.save(existsEntity); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5cad5f5..cbc5aa3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,18 @@ -spring.application.name=autoservice -spring.datasource.url=jdbc:postgresql://localhost:5432/autoservice +# Server +spring.main.banner-mode=off +server.port=8080 +# Logger settings +# Available levels are: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF +logging.level.com.example.autoservice=DEBUG + +# JPA Settings +spring.datasource.url=jdbc:postgresql://192.168.56.101:5432/autoservice spring.datasource.username=postgres spring.datasource.password=postgres +spring.datasource.driver-class-name=org.postgresql.Driver +spring.jpa.hibernate.ddl-auto=update +spring.jpa.open-in-view=false +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -spring.jpa.hibernate.ddl-auto=update