示例#1
0
def register_service(service: Service):
    with ServiceRepository() as repo:
        current_time = get_current_time(get_request_timezone())
        service.created_at = current_time
        service_id = repo.add(service)

        return serialize({"service_id": service_id}), HTTPStatus.CREATED
示例#2
0
def register_category(service: Category):
    with CategoryRepository() as repo:
        current_time = get_current_time(get_request_timezone())
        service.created_at = current_time
        category_id = repo.add(service)

        return serialize({"service_id": category_id}), HTTPStatus.CREATED
示例#3
0
def create_zone(zone: Zone, city_slug: str):
    with ZoneRepository() as repo:
        with CityRepository() as city_repo:
            city: City = city_repo.filter_one(City.slug == city_slug)
            zone.city_id = city.city_id
            zone.created_at = get_current_time(get_request_timezone())
            zone_id = repo.add(zone)
            return serialize({"zone_id": zone_id}), HTTPStatus.CREATED
示例#4
0
def fetch_skill(slug: str):
    with SkillRepository() as repo:
        skill: Skill = repo.filter_one(Skill.slug == slug)
        if skill:
            mapping = create_mapping(skill, SkillDTO)
            return serialize(create_dto(skill, SkillDTO, mapping)), HTTPStatus.OK
        else:
            raise SkillFoundError(ErrorMessages.NoSkillsFound, ErrorCodes.NoSkillsFound,
                                  http_status_code=HTTPStatus.NOT_FOUND)
示例#5
0
def fetch_zone(slug: str):
    with ZoneRepository() as repo:
        zone: Zone = repo.filter_one_with_lazy(Zone.slug == slug)
        if zone:
            mapping = create_mapping(zone, ZoneDTO)
            return serialize(create_dto(zone, ZoneDTO, mapping)), HTTPStatus.OK
        else:
            raise ZoneFoundError(ErrorMessages.NoZonesFound,
                                 ErrorCodes.NoZonesFound,
                                 http_status_code=HTTPStatus.NOT_FOUND)
示例#6
0
def fetch_provide(slug: str):
    with ProvideRepository() as repo:
        provide: Provide = repo.filter_one_with_lazy(Provide.slug == slug)
        if provide:
            mapping = create_mapping(provide, ProvideDTO)
            return serialize(create_dto(provide, ProvideDTO,
                                        mapping)), HTTPStatus.OK
        else:
            raise ProvideFoundError(ErrorMessages.NoProvidesFound,
                                    ErrorCodes.NoProvidesFound,
                                    http_status_code=HTTPStatus.NOT_FOUND)
示例#7
0
def list_skill(qs: str = ''):
    with SkillRepository() as repo:
        result, count = repo.get_skill_list(qs)
        if result:
            mapping = create_mapping(result[0], SkillDTO)
            return serialize(odata(
                count,
                [create_dto(skill, SkillDTO, mapping) for skill in result])), HTTPStatus.OK
        else:
            raise SkillFoundError(ErrorMessages.NoSkillsFound, ErrorCodes.NoSkillsFound,
                                  http_status_code=HTTPStatus.NOT_FOUND)
示例#8
0
def get_category_info(slug: str):
    with CategoryRepository() as repo:
        category: Category = repo.filter_one(Category.slug == slug)
        if category:
            mapping = create_mapping(category, CategoryDTO)

            return serialize(create_dto(category, CategoryDTO, mapping)), HTTPStatus.OK

        else:
            raise CategoryListError(ErrorMessages.NoCategoryFound, ErrorCodes.NoService,
                                    http_status_code=HTTPStatus.NOT_FOUND)
示例#9
0
def get_service_info(slug: str):
    with ServiceRepository() as repo:
        service: Service = repo.filter_one(Service.slug == slug)
        if service:
            mapping = create_mapping(service, ServiceDTO)

            return serialize(create_dto(service, ServiceDTO,
                                        mapping)), HTTPStatus.OK

        else:
            raise ServiceListError(ErrorMessages.NoServicesFound,
                                   ErrorCodes.NoService,
                                   http_status_code=HTTPStatus.NOT_FOUND)
示例#10
0
def list_zone(qs: str = ''):
    with ZoneRepository() as repo:
        result, count = repo.get_zone_list(qs)
        if result:
            mapping = create_mapping(result[0], ZoneDTO)
            return serialize(
                odata(count,
                      [create_dto(zone, ZoneDTO, mapping)
                       for zone in result])), HTTPStatus.OK
        else:
            raise ZoneFoundError(ErrorMessages.NoZonesFound,
                                 ErrorCodes.NoZonesFound,
                                 http_status_code=HTTPStatus.NOT_FOUND)
示例#11
0
def list_categories(qs: str = ''):
    with CategoryRepository() as repo:
        result, count = repo.get_category_list(qs)

        if result:
            mapping = create_mapping(result[0], CategoryDTO)

            return serialize(odata(
                count,
                [create_dto(category, CategoryDTO, mapping) for category in result])), HTTPStatus.OK

        else:
            raise CategoryListError(ErrorMessages.NoCategoryFound, ErrorCodes.NoService,
                                    http_status_code=HTTPStatus.NOT_FOUND)
示例#12
0
def create_provide(provide: Provide, city_slug: str, service_slug: str):
    print(type(provide.start_at))
    with ProvideRepository() as repo:
        provide.created_at = get_current_time(get_request_timezone())

        with CityRepository() as cityRepository:
            provide.city = cityRepository.filter_one(City.slug == city_slug)
            provide.city_id = provide.city.city_id
        with ServiceRepository() as serviceRepository:
            provide.service = serviceRepository.filter_one(
                Service.slug == service_slug)
            provide.service_id = provide.service.service_id

        provide_id = repo.add(provide)
        return serialize({"provide_id": provide_id}), HTTPStatus.CREATED
示例#13
0
def list_services(qs: str = ''):
    with ServiceRepository() as repo:
        result, count = repo.get_service_list(qs)

        if result:
            mapping = create_mapping(result[0], ServiceDTO)

            return serialize(
                odata(count, [
                    create_dto(service, ServiceDTO, mapping)
                    for service in result
                ])), HTTPStatus.OK

        else:
            raise ServiceListError(ErrorMessages.NoServicesFound,
                                   ErrorCodes.NoService,
                                   http_status_code=HTTPStatus.NOT_FOUND)
示例#14
0
def create_skill(skill: Skill):
    with SkillRepository() as repo:
        skill.created_at = get_current_time(get_request_timezone())
        skill_id = repo.add(skill)
        return serialize({"skill_id": skill_id}), HTTPStatus.CREATED