updated create endpoint with models
This commit is contained in:
parent
a8bc73c532
commit
086a55c148
4 changed files with 40 additions and 5 deletions
|
@ -1,6 +1,5 @@
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import __main__
|
|
||||||
|
|
||||||
class DefaultSettings:
|
class DefaultSettings:
|
||||||
API_TITLE = "Support Organizer"
|
API_TITLE = "Support Organizer"
|
||||||
|
@ -26,4 +25,4 @@ class DefaultSettings:
|
||||||
'description': 'Support Organizer for FGO'
|
'description': 'Support Organizer for FGO'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FILE_SAVE_DIRECTORY = Path(__main__.__file__).parent / "temp"
|
FILE_SAVE_DIRECTORY = Path(__file__).parents[1] / "temp"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import __main__
|
|
||||||
|
|
||||||
class DatabaseSettings:
|
class DatabaseSettings:
|
||||||
DATABASE_DIRECTORY = Path(__main__.__file__).parent / "database/storage"
|
DATABASE_DIRECTORY = Path(__file__).parents[1] / "database" / "storage"
|
||||||
|
|
34
backend/src/models/requestentry.py
Normal file
34
backend/src/models/requestentry.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
from enum import Enum
|
||||||
|
import marshmallow as ma
|
||||||
|
|
||||||
|
class ModifiersEnum(Enum):
|
||||||
|
NONE = 0
|
||||||
|
ESPORTS = 1
|
||||||
|
SUPER = 2
|
||||||
|
HYPER = 3
|
||||||
|
|
||||||
|
class BaseField(ma.Schema):
|
||||||
|
id = ma.fields.Integer(description="Atlas Academy id")
|
||||||
|
image = ma.fields.Url(description="URL to atlas image")
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
class CeField(BaseField):
|
||||||
|
name = ma.fields.String(description="Name of CE", example="Holy Night Supper")
|
||||||
|
mlb = ma.fields.Boolean(description="If the CE should be MLB or not", example=True)
|
||||||
|
|
||||||
|
class RequestFieldContent(ma.Schema):
|
||||||
|
servant = ma.fields.Nested(ServantField)
|
||||||
|
ce = ma.fields.Nested(CeField)
|
||||||
|
|
||||||
|
class RequestPostData(ma.Schema):
|
||||||
|
username = ma.fields.String(description="Username of the requesting person", example="Firq")
|
||||||
|
description = ma.fields.String(description="Short description for what the request is used", example="DB 7T attempts with Scathach")
|
||||||
|
friendcode = ma.fields.String(description="Friendcode of the requesting person", example="000,000,000")
|
||||||
|
request = ma.fields.Nested(RequestFieldContent)
|
||||||
|
|
||||||
|
class RequestDatabaseEntry(RequestPostData):
|
||||||
|
uuid = ma.fields.String(description="UUID v4 of the request")
|
|
@ -3,6 +3,7 @@ from flask.views import MethodView
|
||||||
|
|
||||||
from database import Database
|
from database import Database
|
||||||
from models.requests import RequestsCreate, RequestStatus
|
from models.requests import RequestsCreate, RequestStatus
|
||||||
|
from models.requestentry import RequestPostData
|
||||||
from . import routes_requests as blp
|
from . import routes_requests as blp
|
||||||
|
|
||||||
db = Database.get_instance().db
|
db = Database.get_instance().db
|
||||||
|
@ -10,8 +11,10 @@ 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.response(200, RequestsCreate, description="Successful operation")
|
@blp.response(200, RequestsCreate, description="Successful operation")
|
||||||
def post(self):
|
def post(self, 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" }
|
requests[uuid] = { "status": "created" }
|
||||||
|
|
Loading…
Reference in a new issue