-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 40 additions & 1 deletion
41
src/main/java/co/edu/uniandes/dse/parcialejemplo/services/HotelHabitacionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
src/main/java/co/edu/uniandes/dse/parcialejemplo/services/HotelService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters