mirror of
https://github.com/Prominence/car-repair-site.git
synced 2026-01-10 12:16:44 +03:00
Added basic functionality: entities, changelogs, home page.
This commit is contained in:
parent
6f796eb13a
commit
22f1ebf607
26
.gitignore
vendored
Normal file
26
.gitignore
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
.idea/*
|
||||||
|
target/*
|
||||||
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# car-repair-site
|
||||||
|
Learning purposes
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
BIN
java-task-1.1.jpg
Normal file
BIN
java-task-1.1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 103 KiB |
BIN
java-task-1.2.jpg
Normal file
BIN
java-task-1.2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
128
pom.xml
Normal file
128
pom.xml
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.1.2.RELEASE</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>car-repair</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>car-repair</name>
|
||||||
|
<description>Demo project for Spring Boot</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nz.net.ultraq.thymeleaf</groupId>
|
||||||
|
<artifactId>thymeleaf-layout-dialect</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- hot swapping, disable cache for template, enable live reload -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.liquibase</groupId>
|
||||||
|
<artifactId>liquibase-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.liquibase</groupId>
|
||||||
|
<artifactId>liquibase-maven-plugin</artifactId>
|
||||||
|
<version>3.5.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.webjars</groupId>
|
||||||
|
<artifactId>bootstrap</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.webjars</groupId>
|
||||||
|
<artifactId>jquery</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.liquibase</groupId>
|
||||||
|
<artifactId>liquibase-maven-plugin</artifactId>
|
||||||
|
<version>3.5.3</version>
|
||||||
|
<configuration>
|
||||||
|
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
|
||||||
|
</configuration>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.liquibase.ext</groupId>
|
||||||
|
<artifactId>liquibase-hibernate5</artifactId>
|
||||||
|
<version>3.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-beans</artifactId>
|
||||||
|
<version>4.1.7.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-jpa</artifactId>
|
||||||
|
<version>1.7.3.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-jdbc</artifactId>
|
||||||
|
<version>2.0.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>1.19</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.validation</groupId>
|
||||||
|
<artifactId>validation-api</artifactId>
|
||||||
|
<version>2.0.0.Final</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.github.prominence.carrepair;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
|
||||||
|
@EnableJpaRepositories("com.github.prominence.carrepair.repository")
|
||||||
|
@EntityScan("com.github.prominence.carrepair.model")
|
||||||
|
@SpringBootApplication
|
||||||
|
public class CarRepairApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(CarRepairApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.github.prominence.carrepair.conf;
|
||||||
|
|
||||||
|
import nz.net.ultraq.thymeleaf.LayoutDialect;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ApplicationConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LayoutDialect layoutDialect() {
|
||||||
|
return new LayoutDialect();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.github.prominence.carrepair.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/client")
|
||||||
|
public class ClientController {
|
||||||
|
|
||||||
|
@RequestMapping
|
||||||
|
public String index(Model model) {
|
||||||
|
|
||||||
|
return "client/index";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.github.prominence.carrepair.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/")
|
||||||
|
public class HomeController {
|
||||||
|
|
||||||
|
@RequestMapping
|
||||||
|
public String index() {
|
||||||
|
return "home";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package com.github.prominence.carrepair.controller.advice;
|
||||||
|
|
||||||
|
import com.github.prominence.carrepair.service.CarRepairService;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalInfoAdvice {
|
||||||
|
|
||||||
|
private final CarRepairService carRepairService;
|
||||||
|
|
||||||
|
public GlobalInfoAdvice(CarRepairService carRepairService) {
|
||||||
|
this.carRepairService = carRepairService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("globalInfo")
|
||||||
|
public void addBadgeInfo(Model model) {
|
||||||
|
model.addAttribute("clientsCount", carRepairService.getClientCount());
|
||||||
|
model.addAttribute("mechanicsCount", carRepairService.getMechanicCount());
|
||||||
|
model.addAttribute("ordersCount", carRepairService.getOrderCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package com.github.prominence.carrepair.enums;
|
||||||
|
|
||||||
|
public enum OrderStatus {
|
||||||
|
SCHEDULED,
|
||||||
|
DONE,
|
||||||
|
ACCEPTED
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package com.github.prominence.carrepair.model;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "client")
|
||||||
|
public class Client extends Person {
|
||||||
|
|
||||||
|
@Column(name = "phoneNo")
|
||||||
|
private String phoneNo;
|
||||||
|
|
||||||
|
public Client(String firstName, String middleName, String lastName, String phoneNo) {
|
||||||
|
super(firstName, middleName, lastName);
|
||||||
|
this.phoneNo = phoneNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhoneNo() {
|
||||||
|
return phoneNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhoneNo(String phoneNo) {
|
||||||
|
this.phoneNo = phoneNo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.github.prominence.carrepair.model;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "mechanic")
|
||||||
|
public class Mechanic extends Person {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "hourlyPayment")
|
||||||
|
private BigDecimal hourlyPayment;
|
||||||
|
|
||||||
|
public Mechanic(String firstName, String middleName, String lastName, BigDecimal hourlyPayment) {
|
||||||
|
super(firstName, middleName, lastName);
|
||||||
|
this.hourlyPayment = hourlyPayment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mechanic() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getHourlyPayment() {
|
||||||
|
return hourlyPayment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHourlyPayment(BigDecimal hourlyPayment) {
|
||||||
|
this.hourlyPayment = hourlyPayment;
|
||||||
|
}
|
||||||
|
}
|
||||||
119
src/main/java/com/github/prominence/carrepair/model/Order.java
Normal file
119
src/main/java/com/github/prominence/carrepair/model/Order.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
package com.github.prominence.carrepair.model;
|
||||||
|
|
||||||
|
import com.github.prominence.carrepair.enums.OrderStatus;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "orders")
|
||||||
|
public class Order {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "client_id", nullable = false)
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "mechanic_id", nullable = false)
|
||||||
|
private Mechanic mechanic;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "createdOn")
|
||||||
|
private LocalDateTime createdOn;
|
||||||
|
|
||||||
|
@Column(name = "finishedOn")
|
||||||
|
private LocalDateTime finishedOn;
|
||||||
|
|
||||||
|
@Column(name = "totalPrice")
|
||||||
|
private BigDecimal totalPrice;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "orderStatus")
|
||||||
|
private String orderStatus = OrderStatus.SCHEDULED.toString();
|
||||||
|
|
||||||
|
public Order(String description, Client client, Mechanic mechanic, LocalDateTime createdOn, LocalDateTime finishedOn, BigDecimal totalPrice, String orderStatus) {
|
||||||
|
this.description = description;
|
||||||
|
this.client = client;
|
||||||
|
this.mechanic = mechanic;
|
||||||
|
this.createdOn = createdOn;
|
||||||
|
this.finishedOn = finishedOn;
|
||||||
|
this.totalPrice = totalPrice;
|
||||||
|
this.orderStatus = orderStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient(Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mechanic getMechanic() {
|
||||||
|
return mechanic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMechanic(Mechanic mechanic) {
|
||||||
|
this.mechanic = mechanic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getCreatedOn() {
|
||||||
|
return createdOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedOn(LocalDateTime createdOn) {
|
||||||
|
this.createdOn = createdOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getFinishedOn() {
|
||||||
|
return finishedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinishedOn(LocalDateTime finishedOn) {
|
||||||
|
this.finishedOn = finishedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getTotalPrice() {
|
||||||
|
return totalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalPrice(BigDecimal totalPrice) {
|
||||||
|
this.totalPrice = totalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderStatus getOrderStatus() {
|
||||||
|
return OrderStatus.valueOf(orderStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderStatus(OrderStatus orderStatus) {
|
||||||
|
this.orderStatus = orderStatus.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
package com.github.prominence.carrepair.model;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
abstract public class Person {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "firstName")
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
@Column(name = "middleName")
|
||||||
|
private String middleName;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "lastName")
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
public Person(String firstName, String middleName, String lastName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.middleName = middleName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMiddleName() {
|
||||||
|
return middleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMiddleName(String middleName) {
|
||||||
|
this.middleName = middleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.github.prominence.carrepair.repository;
|
||||||
|
|
||||||
|
import com.github.prominence.carrepair.model.Client;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ClientRepository extends JpaRepository<Client, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package com.github.prominence.carrepair.repository;
|
||||||
|
|
||||||
|
import com.github.prominence.carrepair.model.Mechanic;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface MechanicRepository extends JpaRepository<Mechanic, Long> {
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package com.github.prominence.carrepair.repository;
|
||||||
|
|
||||||
|
import com.github.prominence.carrepair.model.Order;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface OrderRepository extends JpaRepository<Order, Long> {
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package com.github.prominence.carrepair.service;
|
||||||
|
|
||||||
|
import com.github.prominence.carrepair.repository.ClientRepository;
|
||||||
|
import com.github.prominence.carrepair.repository.MechanicRepository;
|
||||||
|
import com.github.prominence.carrepair.repository.OrderRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CarRepairService {
|
||||||
|
|
||||||
|
private ClientRepository clientRepository;
|
||||||
|
private MechanicRepository mechanicRepository;
|
||||||
|
private OrderRepository orderRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public CarRepairService(ClientRepository clientRepository, MechanicRepository mechanicRepository, OrderRepository orderRepository) {
|
||||||
|
this.clientRepository = clientRepository;
|
||||||
|
this.mechanicRepository = mechanicRepository;
|
||||||
|
this.orderRepository = orderRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getClientCount() {
|
||||||
|
return clientRepository.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMechanicCount() {
|
||||||
|
return mechanicRepository.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getOrderCount() {
|
||||||
|
return orderRepository.count();
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/resources/application.properties
Normal file
29
src/main/resources/application.properties
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# ===============================
|
||||||
|
# DATABASE
|
||||||
|
# ===============================
|
||||||
|
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
spring.datasource.url=jdbc:mysql://localhost:3306/car_repair
|
||||||
|
spring.datasource.username=carrepair
|
||||||
|
spring.datasource.password=carrepair
|
||||||
|
|
||||||
|
# ===============================
|
||||||
|
# JPA / HIBERNATE
|
||||||
|
# ===============================
|
||||||
|
|
||||||
|
spring.jpa.show-sql=true
|
||||||
|
spring.jpa.hibernate.ddl-auto=validate
|
||||||
|
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
|
||||||
|
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
|
||||||
|
#spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
|
||||||
|
#spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
|
||||||
|
#spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
|
||||||
|
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||||
|
spring.jpa.open-in-view=false
|
||||||
|
|
||||||
|
|
||||||
|
# liquibase
|
||||||
|
spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml
|
||||||
|
|
||||||
|
# thymeleaf
|
||||||
|
spring.thymeleaf.cache = false
|
||||||
9
src/main/resources/db/changelog/changelog-master.xml
Normal file
9
src/main/resources/db/changelog/changelog-master.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<databaseChangeLog
|
||||||
|
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
|
||||||
|
<include file="v1/changelog-v.1.0-cumulative.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
78
src/main/resources/db/changelog/v1/changelog-initial.xml
Normal file
78
src/main/resources/db/changelog/v1/changelog-initial.xml
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
|
||||||
|
<changeSet id="1" author="prominence">
|
||||||
|
<createTable tableName="client">
|
||||||
|
<column autoIncrement="true" name="id" type="BIGINT">
|
||||||
|
<constraints nullable="false" primaryKey="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="firstName" type="VARCHAR(64)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="middleName" type="VARCHAR(64)"/>
|
||||||
|
<column name="lastName" type="VARCHAR(64)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="2" author="prominence">
|
||||||
|
<addColumn tableName="client">
|
||||||
|
<column name="phoneNo" type="VARCHAR(32)"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="3" author="prominence">
|
||||||
|
<createTable tableName="mechanic">
|
||||||
|
<column autoIncrement="true" name="id" type="BIGINT">
|
||||||
|
<constraints nullable="false" primaryKey="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="firstName" type="VARCHAR(64)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="middleName" type="VARCHAR(64)"/>
|
||||||
|
<column name="lastName" type="VARCHAR(64)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="hourlyPayment" type="NUMERIC">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="4" author="prominence">
|
||||||
|
<createTable tableName="orders">
|
||||||
|
<column autoIncrement="true" name="id" type="BIGINT">
|
||||||
|
<constraints nullable="false" primaryKey="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="description" type="VARCHAR(1024)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="client_id" type="BIGINT">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="mechanic_id" type="BIGINT">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="createdOn" type="DATETIME">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="finishedOn" type="DATETIME"/>
|
||||||
|
<column name="totalPrice" type="NUMERIC"/>
|
||||||
|
<column name="orderStatus" type="VARCHAR(16)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
<addForeignKeyConstraint baseTableName="orders"
|
||||||
|
baseColumnNames="client_id"
|
||||||
|
constraintName="order_client_fk"
|
||||||
|
referencedTableName="client"
|
||||||
|
referencedColumnNames="id"
|
||||||
|
onDelete="CASCADE"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="orders"
|
||||||
|
baseColumnNames="mechanic_id"
|
||||||
|
constraintName="order_mechanic_fk"
|
||||||
|
referencedTableName="mechanic"
|
||||||
|
referencedColumnNames="id"
|
||||||
|
onDelete="CASCADE"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<databaseChangeLog
|
||||||
|
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
|
||||||
|
<include file="changelog-initial.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
11
src/main/resources/liquibase.properties
Normal file
11
src/main/resources/liquibase.properties
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
driver=com.mysql.cj.jdbc.Driver
|
||||||
|
url=jdbc:mysql://localhost:3306/car_repair
|
||||||
|
username=carrepair
|
||||||
|
password=carrepair
|
||||||
|
#referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
|
||||||
|
#referenceUrl=hibernate:spring:com.github.prominence.carrepair.model?dialect=org.hibernate.dialect.MySQL5Dialect
|
||||||
|
changeLogFile=src/main/resources/db/changelog/changelog-master.xml
|
||||||
|
#diffChangeLogFile=src/main/resources/liquibase-diff-changeLog.xml
|
||||||
|
|
||||||
|
# output of 'generateChangeLog'
|
||||||
|
#outputChangeLogFile=src/main/resources/db/changelog/v1/changelog-initial.xml
|
||||||
9
src/main/resources/messages.properties
Normal file
9
src/main/resources/messages.properties
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
default.title = Car Repair Service
|
||||||
|
|
||||||
|
badge.clients = Clients
|
||||||
|
badge.mechanics = Mechanics
|
||||||
|
badge.orders = Orders
|
||||||
|
|
||||||
|
home.requirements.label = Requirements
|
||||||
|
|
||||||
|
client.title = Clients
|
||||||
9
src/main/resources/messages_en.properties
Normal file
9
src/main/resources/messages_en.properties
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
default.title = Car Repair Service
|
||||||
|
|
||||||
|
badge.clients = Clients
|
||||||
|
badge.mechanics = Mechanics
|
||||||
|
badge.orders = Orders
|
||||||
|
|
||||||
|
home.requirements.label = Requirements
|
||||||
|
|
||||||
|
client.title = Clients
|
||||||
9
src/main/resources/messages_ru.properties
Normal file
9
src/main/resources/messages_ru.properties
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
default.title = Автосервис
|
||||||
|
|
||||||
|
badge.clients = Клиенты
|
||||||
|
badge.mechanics = Механики
|
||||||
|
badge.orders = Заказы
|
||||||
|
|
||||||
|
home.requirements.label = Требования
|
||||||
|
|
||||||
|
client.title = Клиенты
|
||||||
2
src/main/resources/static/css/main.css
Normal file
2
src/main/resources/static/css/main.css
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
body {
|
||||||
|
}
|
||||||
BIN
src/main/resources/static/images/java-task-1.1.jpg
Normal file
BIN
src/main/resources/static/images/java-task-1.1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 103 KiB |
BIN
src/main/resources/static/images/java-task-1.2.jpg
Normal file
BIN
src/main/resources/static/images/java-task-1.2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
14
src/main/resources/templates/client/index.html
Normal file
14
src/main/resources/templates/client/index.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
|
layout:decorate="~{main}">
|
||||||
|
<head>
|
||||||
|
<title th:text="#{default.title}"></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div layout:fragment="content">
|
||||||
|
<h1 th:text="#{client.title}"></h1>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
18
src/main/resources/templates/home.html
Normal file
18
src/main/resources/templates/home.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
|
layout:decorate="~{main}">
|
||||||
|
<head>
|
||||||
|
<title th:text="#{default.title}"></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div layout:fragment="content">
|
||||||
|
<h1>Car Repair test project</h1>
|
||||||
|
<h2>
|
||||||
|
<span><th:block th:text="#{home.requirements.label}"/>:</span>
|
||||||
|
</h2>
|
||||||
|
<img src="images/java-task-1.1.jpg" alt="Requirements"/>
|
||||||
|
<img src="images/java-task-1.2.jpg" alt="Requirements"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
58
src/main/resources/templates/main.html
Normal file
58
src/main/resources/templates/main.html
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title th:text="#{default.title}">"</title>
|
||||||
|
<!-- Common styles and scripts -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/3.4.0/css/bootstrap.min.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-inverse">
|
||||||
|
<div class="container">
|
||||||
|
<div class="navbar-header">
|
||||||
|
<a class="navbar-brand" th:href="@{/}" th:text="#{default.title}"></a>
|
||||||
|
</div>
|
||||||
|
<div id="navbar" class="collapse navbar-collapse">
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li><a th:href="@{/client/}"><th:block th:text="#{badge.clients}"/> <span class="badge" th:text="${clientsCount}"></span></a></li>
|
||||||
|
<li><a href="#"><th:block th:text="#{badge.mechanics}"/> <span class="badge" th:text="${mechanicsCount}"></span></a></li>
|
||||||
|
<li><a href="#"><th:block th:text="#{badge.orders}"/> <span class="badge" th:text="${ordersCount}"></span></a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body">
|
||||||
|
<div layout:fragment="content">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body">
|
||||||
|
|
||||||
|
© 2019 <th:block th:text="#{default.title}"/>, Alexey Zinchenko
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<script src="/webjars/bootstrap/3.4.0/js/bootstrap.min.js"></script>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.github.prominence.carrepair;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class CarRepairApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user