1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +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! # Imports go here!
from .api_diario_get import ApiDiarioGetStar
from .api_diario_list import ApiDiarioListStar
from .api_user_list import ApiUserListStar from .api_user_list import ApiUserListStar
from .api_user_get import ApiUserGetStar 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_discord_cv import ApiDiscordCvStar
from .api_wiki_get import ApiWikiGetStar
from .api_wiki_list import ApiUserListStar
from .api_discord_play import ApiDiscordPlayStar 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! # Enter the PageStars of your Pack here!
available_page_stars = [ available_page_stars = [
ApiUserListStar,
ApiUserGetStar,
ApiDiarioListStar,
ApiDiarioGetStar, ApiDiarioGetStar,
ApiDiarioListStar,
ApiDiscordCvStar, ApiDiscordCvStar,
ApiWikiGetStar,
ApiUserListStar,
ApiDiscordPlayStar, ApiDiscordPlayStar,
] ApiUserGetStar,
ApiUserListStar,
# Enter the ExceptionStars of your Pack here! ApiWikiGetStar,
available_exception_stars = [ ApiWikiListStar,
] ]
# Don't change this, it should automatically generate __all__ # 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.constellation.api import *
from royalnet.utils import * from royalnet.utils import *
from ..tables import * from ..tables import *
@ -10,9 +8,9 @@ class ApiDiarioGetStar(ApiStar):
async def api(self, data: ApiData) -> dict: async def api(self, data: ApiData) -> dict:
try: try:
diario_id = int(data["diario_id"]) diario_id = int(data["id"])
except ValueError: 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) entry: Diario = await asyncify(data.session.query(self.alchemy.get(Diario)).get, diario_id)
if entry is None: if entry is None:
raise NotFoundError("No such diario entry.") raise NotFoundError("No such diario entry.")

View file

@ -1,4 +1,3 @@
from starlette.requests import Request
from starlette.responses import * from starlette.responses import *
from royalnet.constellation.api import * from royalnet.constellation.api import *
from royalnet.utils 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.constellation.api import *
from royalnet.utils import *
class ApiDiscordCvStar(ApiStar): class ApiDiscordCvStar(ApiStar):

View file

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

View file

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

View file

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

View file

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

View file

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