Fixed issues, now partially working

This commit is contained in:
Firq 2023-10-03 18:25:35 +02:00
parent 086a55c148
commit 2b51afd927
Signed by: Firq
GPG key ID: 3ACC61C8CEC83C20
4 changed files with 22 additions and 12 deletions

View file

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

View file

@ -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

View file

@ -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,

View file

@ -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")