Added new endpoint for roles and updated users endpoints to work with roles
This commit is contained in:
parent
7661088814
commit
10479a625a
10 changed files with 108 additions and 13 deletions
2
areas/roles/__init__.py
Normal file
2
areas/roles/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from .roles import *
|
||||
from .models import *
|
||||
10
areas/roles/models.py
Normal file
10
areas/roles/models.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from sqlalchemy import Integer, String
|
||||
from database import db
|
||||
|
||||
|
||||
class Role(db.Model):
|
||||
id = db.Column(Integer, primary_key=True)
|
||||
name = db.Column(String(length=64))
|
||||
|
||||
def __repr__(self):
|
||||
return f"Role {self.name}"
|
||||
8
areas/roles/role_service.py
Normal file
8
areas/roles/role_service.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from .models import Role
|
||||
|
||||
|
||||
class RoleService:
|
||||
@staticmethod
|
||||
def get_roles():
|
||||
roles = Role.query.all()
|
||||
return [{"id": r.id, "name": r.name} for r in roles]
|
||||
15
areas/roles/roles.py
Normal file
15
areas/roles/roles.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from flask import jsonify, request
|
||||
from flask_jwt_extended import jwt_required
|
||||
from flask_cors import cross_origin
|
||||
|
||||
from areas import api_v1
|
||||
|
||||
from .role_service import RoleService
|
||||
|
||||
|
||||
@api_v1.route("/roles", methods=["GET"])
|
||||
@jwt_required()
|
||||
@cross_origin()
|
||||
def get_roles():
|
||||
roles = RoleService.get_roles()
|
||||
return jsonify(roles)
|
||||
Reference in a new issue