Skip to content

Commit

Permalink
Getting ready to revise ORM usage
Browse files Browse the repository at this point in the history
  • Loading branch information
le717 committed Jun 8, 2024
1 parent 175c54c commit 5d3dcc6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/core/database/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from src.core.database import linkrot, weblink

__all__ = ["linkrot", "weblink"]
10 changes: 5 additions & 5 deletions src/views/linkrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
from flask_smorest import abort

from src.blueprints import linkrot
from src.core import database as db
from src.core import models
from src.core.database import linkrot as db


@linkrot.route("/")
class LinkRotCheck(MethodView):
@linkrot.arguments(models.AuthKey, location="query", as_kwargs=True)
@linkrot.response(200, models.RotResult(many=True))
def post(self, **kwargs: Any) -> list[db.RotResult]:
def post(self, **kwargs: Any) -> list[db.linkrot.RotResult]:
"""Check all links in the ring for link rot."""
del kwargs["auth_key"]
return db.check_all()
return db.linkrot.check_all()


@linkrot.route("/<uuid:id>")
Expand All @@ -24,9 +24,9 @@ class LinkRotSingleCheck(MethodView):
@linkrot.arguments(models.WebLinkId, location="path", as_kwargs=True)
@linkrot.response(200, models.RotResult)
@linkrot.alt_response(404, schema=models.HttpError)
def post(self, **kwargs: Any) -> db.RotResult | None:
def post(self, **kwargs: Any) -> db.linkrot.RotResult | None:
"""Check a single link in the ring for link rot."""
del kwargs["auth_key"]
if (result := db.check_one(str(kwargs["id"]))) is None:
if (result := db.linkrot.check_one(str(kwargs["id"]))) is None:
abort(404, message="That ID does not exist in the webring.")
return result
10 changes: 5 additions & 5 deletions src/views/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from flask.views import MethodView

from src.blueprints import root
from src.core import database as db
from src.core import models
from src.core.database import weblink as db


@root.route("/")
Expand All @@ -24,15 +24,15 @@ def get(self, **kwargs: Any) -> Sequence[models.WebLink]:
query_args = {}
if kwargs["exclude_origin"]:
query_args["http_origin"] = request.headers.get("ORIGIN")
return db.get_all(include_rotted=kwargs["include_rotted"], **query_args)
return db.weblink.get_all(include_rotted=kwargs["include_rotted"], **query_args)

@root.arguments(models.AuthKey, location="query", as_kwargs=True)
@root.arguments(models.WebLinkCreate, location="json", as_kwargs=True)
@root.response(201, models.WebLinkId)
def post(self, **kwargs: Any) -> dict[str, UUID]:
"""Create a webring item."""
del kwargs["auth_key"]
return db.create(kwargs)
return db.weblink.create(kwargs)


@root.route("/<uuid:id>")
Expand All @@ -43,7 +43,7 @@ class WebRing(MethodView):
def delete(self, **kwargs: Any) -> None:
"""Delete a webring item."""
del kwargs["auth_key"]
db.delete(str(kwargs["id"]))
db.weblink.delete(str(kwargs["id"]))

@root.arguments(models.AuthKey, location="query", as_kwargs=True)
@root.arguments(models.WebLinkId, location="path", as_kwargs=True)
Expand All @@ -55,5 +55,5 @@ def patch(self, **kwargs: Any) -> None:
del kwargs["auth_key"]

kwargs["id"] = str(kwargs["id"])
if not db.update(kwargs):
if not db.weblink.update(kwargs):
abort(400)

0 comments on commit 5d3dcc6

Please sign in to comment.