Skip to content

Commit

Permalink
update Reservation (#34)
Browse files Browse the repository at this point in the history
- updateReservation(Reservaton reservation) added.

Issues: [n/a]

Signed-off-by: Kuzu <[email protected]>
  • Loading branch information
Serberx authored Feb 27, 2024
1 parent 7dcaf8c commit 9e4327b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/main/java/com/samic/samic/services/ServiceReservation.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.samic.samic.data.entity.User;
import com.samic.samic.data.repositories.RepositoryReservation;
import com.samic.samic.exceptions.ReservationException;
import com.samic.samic.security.AuthenticatedUser;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,9 +27,9 @@ public class ServiceReservation{
@Autowired
private final RepositoryReservation repositoryReservation;
@Autowired
private final ServiceStorageObject serviceStorageObject;
// @Autowired
// private final AuthenticatedUser authenticatedUser;
private final ServiceStorageObject serviceStorageObject;
@Autowired
private final AuthenticatedUser authenticatedUser;

@Transactional
public Reservation saveReservationByObject(Reservation reservation){
Expand Down Expand Up @@ -58,6 +59,20 @@ public Reservation saveReservationByObject(Reservation reservation){
}
}

public Reservation updateReservation(Reservation reservation){
if(reservation != null){
if(reservation.getId() != null && reservation.getReservedFrom()
.equals(authenticatedUser.getUser()
.get())){
return repositoryReservation.save(reservation);
}else{
throw new ReservationException(reservation.getId() == null ? "Reservation ID is not set!" : "User does not match with Logged in user!");
}
}else{
throw new ReservationException("Given Reservation is null");
}
}

@Transactional
public Reservation findReservationById(Long id){
if(id != null){
Expand Down Expand Up @@ -97,7 +112,8 @@ public void deleteReservationById(Long id){

public void deleteByObject(Reservation reservation){
if(reservation != null){
if(repositoryReservation.findById(reservation.getId()).isPresent()){
if(repositoryReservation.findById(reservation.getId())
.isPresent()){

reservation.setReservedFrom(null);
StorageObject tempSto = serviceStorageObject.findStorageObjectByReservationID(reservation.getId());
Expand Down

0 comments on commit 9e4327b

Please sign in to comment.