예제 #1
0
from flask_restful import Resource
from inz import api
from inz.services.ocr_service import OcrUtility


class OcrEndpoint(Resource):
    # http://127.0.0.1:5000/ocr/{img_name}

    def get(self, img_name):
        text = OcrUtility.recognize(img_name)
        return {'result': text}


api.add_resource(OcrEndpoint, '/ocr/<img_name>')
예제 #2
0
            return category.to_json()
        except RecordNotFoundError as err:
            return err.message, status.HTTP_404_NOT_FOUND
        except UnauthorizedError as err:
            return err.message, status.HTTP_401_UNAUTHORIZED

    def put(self, id):
        data = request.get_json()  # TODO to test if unathorized error needed
        try:
            CategoryService.update(id, current_identity.id, data.get('name'))
            return '', status.HTTP_204_NO_CONTENT
        except RecordNotFoundError as err:
            return err.message, status.HTTP_404_NOT_FOUND
        except UnauthorizedError as err:
            return err.message, status.HTTP_401_UNAUTHORIZED
        except AttributeError:
            return 'Invalid request body', status.HTTP_400_BAD_REQUEST

    def delete(self, id):
        try:
            CategoryService.delete(id, current_identity.id)
            return '', status.HTTP_204_NO_CONTENT
        except RecordNotFoundError as err:
            return err.message, status.HTTP_404_NOT_FOUND
        except UnauthorizedError as err:
            return err.message, status.HTTP_401_UNAUTHORIZED


api.add_resource(CategoryEndpoint, '/category')
api.add_resource(CategoryIdEndpoint, '/category/<int:id>')
예제 #3
0
            return err.message, status.HTTP_401_UNAUTHORIZED

    def put(self, id):
        data = request.get_json()  # TODO to test if unathorized error needed
        try:
            ExpenseService.update(id, current_identity.id,
                                  data.get('product_name'), data.get('price'),
                                  data.get('amount'), data.get('date'),
                                  data.get('category_id'),
                                  current_identity.categories)
            return '', status.HTTP_204_NO_CONTENT
        except RecordNotFoundError as err:
            return err.message, status.HTTP_404_NOT_FOUND
        except UnauthorizedError as err:
            return err.message, status.HTTP_401_UNAUTHORIZED
        except AttributeError:
            return 'Invalid request body', status.HTTP_400_BAD_REQUEST

    def delete(self, id):
        try:
            ExpenseService.delete(id, current_identity.id)
            return '', status.HTTP_204_NO_CONTENT
        except RecordNotFoundError as err:
            return err.message, status.HTTP_404_NOT_FOUND
        except UnauthorizedError as err:
            return err.message, status.HTTP_401_UNAUTHORIZED


api.add_resource(ExpenseEndpoint, '/expense')
api.add_resource(ExpenseIdEndpoint, '/expense/<int:id>')
예제 #4
0
from flask import request
from flask_restful import Resource
from flask_api import status
from flask_jwt import jwt_required, current_identity
from inz import api
from inz.services.category_service import CategoryService


class CategoryAnalysisEndpoint(Resource):
    # http://127.0.0.1:5000/category/analysis
    decorators = [jwt_required()]

    def post(self):
        data = request.get_json()
        print(data)
        try:
            analysis = CategoryService.get_category_analysis(
                data.get('period_start'), data.get('period_end'),
                current_identity.categories, current_identity.expenses)
            return {'analysis': analysis}
        except ValueError:
            return 'Invalid date strings', status.HTTP_400_BAD_REQUEST
        except AttributeError:
            return 'Invalid request body', status.HTTP_400_BAD_REQUEST


api.add_resource(CategoryAnalysisEndpoint, '/analysis')
예제 #5
0
            email = user_data.get('email')
            password = user_data.get('password')
            new_user = UserService.create(email, password)
            return {'id': new_user.id}
        except AttributeError:
            return 'Invalid request body', status.HTTP_400_BAD_REQUEST


# http://127.0.0.1:5000/login + credentials in body;
# this endpoint is provided by flask-jwt module


class IdentityEndpoint(Resource):
    # http://127.0.0.1:5000/protected
    decorators = [jwt_required()]

    def get(self):
        user = current_identity
        return {'id': user.id, 'email': user.email}


class TestEndpoint(Resource):
    # http://127.0.0.1:5000/test
    def get(self):
        return {'content': 'test complete'}


api.add_resource(RegisterEndpoint, '/register')
api.add_resource(IdentityEndpoint, '/identity')
api.add_resource(TestEndpoint, '/test')
예제 #6
0
            return 'Invalid request body', status.HTTP_400_BAD_REQUEST

    def delete(self, id):
        try:
            LimitService.delete(id, current_identity.id)
            return '', status.HTTP_204_NO_CONTENT
        except RecordNotFoundError as err:
            return err.message, status.HTTP_404_NOT_FOUND
        except UnauthorizedError as err:
            return err.message, status.HTTP_401_UNAUTHORIZED


class LimitInfoEndpoint(Resource):
    # http://127.0.0.1:5000/limit-info/{id}
    decorators = [jwt_required()]

    def get(self, id):
        try:
            limit = LimitService.get_by_id(id, current_identity.id)
            info = LimitService.get_info_of(limit)
            return {'info': info}
        except RecordNotFoundError as err:
            return err.message, status.HTTP_404_NOT_FOUND
        except UnauthorizedError as err:
            return err.message, status.HTTP_401_UNAUTHORIZED


api.add_resource(LimitEndpoint, '/limit')
api.add_resource(LimitIdEndpoint, '/limit/<int:id>')
api.add_resource(LimitInfoEndpoint, '/limit_info/<int:id>')