Génération facture et location end date set

This commit is contained in:
jleroy2023
2025-07-16 16:36:03 +02:00
parent dbfaeee1f7
commit 165113cd81
4 changed files with 10 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ package fr.eni.demo.bll;
import fr.eni.demo.bo.Location;
public interface LocationService {
Location findById(int id);
Location findById(Long id);
void add(Location location);
void updateDateEnd(int id, Location location);
void updateDateEnd(String id, Location location);
}

View File

@@ -1,6 +1,5 @@
package fr.eni.demo.bll;
import fr.eni.demo.bo.Adresse;
import fr.eni.demo.bo.Location;
import fr.eni.demo.dal.LocationRepository;
import jakarta.persistence.EntityNotFoundException;
@@ -11,14 +10,14 @@ import java.util.Date;
@Service
public class LocationServiceImpl implements LocationService {
private LocationRepository locationRepository;
private final LocationRepository locationRepository;
public LocationServiceImpl(LocationRepository locationRepository) {
this.locationRepository = locationRepository;
}
@Override
public Location findById(int id) {
public Location findById(Long id) {
return locationRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Location non trouvée"));
}
@@ -29,8 +28,8 @@ public class LocationServiceImpl implements LocationService {
}
@Override
public void updateDateEnd(int id, Location location) {
Location existing = findById(id);
public void updateDateEnd(String id, Location location) {
Location existing = findById(Long.valueOf(id));
location.setId(existing.getId());
location.setEndDate(new Date());
locationRepository.save(location);

View File

@@ -1,6 +1,7 @@
package fr.eni.demo.controller;
import fr.eni.demo.bll.FactureService;
import fr.eni.demo.bll.LocationService;
import fr.eni.demo.bo.Facture;
import fr.eni.demo.bo.Location;
import lombok.RequiredArgsConstructor;
@@ -18,6 +19,7 @@ import java.util.Map;
public class FactureController {
private final FactureService factureService;
private final LocationService locationService;
// Toutes les factures
@GetMapping
@@ -46,7 +48,7 @@ public class FactureController {
double price = 0;
for(Location location : locations){
price += location.getStock().getDailyPrice();
locationService.updateDateEnd(location.getId(), location);
}
Facture facture = new Facture();
facture.setClient(locations.get(0).getClient());

View File

@@ -5,5 +5,5 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface LocationRepository extends MongoRepository<Location, Integer> {
public interface LocationRepository extends MongoRepository<Location, Long> {
}