Skip to content

Commit

Permalink
Avance 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jsepis committed Sep 23, 2022
1 parent b8b326a commit c7ab9a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public class HabitacionService {

public HabitacionEntity createHabitacion(Long hotelId, HabitacionEntity habitacionEntity ) throws EntityNotFoundException, IllegalOperationException{
log.info("Inicia proceso de creacion de habitacion");
Optional<HotelEntity> hotelEntity = hotelRepository.findById(hotelId);
if (hotelEntity.isEmpty())
throw new EntityNotFoundException("Hotel no encontrado");


if(habitacionEntity.getIdentificacion() > habitacionEntity.getNum_camas())
throw new IllegalOperationException("El numero de identificion es mayor al numero de camas");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
package co.edu.uniandes.dse.parcialejemplo.services;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.Optional;

import javax.persistence.EntityNotFoundException;
import javax.websocket.server.ServerEndpoint;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import co.edu.uniandes.dse.parcialejemplo.entities.*;

import co.edu.uniandes.dse.parcialejemplo.repositories.HabitacionRepository;
import co.edu.uniandes.dse.parcialejemplo.repositories.HotelRepository;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class HotelHabitacionService {

@Autowired
private HotelRepository hotelRepository;

@Autowired
private HabitacionRepository habitacionRepository;

@Transactional
public HabitacionEntity addHabitacion(Long hotelId, Long habitacionId) throws EntityNotFoundException {
log.info("Inicia el proceso de anadirle una habitacion a el hotel con id = {0}", hotelId);

Optional<HotelEntity> hotelEntity = hotelRepository.findById(hotelId);
if (hotelEntity.isEmpty())
throw new EntityNotFoundException("Hotel no encontrado");

Optional<HabitacionEntity> habitacionEntity = habitacionRepository.findById(habitacionId);
if (habitacionEntity.isEmpty())
throw new EntityNotFoundException("Habitacion no encontrada");

habitacionEntity.get().setHotel(hotelEntity.get());
log.info("Termina el proceso de anadirle una habitacion a el hotel con id = {0}", hotelId);
return habitacionEntity.get();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package co.edu.uniandes.dse.parcialejemplo.services;

import javax.persistence.EntityNotFoundException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down

0 comments on commit c7ab9a2

Please sign in to comment.