def get_plan(certificate_repository, id_, repository_factory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams(plan_id=id_) use_case = GetPlanUseCase( params=params, plan_repository=repository_factory.plan(), ) plan = use_case.run() if plan is None: return { 'error': None, 'result': None, 'status': 'success', }, 200 presenter = PlanPresenter(plan=plan) return { 'error': None, 'result': presenter.format(), 'status': 'success', }, 200
def create_plan(certificate_repository, repository_factory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams() use_case = CreatePlanUseCase( location_repository=repository_factory.location(), params=params, plan_repository=repository_factory.plan(), task_repository=repository_factory.task(), ) try: plan = use_case.run() presenter = PlanPresenter(plan=plan) return { 'error': None, 'result': presenter.format(), 'status': 'success', }, 201 except InvalidRepeatTypeError as e: return { 'error': { 'message': '不支持的重复类型:{}'.format(e.repeat_type), }, 'result': None, 'status': 'failure', }, 422
def get_location(certificate_repository, id_, repository_factory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams(location_id=id_) use_case = GetLocationUseCase( location_repository=repository_factory.location(), params=params, ) try: location = use_case.run() except AccessDeniedError: return { 'error': { 'code': 403, 'message': '无权查看该地点' }, 'result': None, 'status': 'failure', } presenter = LocationPresenter(location=location, ) return { 'error': None, 'result': presenter.format(), 'status': 'success', }, 200
def list_location(certificate_repository, repository_factory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams() use_case = ListLocationUseCase( location_repository=repository_factory.location(), params=params, ) locations = use_case.run() presenter = ListPlanPresenter(locations) return presenter.format(), 200
def list_task(certificate_repository, repository_factory: RepositoryFactory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams() use_case = ListTaskUseCase( params=params, plan_repository=repository_factory.plan(), task_repository=repository_factory.task(), ) tasks = use_case.run() return ListPresenter(tasks=tasks).build(), 200
def create_task(certificate_repository, repository_factory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams() use_case = CreateTaskUseCase( params=params, task_repository=repository_factory.task(), ) task = use_case.run() return { 'error': None, 'result': Presenter(task=task).build(), 'status': 'success', }, 201
def pop_plan(certificate_repository, repository_factory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams() use_case = PopPlanUseCase( location_repository=repository_factory.location(), params=params, plan_repository=repository_factory.plan(), ) plans = use_case.run() return { 'error': None, 'result': [PlanPresenter(plan=plan).format() for plan in plans], 'status': 'success', }, 200
def delete_task(certificate_repository, id_, repository_factory: RepositoryFactory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() use_case = DeleteTaskUseCase( params=HTTPParams(task_id=id_), plan_repository=repository_factory.plan(), task_repository=repository_factory.task(), ) use_case.run() return { 'error': None, 'result': None, 'status': 'success', }, 200
def get_task(certificate_repository, id_, repository_factory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams(task_id=id_) use_case = GetTaskUseCase( params=params, task_repository=repository_factory.task(), ) task = use_case.run() presenter = Presenter(task=task, ) return { 'error': None, 'result': presenter.build(), 'status': 'success', }, 200
def create_location(certificate_repository: ICertificateRepository, repository_factory: RepositoryFactory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() use_case = CreateLocationUseCase( location_repository=repository_factory.location(), params=HTTPParams(), ) location = use_case.run() presenter = LocationPresenter(location=location) return { 'error': None, 'result': presenter.format(), 'status': 'success', }, 201
def delete_plan(certificate_repository, id_, repository_factory): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams( plan_id=id_, ) use_case = DeletePlanUseCase( params=params, plan_repository=repository_factory.plan(), ) use_case.run() return { 'error': None, 'result': None, 'status': 'success', }, 200
def change_plan(certificate_repository, repository_factory, plan_id): authenticate_use_case = AuthenticateUseCase( certificate_repository=certificate_repository, params=CookiesParams(), ) authenticate_use_case.run() params = HTTPParams(plan_id=plan_id) use_case = ChangePlanUseCase( location_repository=repository_factory.location(), params=params, plan_repository=repository_factory.plan(), ) try: use_case.run() return { 'error': None, 'result': None, 'status': 'success', }, 200 except InvalidRepeatTypeError as e: return { 'error': { 'message': '不支持的重复类型:{}'.format(e.repeat_type), }, 'result': None, 'status': 'failure', }, 200 except PlanNotFoundError as e: return { 'error': { 'message': '找不到计划:{}'.format(e.plan_id), }, 'result': None, 'status': 'failure', }, 200