def update_by(hotel_id: int, **payload): payload = accepts_logic( payload=payload, temp={ 'hotel_id': hotel_id }, schema=HotelUpdateBy ) HotelRepository.update_by(hotel_id, **payload)
def get_all_by(query_params: dict, paginate=True) -> Dict[str, Union[int, List[Hotel]]]: if not paginate: result = HotelRepository.get_all_by_query(**query_params) return { 'total': result.get('total'), 'hotels': result.get('hotels'), } result = HotelRepository.paginate_with(**query_params) return { 'total': result.get('total'), 'hotels': result.get('hotels'), 'page': result.get('page'), 'page_size': result.get('page_size') }
def validate_non_existence(field_name: str = None, **kwargs): hotel = HotelRepository.get_by(**kwargs) if hotel is None: key, value = next(iter(kwargs.items())) field_name = field_name if field_name else key raise ValidationError(field_name=field_name, message=ValidateErrorCode.NOT_EXIST) return hotel
def validate_uniqueness(field_name: str = None, **kwargs): hotel = HotelRepository.get_by(**kwargs) if hotel is not None: key, value = next(iter(kwargs.items())) field_name = field_name if field_name else key raise ValidationError(field_name=field_name, message=ValidateErrorCode.IS_UNIQUE) return hotel
def validate_uniqueness_except_current_hotel_id(hotel_id: int, field_name: str = None, **kwargs): hotel = HotelRepository.get_by(**kwargs) if hotel is not None and hotel.id != hotel_id: key, value = next(iter(kwargs.items())) field_name = field_name if field_name else key raise ValidationError(field_name=field_name, message=ValidateErrorCode.IS_UNIQUE) return hotel
def is_existed(**kwargs) -> Hotel: hotel = HotelRepository.get_by(**kwargs) return hotel
def is_existed_except_by_id(hotel_id: int, **kwargs) -> bool: hotel = HotelRepository.get_by(**kwargs) if not hotel or hotel.id == hotel_id: return False return True
def get_all_payment_information(hotel_id): hotel = HotelRepository.get_by(id=hotel_id) if hotel is None: raise HotelNotFoundException return list(hotel.payment_informations)
def create(payload: dict) -> Hotel: payload = accepts_logic(payload=payload, schema=HotelCreate) hotel = HotelRepository.create(payload) return hotel