Пример #1
0
    def wrapper(*args, **kwargs):
        auth_service = AuthService()
        user_id = auth_service.get_auth_user_id()

        if user_id is None:
            return json_response.unauthorized()

        user = auth_service.model.get_by_id(user_id)

        if user is None:
            return json_response.unauthorized()

        return func(*args, **kwargs, user=user)
Пример #2
0
def login():
    data = request.get_json()
    auth_service = AuthService()
    try:
        auth_service.login(data['email'], data['password'])
    except (UserNotFound, InvalidCredentials) as e:
        return json_response.unauthorized()
    return json_response.success({"result": "success"})
Пример #3
0
def get_category_by_id(id: int, user):
    categories_service = CategoriesService()

    try:
        return categories_service.get_category_by_id(id, user)
    except UnAuthorized:
        return json_response.unauthorized()
    except CategoryDoesntExist:
        return json_response.not_found()
Пример #4
0
def get_categories(user):
    categories_service = CategoriesService()

    try:
        return json_response.success(categories_service.get_categories(user))
    except UnAuthorized:
        return json_response.unauthorized()
    except NoCategories:
        return json_response.not_found()
Пример #5
0
def create_transaction(user):
    data = request.get_json()
    transaction_service = TransactionsService()

    try:
        return json_response.success(
            transaction_service.create_transaction(data, user))
    except UnAuthorized:
        return json_response.unauthorized()
Пример #6
0
def delete_category_by_id(id: int, user):
    categories_service = CategoriesService()

    try:
        return json_response.success(
            categories_service.delete_category_by_id(id, user))
    except UnAuthorized:
        return json_response.unauthorized()
    except CategoryDoesntExist:
        return json_response.not_found()
Пример #7
0
def delete_transaction(id: int, user):
    transaction_service = TransactionsService()

    try:
        transaction_service.delete_transaction_by_id(id, user)
        return json_response.deleted()
    except UnAuthorized:
        return json_response.unauthorized()
    except TransactionDoesntExist:
        return json_response.not_found()
Пример #8
0
def get_transaction_by_id(id: int, user):
    transaction_service = TransactionsService()

    try:
        return json_response.success(
            transaction_service.get_transaction_by_id(id, user))
    except UnAuthorized:
        return json_response.unauthorized()
    except TransactionDoesntExist:
        return json_response.not_found()
Пример #9
0
def get_transactions(user):
    transaction_service = TransactionsService()

    try:
        return json_response.success(
            transaction_service.get_transactions(user))
    except UnAuthorized:
        return json_response.unauthorized()
    except NoTransactions:
        return json_response.not_found()
Пример #10
0
def edit_category_by_id(id: int, user):
    data = request.get_json()
    categories_service = CategoriesService()

    try:
        return json_response.success(
            categories_service.edit_category_by_id(id, data, user))
    except UnAuthorized:
        return json_response.unauthorized()
    except CategoryDoesntExist:
        return json_response.not_found()
Пример #11
0
def create_category(user):
    data = request.get_json()
    categories_service = CategoriesService()

    try:
        return json_response.success(
            categories_service.create_category(data, user))
    except UnAuthorized:
        return json_response.unauthorized()
    except CategoryAlreadyExist:
        return json_response.conflict()
Пример #12
0
def edit_transaction(id: int, user):
    data = request.get_json()
    transaction_service = TransactionsService()

    try:
        return json_response.success(
            transaction_service.edit_transaction_by_id(id, data, user))
    except UnAuthorized:
        return json_response.unauthorized()
    except TransactionDoesntExist:
        return json_response.not_found()