Moved models

This commit is contained in:
Firq 2023-10-02 15:29:19 +02:00
parent cf18cbdc4e
commit 6713d4658b
Signed by: Firq
GPG key ID: 3ACC61C8CEC83C20
8 changed files with 56 additions and 44 deletions

View 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

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

View file

@ -1,24 +1,12 @@
from datetime import datetime
from enum import Enum
from flask.views import MethodView
import marshmallow as ma
from app import Application
from models.interface import HealthGet, HealthStatus
from . import routes as blp
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")
class ApiVersion(MethodView):
@blp.doc(summary="Returns the status and alive-time of the server")

View file

@ -1,12 +1,9 @@
from flask import redirect, url_for
from flask.views import MethodView
import marshmallow as ma
from models.interface import OpenAPIGet
from . import routes as blp
class OpenAPIGet(ma.Schema):
pass
@blp.route("/openapi")
class ApiVersion(MethodView):
@blp.doc(summary="Get the OpenAPI spec as a JSON.")

View file

@ -1,16 +1,11 @@
from flask.views import MethodView
import marshmallow as ma
from database import Database
from models.requests import RequestsAll
from . import routes_requests as blp
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")
class AllRequests(MethodView):
@blp.doc(summary="Returns all requests")

View file

@ -1,16 +1,12 @@
from uuid import uuid4
from flask.views import MethodView
import marshmallow as ma
from database import Database
from models.requests import RequestsCreate, RequestStatus
from . import routes_requests as blp
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")
class CreateRequest(MethodView):
@blp.doc(summary="Create a new request")
@ -21,7 +17,8 @@ class CreateRequest(MethodView):
requests[uuid] = { "status": "created" }
session.write()
response = {
"status": f"Request {uuid} was created",
"status": RequestStatus.CREATED,
"message": f"Request {uuid} was created",
"uuid": uuid
}
return response

View file

@ -1,21 +1,12 @@
from flask_smorest import abort
from flask.views import MethodView
import marshmallow as ma
from database import Database
from models.requests import UuidSchema, RequestsInteraction, RequestsInteractionDelete, RequestStatus
from . import routes_requests as blp
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>")
class InteractRequest(MethodView):
@blp.doc(summary="Returns a specific request by its UID")
@ -39,6 +30,7 @@ class InteractRequest(MethodView):
del requests[uuid]
session.write()
response = {
"status": f"Request {uuid} was deleted."
"status": RequestStatus.DELETED,
"message": f"Request {uuid} was deleted."
}
return response

View file

@ -1,12 +1,9 @@
from flask.views import MethodView
import marshmallow as ma
from config.api_settings import DefaultSettings
from models.interface import ApiVersionGet
from . import routes as blp
class ApiVersionGet(ma.Schema):
version = ma.fields.String(example="0.1")
@blp.route("/version")
class ApiVersion(MethodView):
@blp.doc(summary="Get the REST interface version identification.")