From 2b51afd927a812a913ad2a2adcd7cdaca971abd3 Mon Sep 17 00:00:00 2001 From: Firq Date: Tue, 3 Oct 2023 18:25:35 +0200 Subject: [PATCH] Fixed issues, now partially working --- backend/src/models/requestentry.py | 9 +++------ backend/src/routes/requests/base.py | 11 ++++++++--- backend/src/routes/requests/create.py | 8 ++++++-- backend/src/routes/requests/interact.py | 6 +++++- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/backend/src/models/requestentry.py b/backend/src/models/requestentry.py index ee2783f..7581851 100644 --- a/backend/src/models/requestentry.py +++ b/backend/src/models/requestentry.py @@ -1,11 +1,7 @@ from enum import Enum import marshmallow as ma -class ModifiersEnum(Enum): - NONE = 0 - ESPORTS = 1 - SUPER = 2 - HYPER = 3 +from .requests import RequestStatus class BaseField(ma.Schema): id = ma.fields.Integer(description="Atlas Academy id") @@ -14,7 +10,7 @@ class BaseField(ma.Schema): class ServantField(BaseField): name = ma.fields.String(description="Name of servant", example="Scáthach") level = ma.fields.Integer(description="Servant level", example=120) - modifiers = ma.fields.List(ma.fields.Enum(ModifiersEnum), example=ModifiersEnum.HYPER) + modifiers = ma.fields.List(ma.fields.String(example="HYPER")) class CeField(BaseField): name = ma.fields.String(description="Name of CE", example="Holy Night Supper") @@ -32,3 +28,4 @@ class RequestPostData(ma.Schema): class RequestDatabaseEntry(RequestPostData): uuid = ma.fields.String(description="UUID v4 of the request") + status = ma.fields.Enum(RequestStatus) diff --git a/backend/src/routes/requests/base.py b/backend/src/routes/requests/base.py index ecb803f..c4a69a4 100644 --- a/backend/src/routes/requests/base.py +++ b/backend/src/routes/requests/base.py @@ -1,7 +1,8 @@ from flask.views import MethodView from database import Database -from models.requests import RequestsAll +from models.requests import RequestStatus +from models.requestentry import RequestDatabaseEntry from . import routes_requests as blp db = Database.get_instance().db @@ -9,10 +10,14 @@ db = Database.get_instance().db @blp.route("/all") class AllRequests(MethodView): @blp.doc(summary="Returns all requests") - @blp.response(200, RequestsAll(many=True), description="Successful operation") + @blp.response(200, RequestDatabaseEntry(many=True), description="Successful operation") def get(self): db_data = db.at("requests").read() response = [] for key, value in db_data.items(): - response.append({"uuid": key, **value}) + value.update({ + "status": RequestStatus(value["status"]) + }) + response.append(value) + print(response) return response diff --git a/backend/src/routes/requests/create.py b/backend/src/routes/requests/create.py index 1e30918..232c977 100644 --- a/backend/src/routes/requests/create.py +++ b/backend/src/routes/requests/create.py @@ -11,13 +11,17 @@ db = Database.get_instance().db @blp.route("/create") class CreateRequest(MethodView): @blp.doc(summary="Create a new request") - @blp.arguments(RequestPostData, location="body") + @blp.arguments(RequestPostData) @blp.response(200, RequestsCreate, description="Successful operation") def post(self, data): print(data) uuid = str(uuid4()) with db.at("requests").session() as (session, requests): - requests[uuid] = { "status": "created" } + data.update({ + "status": RequestStatus.ACTIVE, + "uuid": uuid + }) + requests[uuid] = data session.write() response = { "status": RequestStatus.CREATED, diff --git a/backend/src/routes/requests/interact.py b/backend/src/routes/requests/interact.py index 20295c1..0765ec1 100644 --- a/backend/src/routes/requests/interact.py +++ b/backend/src/routes/requests/interact.py @@ -3,6 +3,7 @@ from flask.views import MethodView from database import Database from models.requests import UuidSchema, RequestsInteraction, RequestsInteractionDelete, RequestStatus +from models.requestentry import RequestDatabaseEntry from . import routes_requests as blp db = Database.get_instance().db @@ -11,12 +12,15 @@ db = Database.get_instance().db class InteractRequest(MethodView): @blp.doc(summary="Returns a specific request by its UID") @blp.arguments(UuidSchema, location='path', as_kwargs=True) - @blp.response(200, RequestsInteraction, description="Successful operation") + @blp.response(200, RequestDatabaseEntry, description="Successful operation") @blp.alt_response(404) def get(self, uuid): response = db.at("requests", key=uuid).read() if response is None: abort(404, message=f"Request {uuid} does not exist.") + response.update({ + "status": RequestStatus(response["status"]) + }) return response @blp.doc(summary="Deletes a specific request by its UID")