Skip to content

Commit

Permalink
Entrega #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jsepis committed Sep 23, 2022
1 parent 0e4f511 commit b8b326a
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 0 deletions.
Binary file added Parcial Práctico 1.pdf
Binary file not shown.
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;

}
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<>();

}
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);
}
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);
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package co.edu.uniandes.dse.parcialejemplo.services;

public class HotelHabitacionService {

}
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);
}


}

0 comments on commit b8b326a

Please sign in to comment.