<div class="card text-center" style="width: 18rem;">
<img class="card-img-top" src="{% static 'images\Drinks.jpg' %}" alt="Card image cap" style="max-width: 500px; max-height: 500px; object-fit: cover;">
<div class="card-body">
<h5 class="card-title">Напитки</h5>
</div>
</div>
package com.example.karakum;
import ch.qos.logback.core.net.server.Client;
import com.example.karakum.persist.entity.*;
import com.example.karakum.repo.*;
import com.example.karakum.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Optional;
@Controller
public class LadaController {
private final ICarService carService;
private final IClientService clientService;
private final IConsultantService consultantService;
private final IBranchService branchService;
private final IContractService contractService;
@Autowired
public LadaController(ICarService carService, IClientService clientService, IConsultantService consultantService, IBranchService branchService, IContractService contractService, IContractCompositionServices contractCompositionServices) {
this.carService = carService;
this.clientService = clientService;
this.consultantService = consultantService;
this.branchService = branchService;
this.contractService = contractService;
}
@Autowired
private ClientRepository clientRepository;
@Autowired
private ConsultantRepository consultantRepository;
@Autowired
private BranchRepository branchRepository;
@Autowired
private CarRepository carRepository;
@Autowired
private ContractRepository contractRepository;
@GetMapping(value = "/clients")
public String getClient(Map model) {
model.put("clients", clientService.getAllClients());
return "client";
}
@GetMapping(value = "/cars")
public String getCars(Map model) {
model.put("cars", carService.getAllCars());
return "cars";
}
@GetMapping(value = "/consultants")
public String getConsultants(Map model) {
model.put("consultants", consultantService.getAllConsultants());
return "consultant";
}
@GetMapping(value = "/branches")
public String getBranches(Map model) {
model.put("branches", branchService.getAllBranches());
return "branch";
}
@GetMapping(value = "/contracts")
public String getContracts(Map model) {
model.put("contracts", contractService.getAllContracts());
return "contract";
}
/*
@GetMapping(value = "/compositions")
public String getCompositions(Map model){
model.put("compositions", contractService.getAllContracts());
return "composition";
}
*/
@Value("Lada Service")
private String title;
@GetMapping(value = {"/", "/index"})
public String index(Model model) {
model.addAttribute("title", title);
return "index";
}
@GetMapping(value = {"/clients/add"})
public String clientAdd(Model model) {
return "clientadd";
}
@PostMapping({"/clients/add"})
public String clientEntityAdd(@RequestParam String clientfn, @RequestParam String clientpassport, @RequestParam String clientbank, @RequestParam String clientbanknum, @RequestParam String clientsign, Model model) {
ClientEntity clientEntity = new ClientEntity(clientfn, clientpassport, clientbank, clientbanknum, clientsign);
clientRepository.save(clientEntity);
return "clientadd";
}
@GetMapping(value = "/consultants/add")
public String consultantAdd(Model model) {
return "consultantadd";
}
@PostMapping(value = "/consultants/add")
public String consultantEntityAdd(@RequestParam String consultantFullName, @RequestParam String consultantDateOfBirth, @RequestParam Integer consultantBranchId, Model model) throws ParseException {
Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(String.valueOf(consultantDateOfBirth));
ConsultantEntity consultantEntity = new ConsultantEntity(consultantFullName, date1, consultantBranchId);
consultantRepository.save(consultantEntity);
return "consultantadd";
}
@GetMapping(value = "/branches/add")
public String branchAdd(Model model) {
return "branchadd";
}
@PostMapping(value = "/branches/add")
public String branchEntityAdd(@RequestParam String branchName,
@RequestParam String branchInn,
@RequestParam String branchComandor,
@RequestParam Integer branchParking,
@RequestParam String branchAdress,
@RequestParam String branchPhone,
Model model) {
BranchEntity branchEntity = new BranchEntity(branchName, branchInn, branchComandor, branchParking, branchAdress, branchPhone);
branchRepository.save(branchEntity);
return "branchadd";
}
@GetMapping(value = "/cars/add")
public String carAdd(Model model) {
return "caradd";
}
@PostMapping(value = "/cars/add")
public String carEntityAdd(@RequestParam String carBrand,
@RequestParam String carModel,
@RequestParam Integer carBodyNum,
@RequestParam Integer carEngineNum,
@RequestParam String carBodyModel,
@RequestParam Integer carEngineVolume,
@RequestParam Integer carEnginePower,
@RequestParam String carWheel,
@RequestParam String carDriveBool,
@RequestParam Double carPrice,
@RequestParam String carType,
@RequestParam Integer carYear,
@RequestParam Integer carMileage,
@RequestParam String carBodyType,
Model model) {
CarEntity carEntity = new CarEntity(carBrand, carModel, carBodyNum, carEngineNum, carBodyModel, carEngineVolume, carEnginePower, carWheel, carDriveBool, carPrice, carType, carYear, carMileage, carBodyType);
carRepository.save(carEntity);
return "caradd";
}
@GetMapping(value = "/contracts/add")
public String contractAdd(Model model) {
return "contractadd";
}
@PostMapping(value = "/contracts/add")
public String contractEntityAdd(@RequestParam Integer contractBranchId, @RequestParam Integer contactConsultantId, @RequestParam Integer contractClientId, Model model) {
ContractEntity contractEntity = new ContractEntity(contractBranchId, contactConsultantId, contractClientId);
contractRepository.save(contractEntity);
return "contractadd";
}
/*EXPERIMENT*/
/* @PostMapping(value = "/client/{clientId}")
public String clientDetails(@PathVariable(value = "clientId") Integer clientId, Model model){
Optional client= clientRepository.findById(clientId);
model.addAttribute("client", client);
return "client-details";
} */
@GetMapping(value = "/clients/{clientId}")
public String clientDetails(Model model, @PathVariable Integer clientId) {
Optional client = null;
try {
client = clientRepository.findById(clientId);
model.addAttribute("allowDelete", false);
} catch (Exception ex) {
model.addAttribute("errorMessage", ex.getMessage());
}
model.addAttribute("client", client);
return "client-details";
}
}
package com.example.karakum.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
@AllArgsConstructor
public class ClientDto {
@NotBlank(message = "Input correct name")
private String clientFn;
@NotBlank(message = "Input correct passport data")
private String clientPassport;
@NotBlank(message = "Input correct bank name")
private String clientBank;
@NotBlank(message = "Input correct bank number")
private String clientBankNum;
@NotBlank(message = "Input correct client sign")
private String clientSign;
}