예제 #1
0
 def get_all_by(query_params: dict,
                paginate=True) -> Dict[str, Union[int, List[Tour]]]:
     if not paginate:
         result = TourRepository.get_all_by_query(**query_params)
         return {
             'total': result.get('total'),
             'tours': result.get('tours'),
         }
     result = TourRepository.paginate_with(**query_params)
     return {
         'total': result.get('total'),
         'tours': result.get('tours'),
         'page': result.get('page'),
         'page_size': result.get('page_size')
     }
예제 #2
0
    def validate_uniqueness_except_current_tour_id(tour_id: int, field_name: str = None, **kwargs):
        tour = TourRepository.get_by(**kwargs)

        if tour is not None and tour.id != tour_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 tour
예제 #3
0
    def validate_non_existence(field_name: str = None, **kwargs):
        tour = TourRepository.get_by(**kwargs)

        if tour 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 tour
예제 #4
0
    def validate_uniqueness(field_name: str = None, **kwargs):
        tour = TourRepository.get_by(**kwargs)

        if tour 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 tour
예제 #5
0
 def update_by(tour_id: int, **payload):
     payload = accepts_logic(payload=payload,
                             temp={'tour_id': tour_id},
                             schema=TourUpdateBy)
     TourRepository.update_by(tour_id, **payload)
예제 #6
0
 def get_all_tour_payment_information(tour_id):
     tour = TourRepository.get_by(id=tour_id)
     if tour is None:
         raise TourNotFoundException
     return list(tour.tour_payment_informations)
예제 #7
0
 def create(payload: dict) -> Tour:
     payload = accepts_logic(payload=payload, schema=TourCreate)
     tour = TourRepository.create(payload)
     return tour
예제 #8
0
 def is_existed(**kwargs) -> Tour:
     tour = TourRepository.get_by(**kwargs)
     return tour
예제 #9
0
    def is_existed_except_by_id(tour_id: int, **kwargs) -> bool:
        tour = TourRepository.get_by(**kwargs)

        if not tour or tour.id == tour_id:
            return False
        return True