コード例 #1
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
コード例 #2
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
コード例 #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 update_skill(slug: str, **kwargs):
    with SkillRepository() as repo:
        skill: Skill = repo.filter_one(Skill.slug == slug)
        if skill:
            update_from(skill, **kwargs)
            skill.updated_at = get_current_time(get_request_timezone())
            return '', HTTPStatus.NO_CONTENT
        else:
            raise SkillFoundError(ErrorMessages.NoSkillsFound, ErrorCodes.NoSkillsFound,
                                  http_status_code=HTTPStatus.NOT_FOUND)
コード例 #5
0
def modify_category(slug: str, **kwargs):
    with CategoryRepository() as repo:
        category: Category = repo.filter_one(Category.slug == slug)
        if category:

            update_time = get_current_time(get_request_timezone())
            update_from(category, **kwargs)
            category.updated_at = update_time

            return '', HTTPStatus.NO_CONTENT
        else:
            raise CategoryListError(ErrorMessages.NoCategoryFound, ErrorCodes.NoService,
                                    http_status_code=HTTPStatus.NOT_FOUND)
コード例 #6
0
def modify_service(slug: str, **kwargs):
    with ServiceRepository() as repo:
        service: Service = repo.filter_one(Service.slug == slug)
        if service:

            update_time = get_current_time(get_request_timezone())
            update_from(service, **kwargs)
            service.updated_at = update_time

            return '', HTTPStatus.NO_CONTENT
        else:
            raise ServiceListError(ErrorMessages.NoServicesFound,
                                   ErrorCodes.NoService,
                                   http_status_code=HTTPStatus.NOT_FOUND)
コード例 #7
0
def update_zone(slug: str, city_slug: str, **kwargs):
    with ZoneRepository() as repo:
        with CityRepository() as city_repo:
            zone: Zone = repo.filter_one(Zone.slug == slug)
            if zone:
                update_from(zone, **kwargs)
                zone.city = city_repo.filter_one(City.slug == city_slug)
                zone.city_id = zone.city.city_id
                zone.updated_at = get_current_time(get_request_timezone())
                return '', HTTPStatus.NO_CONTENT
            else:
                raise ZoneFoundError(ErrorMessages.NoZonesFound,
                                     ErrorCodes.NoZonesFound,
                                     http_status_code=HTTPStatus.NOT_FOUND)
コード例 #8
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
コード例 #9
0
def update_provide(slug: str, city_slug: str, service_slug: str, **kwargs):
    with ProvideRepository() as repo:
        provide: Provide = repo.filter_one(Provide.slug == slug)
        if provide:
            update_from(provide, **kwargs)
            provide.updated_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

            return '', HTTPStatus.NO_CONTENT
        else:
            raise ProvideFoundError(ErrorMessages.NoProvidesFound,
                                    ErrorCodes.NoProvidesFound,
                                    http_status_code=HTTPStatus.NOT_FOUND)
コード例 #10
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