Moved models
This commit is contained in:
parent
cf18cbdc4e
commit
6713d4658b
8 changed files with 56 additions and 44 deletions
19
backend/src/models/interface.py
Normal file
19
backend/src/models/interface.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from enum import Enum
|
||||||
|
import marshmallow as ma
|
||||||
|
|
||||||
|
class HealthStatus(Enum):
|
||||||
|
OK = 0
|
||||||
|
WARNING = 1
|
||||||
|
ERROR = 2
|
||||||
|
CRITICAL = 3
|
||||||
|
|
||||||
|
class HealthGet(ma.Schema):
|
||||||
|
alive_since = ma.fields.String()
|
||||||
|
alive_for = ma.fields.String()
|
||||||
|
status = ma.fields.Enum(HealthStatus, type=ma.fields.String)
|
||||||
|
|
||||||
|
class ApiVersionGet(ma.Schema):
|
||||||
|
version = ma.fields.String(example="0.1")
|
||||||
|
|
||||||
|
class OpenAPIGet(ma.Schema):
|
||||||
|
pass
|
27
backend/src/models/requests.py
Normal file
27
backend/src/models/requests.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from enum import Enum
|
||||||
|
import marshmallow as ma
|
||||||
|
|
||||||
|
class RequestStatus(Enum):
|
||||||
|
CREATED = 0
|
||||||
|
ACTIVE = 1
|
||||||
|
COMPLETED = 64
|
||||||
|
DELETED = 255
|
||||||
|
|
||||||
|
class RequestsAll(ma.Schema):
|
||||||
|
uuid = ma.fields.String(description="UUID v4", example="3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a")
|
||||||
|
status = ma.fields.String()
|
||||||
|
|
||||||
|
class RequestsCreate(ma.Schema):
|
||||||
|
message = ma.fields.String(example="Request 3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a was created")
|
||||||
|
status = ma.fields.Enum(RequestStatus, type=ma.fields.String)
|
||||||
|
uuid = ma.fields.String(example="3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a")
|
||||||
|
|
||||||
|
class UuidSchema(ma.Schema):
|
||||||
|
uuid = ma.fields.String(description="UUID of the request", example="3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a")
|
||||||
|
|
||||||
|
class RequestsInteraction(ma.Schema):
|
||||||
|
status = ma.fields.String()
|
||||||
|
|
||||||
|
class RequestsInteractionDelete(ma.Schema):
|
||||||
|
message = ma.fields.String(example="Request 3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a was deleted.")
|
||||||
|
status = ma.fields.Enum(RequestStatus, type=ma.fields.String)
|
|
@ -1,24 +1,12 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
|
||||||
from flask.views import MethodView
|
from flask.views import MethodView
|
||||||
import marshmallow as ma
|
|
||||||
|
|
||||||
from app import Application
|
from app import Application
|
||||||
|
from models.interface import HealthGet, HealthStatus
|
||||||
from . import routes as blp
|
from . import routes as blp
|
||||||
|
|
||||||
instance = Application.get_instance()
|
instance = Application.get_instance()
|
||||||
|
|
||||||
class HealthStatus(Enum):
|
|
||||||
OK = 0
|
|
||||||
WARNING = 1
|
|
||||||
ERROR = 2
|
|
||||||
CRITICAL = 3
|
|
||||||
|
|
||||||
class HealthGet(ma.Schema):
|
|
||||||
alive_since = ma.fields.String()
|
|
||||||
alive_for = ma.fields.String()
|
|
||||||
status = ma.fields.Enum(HealthStatus, type=ma.fields.String)
|
|
||||||
|
|
||||||
@blp.route("/health")
|
@blp.route("/health")
|
||||||
class ApiVersion(MethodView):
|
class ApiVersion(MethodView):
|
||||||
@blp.doc(summary="Returns the status and alive-time of the server")
|
@blp.doc(summary="Returns the status and alive-time of the server")
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
from flask import redirect, url_for
|
from flask import redirect, url_for
|
||||||
from flask.views import MethodView
|
from flask.views import MethodView
|
||||||
import marshmallow as ma
|
|
||||||
|
|
||||||
|
from models.interface import OpenAPIGet
|
||||||
from . import routes as blp
|
from . import routes as blp
|
||||||
|
|
||||||
class OpenAPIGet(ma.Schema):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@blp.route("/openapi")
|
@blp.route("/openapi")
|
||||||
class ApiVersion(MethodView):
|
class ApiVersion(MethodView):
|
||||||
@blp.doc(summary="Get the OpenAPI spec as a JSON.")
|
@blp.doc(summary="Get the OpenAPI spec as a JSON.")
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
from flask.views import MethodView
|
from flask.views import MethodView
|
||||||
import marshmallow as ma
|
|
||||||
|
|
||||||
from database import Database
|
from database import Database
|
||||||
|
from models.requests import RequestsAll
|
||||||
from . import routes_requests as blp
|
from . import routes_requests as blp
|
||||||
|
|
||||||
db = Database.get_instance().db
|
db = Database.get_instance().db
|
||||||
|
|
||||||
class RequestsAll(ma.Schema):
|
|
||||||
uuid = ma.fields.String(description="UUID v4", example="3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a")
|
|
||||||
status = ma.fields.String()
|
|
||||||
|
|
||||||
|
|
||||||
@blp.route("/all")
|
@blp.route("/all")
|
||||||
class AllRequests(MethodView):
|
class AllRequests(MethodView):
|
||||||
@blp.doc(summary="Returns all requests")
|
@blp.doc(summary="Returns all requests")
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from flask.views import MethodView
|
from flask.views import MethodView
|
||||||
import marshmallow as ma
|
|
||||||
|
|
||||||
from database import Database
|
from database import Database
|
||||||
|
from models.requests import RequestsCreate, RequestStatus
|
||||||
from . import routes_requests as blp
|
from . import routes_requests as blp
|
||||||
|
|
||||||
db = Database.get_instance().db
|
db = Database.get_instance().db
|
||||||
|
|
||||||
class RequestsCreate(ma.Schema):
|
|
||||||
status = ma.fields.String(example="Request 3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a was created")
|
|
||||||
uuid = ma.fields.String(example="3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a")
|
|
||||||
|
|
||||||
@blp.route("/create")
|
@blp.route("/create")
|
||||||
class CreateRequest(MethodView):
|
class CreateRequest(MethodView):
|
||||||
@blp.doc(summary="Create a new request")
|
@blp.doc(summary="Create a new request")
|
||||||
|
@ -21,7 +17,8 @@ class CreateRequest(MethodView):
|
||||||
requests[uuid] = { "status": "created" }
|
requests[uuid] = { "status": "created" }
|
||||||
session.write()
|
session.write()
|
||||||
response = {
|
response = {
|
||||||
"status": f"Request {uuid} was created",
|
"status": RequestStatus.CREATED,
|
||||||
|
"message": f"Request {uuid} was created",
|
||||||
"uuid": uuid
|
"uuid": uuid
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -1,21 +1,12 @@
|
||||||
from flask_smorest import abort
|
from flask_smorest import abort
|
||||||
from flask.views import MethodView
|
from flask.views import MethodView
|
||||||
import marshmallow as ma
|
|
||||||
|
|
||||||
from database import Database
|
from database import Database
|
||||||
|
from models.requests import UuidSchema, RequestsInteraction, RequestsInteractionDelete, RequestStatus
|
||||||
from . import routes_requests as blp
|
from . import routes_requests as blp
|
||||||
|
|
||||||
db = Database.get_instance().db
|
db = Database.get_instance().db
|
||||||
|
|
||||||
class UuidSchema(ma.Schema):
|
|
||||||
uuid = ma.fields.String(description="UUID of the request", example="3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a")
|
|
||||||
|
|
||||||
class RequestsInteraction(ma.Schema):
|
|
||||||
status = ma.fields.String()
|
|
||||||
|
|
||||||
class RequestsInteractionDelete(ma.Schema):
|
|
||||||
status = ma.fields.String(example="Request 3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a was deleted.")
|
|
||||||
|
|
||||||
@blp.route("/<string:uuid>")
|
@blp.route("/<string:uuid>")
|
||||||
class InteractRequest(MethodView):
|
class InteractRequest(MethodView):
|
||||||
@blp.doc(summary="Returns a specific request by its UID")
|
@blp.doc(summary="Returns a specific request by its UID")
|
||||||
|
@ -39,6 +30,7 @@ class InteractRequest(MethodView):
|
||||||
del requests[uuid]
|
del requests[uuid]
|
||||||
session.write()
|
session.write()
|
||||||
response = {
|
response = {
|
||||||
"status": f"Request {uuid} was deleted."
|
"status": RequestStatus.DELETED,
|
||||||
|
"message": f"Request {uuid} was deleted."
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
from flask.views import MethodView
|
from flask.views import MethodView
|
||||||
import marshmallow as ma
|
|
||||||
|
|
||||||
from config.api_settings import DefaultSettings
|
from config.api_settings import DefaultSettings
|
||||||
|
from models.interface import ApiVersionGet
|
||||||
from . import routes as blp
|
from . import routes as blp
|
||||||
|
|
||||||
class ApiVersionGet(ma.Schema):
|
|
||||||
version = ma.fields.String(example="0.1")
|
|
||||||
|
|
||||||
@blp.route("/version")
|
@blp.route("/version")
|
||||||
class ApiVersion(MethodView):
|
class ApiVersion(MethodView):
|
||||||
@blp.doc(summary="Get the REST interface version identification.")
|
@blp.doc(summary="Get the REST interface version identification.")
|
||||||
|
|
Loading…
Reference in a new issue