예제 #1
0
 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)
예제 #2
0
 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')
     }
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
    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
예제 #6
0
 def is_existed(**kwargs) -> Hotel:
     hotel = HotelRepository.get_by(**kwargs)
     return hotel
예제 #7
0
    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
예제 #8
0
 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)
예제 #9
0
 def create(payload: dict) -> Hotel:
     payload = accepts_logic(payload=payload, schema=HotelCreate)
     hotel = HotelRepository.create(payload)
     return hotel