Ejemplo n.º 1
0
from app import api, Resource, fields, jwt_required, get_jwt_identity
from models.taskmodel import TaskModel, task_schema, tasks_schema
from models.userModel import UserModel, users_schema, user_schema
#define my namespaces

ns_tasks = api.namespace('tasks', description="All opartation of tasks")

#documenting
#models
a_task_model = api.model('Task', {
    'title': fields.String(),
    'description': fields.String()
})

# tasks= [
#     {"id":1, "title":"Learn Javascript", "description":"Learning Basics"},
#     {"id":2, "title":"Learn Python", "description":"Learning Basics"},
#     {"id":3, "title":"Learn PHP", "description":"Learning Basics"}
# ]


# @api.route('/tasks')
@ns_tasks.route('')
class TaskList(Resource):
    @jwt_required
    def get(self):
        """Use  this endpoint to get all the tasks"""
        # tasks=TaskModel.fetch_all()
        user_id = get_jwt_identity()
        user = UserModel.get_userby_id(user_id)
        user_tasks = user.tasks
Ejemplo n.º 2
0
from Models.userModel import UserModel, users_schema, user_schema
from app import api, fields, Resource, get_jwt_identity
from Models.taskModel import TaskModel, tasks_schema

user_namespace = api.namespace(
    'users', description='Endpoint for all operations concerning users')

user_model = api.model(
    'User', {
        'full_name': fields.String(),
        'email': fields.String(),
        'password': fields.String()
    })


@user_namespace.route('')
class UserList(Resource):
    def get(self):
        """get all users"""
        users = UserModel.fetch_all()
        return users_schema.dump(users), 200


@user_namespace.route('/<int:id>')
class User(Resource):
    def get(self, id):
        user = UserModel.fetch_by_id(id)
        return user_schema.dump(user), 200

    @api.expect(user_model)
    def put(self, id):
from app import api, Resource, fields, create_access_token
from models.userModel import UserModel, user_schema, users_schema
from werkzeug.security import generate_password_hash

ns_userLogin = api.namespace('login', description=" Login Details")
ns_registration = api.namespace('register', description="Registration Details")

register_model = api.model(
    'Register Credentials', {
        'firstname': fields.String(),
        'email': fields.String(),
        'password': fields.String()
    })
login_model = api.model('Login Credentials', {
    'email': fields.String(),
    'password': fields.String()
})


@ns_registration.route('')
class Registration(Resource):
    @api.expect(register_model)
    def post(self):
        """Add a new user"""
        data = api.payload
        users = UserModel(fullname=data["firstname"],
                          email=data['email'],
                          password=generate_password_hash(data['password']))
        users.save_toDB()
        return user_schema.dump(users), 201