Added new endpoint for roles and updated users endpoints to work with roles

This commit is contained in:
Luka Radenovic 2022-04-14 13:32:35 +02:00
parent 7661088814
commit 10479a625a
10 changed files with 108 additions and 13 deletions

2
areas/roles/__init__.py Normal file
View file

@ -0,0 +1,2 @@
from .roles import *
from .models import *

10
areas/roles/models.py Normal file
View 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}"

View 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
View 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)