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;
|
import fr.eni.demo.bo.Location;
|
||||||
|
|
||||||
public interface LocationService {
|
public interface LocationService {
|
||||||
Location findById(int id);
|
Location findById(Long id);
|
||||||
void add(Location location);
|
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;
|
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 jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
@@ -11,14 +10,14 @@ import java.util.Date;
|
|||||||
@Service
|
@Service
|
||||||
public class LocationServiceImpl implements LocationService {
|
public class LocationServiceImpl implements LocationService {
|
||||||
|
|
||||||
private LocationRepository locationRepository;
|
private final LocationRepository locationRepository;
|
||||||
|
|
||||||
public LocationServiceImpl(LocationRepository locationRepository) {
|
public LocationServiceImpl(LocationRepository locationRepository) {
|
||||||
this.locationRepository = locationRepository;
|
this.locationRepository = locationRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location findById(int id) {
|
public Location findById(Long id) {
|
||||||
return locationRepository.findById(id)
|
return locationRepository.findById(id)
|
||||||
.orElseThrow(() -> new EntityNotFoundException("Location non trouvée"));
|
.orElseThrow(() -> new EntityNotFoundException("Location non trouvée"));
|
||||||
}
|
}
|
||||||
@@ -29,8 +28,8 @@ public class LocationServiceImpl implements LocationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDateEnd(int id, Location location) {
|
public void updateDateEnd(String id, Location location) {
|
||||||
Location existing = findById(id);
|
Location existing = findById(Long.valueOf(id));
|
||||||
location.setId(existing.getId());
|
location.setId(existing.getId());
|
||||||
location.setEndDate(new Date());
|
location.setEndDate(new Date());
|
||||||
locationRepository.save(location);
|
locationRepository.save(location);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package fr.eni.demo.controller;
|
package fr.eni.demo.controller;
|
||||||
|
|
||||||
import fr.eni.demo.bll.FactureService;
|
import fr.eni.demo.bll.FactureService;
|
||||||
|
import fr.eni.demo.bll.LocationService;
|
||||||
import fr.eni.demo.bo.Facture;
|
import fr.eni.demo.bo.Facture;
|
||||||
import fr.eni.demo.bo.Location;
|
import fr.eni.demo.bo.Location;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -18,6 +19,7 @@ import java.util.Map;
|
|||||||
public class FactureController {
|
public class FactureController {
|
||||||
|
|
||||||
private final FactureService factureService;
|
private final FactureService factureService;
|
||||||
|
private final LocationService locationService;
|
||||||
|
|
||||||
// Toutes les factures
|
// Toutes les factures
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@@ -46,7 +48,7 @@ public class FactureController {
|
|||||||
double price = 0;
|
double price = 0;
|
||||||
for(Location location : locations){
|
for(Location location : locations){
|
||||||
price += location.getStock().getDailyPrice();
|
price += location.getStock().getDailyPrice();
|
||||||
|
locationService.updateDateEnd(location.getId(), location);
|
||||||
}
|
}
|
||||||
Facture facture = new Facture();
|
Facture facture = new Facture();
|
||||||
facture.setClient(locations.get(0).getClient());
|
facture.setClient(locations.get(0).getClient());
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ import org.springframework.data.mongodb.repository.MongoRepository;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface LocationRepository extends MongoRepository<Location, Integer> {
|
public interface LocationRepository extends MongoRepository<Location, Long> {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user