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 from enum import Enum
import marshmallow as ma import marshmallow as ma
class ModifiersEnum(Enum): from .requests import RequestStatus
NONE = 0
ESPORTS = 1
SUPER = 2
HYPER = 3
class BaseField(ma.Schema): class BaseField(ma.Schema):
id = ma.fields.Integer(description="Atlas Academy id") id = ma.fields.Integer(description="Atlas Academy id")
@ -14,7 +10,7 @@ class BaseField(ma.Schema):
class ServantField(BaseField): class ServantField(BaseField):
name = ma.fields.String(description="Name of servant", example="Scáthach") name = ma.fields.String(description="Name of servant", example="Scáthach")
level = ma.fields.Integer(description="Servant level", example=120) 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): class CeField(BaseField):
name = ma.fields.String(description="Name of CE", example="Holy Night Supper") name = ma.fields.String(description="Name of CE", example="Holy Night Supper")
@ -32,3 +28,4 @@ class RequestPostData(ma.Schema):
class RequestDatabaseEntry(RequestPostData): class RequestDatabaseEntry(RequestPostData):
uuid = ma.fields.String(description="UUID v4 of the request") 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 flask.views import MethodView
from database import Database 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 from . import routes_requests as blp
db = Database.get_instance().db db = Database.get_instance().db
@ -9,10 +10,14 @@ db = Database.get_instance().db
@blp.route("/all") @blp.route("/all")
class AllRequests(MethodView): class AllRequests(MethodView):
@blp.doc(summary="Returns all requests") @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): def get(self):
db_data = db.at("requests").read() db_data = db.at("requests").read()
response = [] response = []
for key, value in db_data.items(): 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 return response

View file

@ -11,13 +11,17 @@ db = Database.get_instance().db
@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")
@blp.arguments(RequestPostData, location="body") @blp.arguments(RequestPostData)
@blp.response(200, RequestsCreate, description="Successful operation") @blp.response(200, RequestsCreate, description="Successful operation")
def post(self, data): def post(self, data):
print(data) print(data)
uuid = str(uuid4()) uuid = str(uuid4())
with db.at("requests").session() as (session, requests): with db.at("requests").session() as (session, requests):
requests[uuid] = { "status": "created" } data.update({
"status": RequestStatus.ACTIVE,
"uuid": uuid
})
requests[uuid] = data
session.write() session.write()
response = { response = {
"status": RequestStatus.CREATED, "status": RequestStatus.CREATED,

View file

@ -3,6 +3,7 @@ from flask.views import MethodView
from database import Database from database import Database
from models.requests import UuidSchema, RequestsInteraction, RequestsInteractionDelete, RequestStatus from models.requests import UuidSchema, RequestsInteraction, RequestsInteractionDelete, RequestStatus
from models.requestentry import RequestDatabaseEntry
from . import routes_requests as blp from . import routes_requests as blp
db = Database.get_instance().db db = Database.get_instance().db
@ -11,12 +12,15 @@ db = Database.get_instance().db
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")
@blp.arguments(UuidSchema, location='path', as_kwargs=True) @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) @blp.alt_response(404)
def get(self, uuid): def get(self, uuid):
response = db.at("requests", key=uuid).read() response = db.at("requests", key=uuid).read()
if response is None: if response is None:
abort(404, message=f"Request {uuid} does not exist.") abort(404, message=f"Request {uuid} does not exist.")
response.update({
"status": RequestStatus(response["status"])
})
return response return response
@blp.doc(summary="Deletes a specific request by its UID") @blp.doc(summary="Deletes a specific request by its UID")