Génération facture et location end date set
This commit is contained in:
@@ -2,10 +2,12 @@ package fr.eni.demo.controller;
|
||||
|
||||
import fr.eni.demo.bll.FactureService;
|
||||
import fr.eni.demo.bo.Facture;
|
||||
import fr.eni.demo.bo.Location;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -21,26 +23,45 @@ public class FactureController {
|
||||
@GetMapping
|
||||
public ResponseEntity<Map<String, Object>> getAllFactures() {
|
||||
List<Facture> result = factureService.getAll();
|
||||
return buildResponse(result);
|
||||
return buildResponse("List all order", true, result);
|
||||
}
|
||||
|
||||
// Factures par client
|
||||
@GetMapping("/client/{clientId}")
|
||||
public ResponseEntity<Map<String, Object>> getFactureByClient(@PathVariable Long clientId) {
|
||||
return buildResponse(factureService.getByClient(clientId));
|
||||
List<Facture> result = factureService.getByClient(clientId);
|
||||
return buildResponse("List order customer", true, result);
|
||||
}
|
||||
|
||||
// Factures impayees
|
||||
@GetMapping("/unpayed")
|
||||
public ResponseEntity<Map<String, Object>> getUnpayedFactures() {
|
||||
List<Facture> result = factureService.getUnpayed();
|
||||
return buildResponse(result);
|
||||
return buildResponse("List unpayed older", true, result);
|
||||
}
|
||||
|
||||
private ResponseEntity<Map<String, Object>> buildResponse(Object data) {
|
||||
// Génère une facture
|
||||
@PostMapping
|
||||
public ResponseEntity<Map<String, Object>> setFacture(@RequestBody List<Location> locations) {
|
||||
double price = 0;
|
||||
for(Location location : locations){
|
||||
price += location.getStock().getDailyPrice();
|
||||
|
||||
}
|
||||
Facture facture = new Facture();
|
||||
facture.setClient(locations.get(0).getClient());
|
||||
facture.setDatePay(new Date());
|
||||
facture.setPrice(price);
|
||||
factureService.add(facture);
|
||||
return buildResponse("Older created", true, new HashMap<>());
|
||||
}
|
||||
|
||||
private ResponseEntity<Map<String, Object>> buildResponse(String message, boolean status, Object data) {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("message", message);
|
||||
response.put("status", status);
|
||||
response.put("data", data);
|
||||
response.put("status", 200);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user