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
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
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
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)
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)
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)
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)
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)
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)
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)
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)
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
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)
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