-
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
8 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
24 changes: 24 additions & 0 deletions
24
src/main/java/co/edu/uniandes/dse/parcialejemplo/entities/HabitacionEntity.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package co.edu.uniandes.dse.parcialejemplo.entities; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.ManyToOne; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import uk.co.jemos.podam.common.PodamExclude; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
public class HabitacionEntity extends BaseEntity { | ||
|
||
private int identificacion; | ||
private int num_personas; | ||
private int num_camas; | ||
private int num_banos; | ||
|
||
@PodamExclude | ||
@ManyToOne | ||
private HotelEntity hotel; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/co/edu/uniandes/dse/parcialejemplo/entities/HotelEntity.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package co.edu.uniandes.dse.parcialejemplo.entities; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.persistence.*; | ||
|
||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import uk.co.jemos.podam.common.PodamExclude; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
public class HotelEntity extends BaseEntity{ | ||
|
||
private String nombre; | ||
private String direccion; | ||
private Float estrellas; | ||
|
||
@PodamExclude | ||
@OneToMany(mappedBy = "hotel", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST, orphanRemoval = true) | ||
private List<HabitacionEntity> habitaciones = new ArrayList<>(); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/co/edu/uniandes/dse/parcialejemplo/repositories/HabitacionRepository.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package co.edu.uniandes.dse.parcialejemplo.repositories; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import co.edu.uniandes.dse.parcialejemplo.entities.HabitacionEntity; | ||
|
||
@Repository | ||
public interface HabitacionRepository extends JpaRepository<HabitacionEntity, Long>{ | ||
List<HabitacionEntity> findById(long id); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/co/edu/uniandes/dse/parcialejemplo/repositories/HotelRepository.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package co.edu.uniandes.dse.parcialejemplo.repositories; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import co.edu.uniandes.dse.parcialejemplo.entities.HotelEntity; | ||
|
||
@Repository | ||
public interface HotelRepository extends JpaRepository<HotelEntity, Long> { | ||
List<HotelEntity> findById(long id); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/co/edu/uniandes/dse/parcialejemplo/services/HabitacionService.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package co.edu.uniandes.dse.parcialejemplo.services; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import java.util.Optional; | ||
|
||
import javax.persistence.EntityNotFoundException; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import co.edu.uniandes.dse.parcialejemplo.entities.*; | ||
import co.edu.uniandes.dse.parcialejemplo.exceptions.IllegalOperationException; | ||
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 HabitacionService { | ||
|
||
@Autowired | ||
HabitacionRepository habitacionRepository; | ||
|
||
@Autowired | ||
HotelRepository hotelRepository; | ||
|
||
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"); | ||
|
||
log.info("Termina el proceso de creacion de habitacion"); | ||
return habitacionRepository.save(habitacionEntity); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package co.edu.uniandes.dse.parcialejemplo.services; | ||
|
||
public class HotelHabitacionService { | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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; | ||
|
||
import co.edu.uniandes.dse.parcialejemplo.entities.HotelEntity; | ||
import co.edu.uniandes.dse.parcialejemplo.exceptions.IllegalOperationException; | ||
import co.edu.uniandes.dse.parcialejemplo.repositories.HotelRepository; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Service | ||
public class HotelService { | ||
|
||
@Autowired | ||
HotelRepository hotelRepository; | ||
|
||
@Transactional | ||
public HotelEntity createHotel(HotelEntity hotelEntity) throws IllegalOperationException{ | ||
log.info("Comienza el proceso de creacion de hotel"); | ||
if (hotelEntity.getEstrellas()< 1 || hotelEntity.getEstrellas() >5){ | ||
throw new IllegalOperationException("El numero de estrellas no es valido"); | ||
} | ||
|
||
return hotelRepository.save(hotelEntity); | ||
} | ||
|
||
|
||
} |