Пример #1
0
async def post(schema: ApplicationRequestSchema,
               current_user: dict = Depends(get_current_user),
               service: ApplicationService = Depends(get_application_service)):
    try:
        await service.create(schema.__dict__, current_user)

        return created()
    except ValueError as e:
        return bad_request(str(e))
Пример #2
0
async def get(name: str,
              current_user: dict = Depends(get_current_user),
              service: ApplicationService = Depends(get_application_service)):
    try:
        users: List[str] = await service.get_application_users(
            name, current_user)

        return [user["email"] for user in users]
    except ValueError as e:
        return bad_request(str(e))
Пример #3
0
async def inactivate(
    name: str,
    current_user: dict = Depends(get_current_user),
    service: ApplicationService = Depends(get_application_service)):
    try:
        await service.inactivate(name, current_user)

        return ok()
    except ValueError as e:
        return bad_request(str(e))
Пример #4
0
async def put(name: str,
              schema: ApplicationRequestSchema,
              current_user: dict = Depends(get_current_user),
              service: ApplicationService = Depends(get_application_service)):
    try:
        await service.update(schema.__dict__, name, current_user)

        return ok()
    except ValueError as e:
        return bad_request(str(e))
Пример #5
0
async def delete(
    name: str,
    email: str,
    current_user: dict = Depends(get_current_user),
    service: ApplicationService = Depends(get_application_service)):
    try:
        await service.remove_user(name, email, current_user)

        return ok()
    except ValueError as e:
        return bad_request(str(e))
Пример #6
0
async def patch(
    name: str,
    schema: ApplicationFeatureRequestSchema,
    current_user: dict = Depends(get_current_user),
    service: ApplicationService = Depends(get_application_service)):
    try:
        await service.add_feature(name, schema.__dict__, current_user)
    except ValueError as e:
        return bad_request(str(e))
    else:
        return ok()
Пример #7
0
async def get(name: str,
              current_user: dict = Depends(get_current_user),
              service: ApplicationService = Depends(get_application_service)):
    try:
        features = await service.get_application_features(name, current_user)

        return [
            ApplicationFeatureResponseSchema(**feature) for feature in features
        ]
    except ValueError as e:
        return bad_request(str(e))
Пример #8
0
async def patch(
        schema: UserChangePasswordSchema,
        service: UserService = Depends(get_user_service),
        current_user: dict = Depends(get_current_user),
):
    try:
        await service.change_password(current_user["email"],
                                      schema.new_password,
                                      schema.confirm_password)

        return ok()
    except ValueError as e:
        return bad_request(str(e))
Пример #9
0
async def activate(
    name: str,
    environment: str,
    feature_name: str,
    current_user: dict = Depends(get_current_user),
    service: ApplicationService = Depends(get_application_service)):
    try:
        await service.activate_feature(name, environment, feature_name,
                                       current_user)
    except ValueError as e:
        return bad_request(str(e))
    else:
        return ok()