TG-103 Initial Flask app stucture
This commit is contained in:
18
backend/app/api/exampleapi/controller.py
Normal file
18
backend/app/api/exampleapi/controller.py
Normal file
@ -0,0 +1,18 @@
|
||||
from flask_restful import Resource
|
||||
|
||||
|
||||
class SomeApi(Resource):
|
||||
"""
|
||||
Some Api Resource
|
||||
"""
|
||||
def post(self):
|
||||
return {'somepost': 'somepostdata'}, 201
|
||||
|
||||
def get(self, id=None):
|
||||
return {'someget': 'somegetdata'}, 200
|
||||
|
||||
def delete(self, id=None):
|
||||
return {'somedelete': 'somedeletedata'}, 204
|
||||
|
||||
def put(self, id=None):
|
||||
return {'someput': 'someputdata'}, 204
|
33
backend/app/api/exampleapi/model.py
Normal file
33
backend/app/api/exampleapi/model.py
Normal file
@ -0,0 +1,33 @@
|
||||
from passlib.apps import custom_app_context as pwd_context
|
||||
|
||||
from app.core import db
|
||||
|
||||
users_roles = db.Table('users_roles',
|
||||
db.Column('user_id',
|
||||
db.Integer,
|
||||
db.ForeignKey('user.id')
|
||||
),
|
||||
db.Column('role_id',
|
||||
db.Integer,
|
||||
db.ForeignKey('role.id')
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Role(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(80), unique=True, nullable=False)
|
||||
description = db.Column(db.String(255), nullable=False)
|
||||
|
||||
|
||||
class User(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
email = db.Column(db.String(255), index=True, unique=True, nullable=False)
|
||||
password_hash = db.Column(db.String(64), nullable=False)
|
||||
roles = db.relationship('Role', secondary=users_roles)
|
||||
|
||||
def hash_password(self, password):
|
||||
self.password_hash = pwd_context.encrypt(password)
|
||||
|
||||
def verify_password(self, password):
|
||||
return pwd_context.verify(password, self.password_hash)
|
Reference in New Issue
Block a user