Génération facture et location end date set
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package fr.eni.demo.bll;
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
import fr.eni.demo.bo.Facture;
|
import fr.eni.demo.bo.Facture;
|
||||||
|
import fr.eni.demo.bo.Location;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -8,4 +9,5 @@ public interface FactureService {
|
|||||||
List<Facture> getByClient(Long clientId);
|
List<Facture> getByClient(Long clientId);
|
||||||
List<Facture> getAll();
|
List<Facture> getAll();
|
||||||
List<Facture> getUnpayed();
|
List<Facture> getUnpayed();
|
||||||
|
void add(Facture facture);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package fr.eni.demo.bll;
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
import fr.eni.demo.bo.Facture;
|
import fr.eni.demo.bo.Facture;
|
||||||
|
import fr.eni.demo.bo.Location;
|
||||||
import fr.eni.demo.dal.FactureRepository;
|
import fr.eni.demo.dal.FactureRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -35,4 +36,10 @@ public class FactureServiceImpl implements FactureService {
|
|||||||
public List<Facture> getUnpayed() {
|
public List<Facture> getUnpayed() {
|
||||||
return factureRepo.findByDatePayEmpty();
|
return factureRepo.findByDatePayEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Facture facture) {
|
||||||
|
factureRepo.save(facture);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,7 @@ package fr.eni.demo.bll;
|
|||||||
import fr.eni.demo.bo.Location;
|
import fr.eni.demo.bo.Location;
|
||||||
|
|
||||||
public interface LocationService {
|
public interface LocationService {
|
||||||
|
Location findById(int id);
|
||||||
void add(Location location);
|
void add(Location location);
|
||||||
|
void updateDateEnd(int id, Location location);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,39 @@
|
|||||||
package fr.eni.demo.bll;
|
package fr.eni.demo.bll;
|
||||||
|
|
||||||
|
import fr.eni.demo.bo.Adresse;
|
||||||
import fr.eni.demo.bo.Location;
|
import fr.eni.demo.bo.Location;
|
||||||
import fr.eni.demo.dal.LocationRepository;
|
import fr.eni.demo.dal.LocationRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class LocationServiceImpl implements LocationService {
|
public class LocationServiceImpl implements LocationService {
|
||||||
|
|
||||||
private LocationRepository locationRepository;
|
private LocationRepository locationRepository;
|
||||||
|
|
||||||
public LocationServiceImpl(LocationRepository locationRepository) {
|
public LocationServiceImpl(LocationRepository locationRepository) {
|
||||||
this.locationRepository = locationRepository;
|
this.locationRepository = locationRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location findById(int id) {
|
||||||
|
return locationRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new EntityNotFoundException("Location non trouvée"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Location location) {
|
public void add(Location location) {
|
||||||
locationRepository.save(location);
|
locationRepository.save(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDateEnd(int id, Location location) {
|
||||||
|
Location existing = findById(id);
|
||||||
|
location.setId(existing.getId());
|
||||||
|
location.setEndDate(new Date());
|
||||||
|
locationRepository.save(location);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public class ClientController {
|
|||||||
clientService.delete(id);
|
clientService.delete(id);
|
||||||
return buildResponse("Address deleted", true, new HashMap<>());
|
return buildResponse("Address deleted", true, new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseEntity<Map<String, Object>> buildResponse(String message, boolean status, Object data) {
|
private ResponseEntity<Map<String, Object>> buildResponse(String message, boolean status, Object data) {
|
||||||
Map<String, Object> response = new HashMap<>();
|
Map<String, Object> response = new HashMap<>();
|
||||||
response.put("message", message);
|
response.put("message", message);
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package fr.eni.demo.controller;
|
|||||||
|
|
||||||
import fr.eni.demo.bll.FactureService;
|
import fr.eni.demo.bll.FactureService;
|
||||||
import fr.eni.demo.bo.Facture;
|
import fr.eni.demo.bo.Facture;
|
||||||
|
import fr.eni.demo.bo.Location;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -21,26 +23,45 @@ public class FactureController {
|
|||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<Map<String, Object>> getAllFactures() {
|
public ResponseEntity<Map<String, Object>> getAllFactures() {
|
||||||
List<Facture> result = factureService.getAll();
|
List<Facture> result = factureService.getAll();
|
||||||
return buildResponse(result);
|
return buildResponse("List all order", true, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Factures par client
|
// Factures par client
|
||||||
@GetMapping("/client/{clientId}")
|
@GetMapping("/client/{clientId}")
|
||||||
public ResponseEntity<Map<String, Object>> getFactureByClient(@PathVariable Long 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
|
// Factures impayees
|
||||||
@GetMapping("/unpayed")
|
@GetMapping("/unpayed")
|
||||||
public ResponseEntity<Map<String, Object>> getUnpayedFactures() {
|
public ResponseEntity<Map<String, Object>> getUnpayedFactures() {
|
||||||
List<Facture> result = factureService.getUnpayed();
|
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<>();
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("message", message);
|
||||||
|
response.put("status", status);
|
||||||
response.put("data", data);
|
response.put("data", data);
|
||||||
response.put("status", 200);
|
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class SecurityConfig {
|
|||||||
UserDetails user = User.builder()
|
UserDetails user = User.builder()
|
||||||
.username("user")
|
.username("user")
|
||||||
.password(encoder.encode("password"))
|
.password(encoder.encode("password"))
|
||||||
.roles("USER")
|
.roles("EMPLOYE")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return new InMemoryUserDetailsManager(user);
|
return new InMemoryUserDetailsManager(user);
|
||||||
|
|||||||
Reference in New Issue
Block a user