1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

probably break some stuff

This commit is contained in:
Steffo 2020-02-09 19:12:34 +01:00
parent 5eec828be1
commit da03f8e6ad
9 changed files with 47 additions and 62 deletions

View file

@ -1,29 +1,24 @@
# Imports go here!
from .api_diario_get import ApiDiarioGetStar
from .api_diario_list import ApiDiarioListStar
from .api_user_list import ApiUserListStar
from .api_user_get import ApiUserGetStar
from .api_diario_list import ApiDiarioListStar
from .api_diario_get import ApiDiarioGetStar
from .api_discord_cv import ApiDiscordCvStar
from .api_wiki_get import ApiWikiGetStar
from .api_wiki_list import ApiUserListStar
from .api_discord_play import ApiDiscordPlayStar
from .api_wiki_get import ApiWikiGetStar
from .api_wiki_list import ApiWikiListStar
# Enter the PageStars of your Pack here!
available_page_stars = [
ApiUserListStar,
ApiUserGetStar,
ApiDiarioListStar,
ApiDiarioGetStar,
ApiDiarioListStar,
ApiDiscordCvStar,
ApiWikiGetStar,
ApiUserListStar,
ApiDiscordPlayStar,
]
# Enter the ExceptionStars of your Pack here!
available_exception_stars = [
ApiUserGetStar,
ApiUserListStar,
ApiWikiGetStar,
ApiWikiListStar,
]
# Don't change this, it should automatically generate __all__
__all__ = [star.__name__ for star in [*available_page_stars, *available_exception_stars]]
__all__ = [star.__name__ for star in available_page_stars]

View file

@ -1,5 +1,3 @@
from starlette.requests import Request
from starlette.responses import *
from royalnet.constellation.api import *
from royalnet.utils import *
from ..tables import *
@ -10,9 +8,9 @@ class ApiDiarioGetStar(ApiStar):
async def api(self, data: ApiData) -> dict:
try:
diario_id = int(data["diario_id"])
diario_id = int(data["id"])
except ValueError:
raise InvalidParameterError("'diario_id' is not a valid int.")
raise InvalidParameterError("'id' is not a valid int.")
entry: Diario = await asyncify(data.session.query(self.alchemy.get(Diario)).get, diario_id)
if entry is None:
raise NotFoundError("No such diario entry.")

View file

@ -1,4 +1,3 @@
from starlette.requests import Request
from starlette.responses import *
from royalnet.constellation.api import *
from royalnet.utils import *

View file

@ -1,7 +1,4 @@
from starlette.requests import Request
from starlette.responses import *
from royalnet.constellation.api import *
from royalnet.utils import *
class ApiDiscordCvStar(ApiStar):

View file

@ -1,6 +1,4 @@
from typing import *
from starlette.requests import Request
from starlette.responses import *
from royalnet.constellation.api import *
import logging
@ -9,7 +7,7 @@ log = logging.getLogger(__name__)
class ApiDiscordPlayStar(ApiStar):
path = "/api/discord/play"
path = "/api/discord/play/v1"
async def api(self, data: ApiData) -> dict:
url = data["url"]
@ -25,6 +23,4 @@ class ApiDiscordPlayStar(ApiStar):
url=url,
guild_id=guild_id,
user=user)
return JSONResponse(response, headers={
"Access-Control-Allow-Origin": "*",
})
return response

View file

@ -3,19 +3,19 @@ from starlette.responses import *
from royalnet.constellation import *
from royalnet.utils import *
from royalnet.backpack.tables import *
from royalnet.constellation.api import *
class ApiUserGetStar(PageStar):
path = "/api/user/get/{uid_str}"
class ApiUserGetStar(ApiStar):
path = "/api/user/get/v1"
async def page(self, request: Request) -> JSONResponse:
uid_str = request.path_params.get("uid_str", "")
async def api(self, data: ApiData) -> dict:
user_id_str = data["id"]
try:
uid = int(uid_str)
user_id = int(user_id_str)
except (ValueError, TypeError):
return shoot(400, "Invalid uid")
async with self.alchemy.session_acm() as session:
user: User = await asyncify(session.query(self.alchemy.get(User)).get, uid)
raise InvalidParameterError("'id' is not a valid int.")
user: User = await asyncify(data.session.query(self.alchemy.get(User)).get, user_id)
if user is None:
return shoot(404, "No such user")
return JSONResponse(user.json())
raise NotFoundError("No such user.")
return user.json()

View file

@ -3,12 +3,12 @@ from starlette.responses import *
from royalnet.constellation import *
from royalnet.utils import *
from royalnet.backpack.tables import *
from royalnet.constellation.api import *
class ApiUserListStar(PageStar):
path = "/api/user/list"
class ApiUserListStar(ApiStar):
path = "/api/user/list/v1"
async def page(self, request: Request) -> JSONResponse:
async with self.alchemy.session_acm() as session:
users: typing.List[User] = await asyncify(session.query(self.alchemy.get(User)).all)
return JSONResponse([user.json() for user in users])
async def api(self, data: ApiData) -> dict:
users: typing.List[User] = await asyncify(data.session.query(self.alchemy.get(User)).all)
return [user.json() for user in users]

View file

@ -4,19 +4,19 @@ from royalnet.constellation import *
from royalnet.utils import *
from ..tables import *
import uuid
from royalnet.constellation.api import *
class ApiWikiGetStar(PageStar):
path = "/api/wiki/get/{wiki_page_uuid}"
class ApiWikiGetStar(ApiStar):
path = "/api/wiki/get/v1"
async def page(self, request: Request) -> JSONResponse:
wiki_page_uuid_str = request.path_params.get("wiki_page_uuid", "")
async def api(self, data: ApiData) -> dict:
wikipage_id_str = data["id"]
try:
wiki_page_uuid = uuid.UUID(wiki_page_uuid_str)
wikipage_id = uuid.UUID(wikipage_id_str)
except (ValueError, AttributeError, TypeError):
return shoot(400, "Invalid wiki_page_uuid")
async with self.alchemy.session_acm() as session:
wikipage: WikiPage = await asyncify(session.query(self.alchemy.get(WikiPage)).get, wiki_page_uuid)
if wikipage is None:
return shoot(404, "No such page")
return JSONResponse(wikipage.json_full())
raise InvalidParameterError("'id' is not a valid UUID.")
wikipage: WikiPage = await asyncify(data.session.query(self.alchemy.get(WikiPage)).get, wikipage_id)
if wikipage is None:
raise NotFoundError("No such page.")
return wikipage.json_full()

View file

@ -4,12 +4,12 @@ from royalnet.constellation import *
from royalnet.utils import *
from royalnet.backpack.tables import *
from ..tables import *
from royalnet.constellation.api import *
class ApiUserListStar(PageStar):
path = "/api/wiki/list"
class ApiWikiListStar(ApiData):
path = "/api/wiki/list/v1"
async def page(self, request: Request) -> JSONResponse:
async with self.alchemy.session_acm() as session:
pages: typing.List[WikiPage] = await asyncify(session.query(self.alchemy.get(WikiPage)).all)
return JSONResponse([page.json_list() for page in pages])
async def api(self, data: ApiData) -> dict:
pages: typing.List[WikiPage] = await asyncify(data.session.query(self.alchemy.get(WikiPage)).all)
return [page.json_list() for page in pages]