Génération facture et location end date set
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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> {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user