Skip to content

Commit

Permalink
minor code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 30, 2024
1 parent 39f5d0a commit a490454
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions server/contrib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from dataclasses import dataclass
from datetime import datetime
from typing import Annotated, Any
from uuid import UUID

import litestar
from litestar import Response
Expand Down Expand Up @@ -178,7 +178,7 @@ async def delete_patch(patch_id: str, request: AuthorizedRequest) -> Redirect:

@router
@litestar.get("/edit/subject/{patch_id:uuid}", guards=[require_user_login])
async def _(request: AuthorizedRequest, patch_id: uuid.UUID) -> Response[Any]:
async def _(request: AuthorizedRequest, patch_id: UUID) -> Response[Any]:
p = await pg.fetchrow(
"select * from view_subject_patch where id = $1",
patch_id,
Expand Down Expand Up @@ -225,7 +225,7 @@ class EditSubjectPatch:
)
async def _(
request: AuthorizedRequest,
patch_id: uuid.UUID,
patch_id: UUID,
data: Annotated[EditSubjectPatch, Body(media_type=RequestEncodingType.URL_ENCODED)],
) -> Response[Any]:
await _validate_captcha(data.cf_turnstile_response)
Expand Down Expand Up @@ -412,7 +412,7 @@ async def creat_episode_patch(
guards=[require_user_login],
status_code=200,
)
async def delete_episode_patch(patch_id: uuid.UUID, request: AuthorizedRequest) -> Redirect:
async def delete_episode_patch(patch_id: UUID, request: AuthorizedRequest) -> Redirect:
async with pg.acquire() as conn:
async with conn.transaction():
p = await conn.fetchrow(
Expand Down
4 changes: 2 additions & 2 deletions server/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum
import uuid
from dataclasses import dataclass
from datetime import datetime
from uuid import UUID


class PatchState(enum.IntEnum):
Expand All @@ -13,7 +13,7 @@ class PatchState(enum.IntEnum):

@dataclass(frozen=True, kw_only=True, slots=True)
class PatchBase:
id: uuid.UUID
id: UUID
state: int
from_user_id: int
wiki_user_id: int
Expand Down
8 changes: 4 additions & 4 deletions server/patch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import difflib
import uuid
from uuid import UUID

import litestar
from litestar.exceptions import InternalServerException, NotFoundException
Expand All @@ -17,13 +17,13 @@

@router
@litestar.get("/patch/{patch_id:uuid}", sync_to_thread=False)
def get_patch_redirect(patch_id: uuid.UUID) -> Redirect:
def get_patch_redirect(patch_id: UUID) -> Redirect:
return Redirect(f"/subject/{patch_id}")


@router
@litestar.get("/subject/{patch_id:uuid}")
async def get_patch(patch_id: uuid.UUID, request: Request) -> Template:
async def get_patch(patch_id: UUID, request: Request) -> Template:
p = await pg.fetchrow(
"""select * from subject_patch where id = $1 and deleted_at is NULL limit 1""", patch_id
)
Expand Down Expand Up @@ -112,7 +112,7 @@ async def get_patch(patch_id: uuid.UUID, request: Request) -> Template:

@router
@litestar.get("/episode/{patch_id:uuid}")
async def get_episode_patch(patch_id: uuid.UUID, request: Request) -> Template:
async def get_episode_patch(patch_id: UUID, request: Request) -> Template:
p = await pg.fetchrow(
"""select * from episode_patch where id = $1 and deleted_at is NULL limit 1""", patch_id
)
Expand Down
8 changes: 4 additions & 4 deletions server/review.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

import enum
import uuid
from dataclasses import dataclass
from datetime import datetime
from typing import Annotated, Any
from uuid import UUID

import litestar
import pydash
Expand Down Expand Up @@ -220,7 +220,7 @@ class EpisodeReviewController(Controller):
)
async def review_episode_patch(
self,
patch_id: uuid.UUID,
patch_id: UUID,
request: AuthorizedRequest,
data: Annotated[ReviewPatch, Body(media_type=RequestEncodingType.URL_ENCODED)],
) -> Response[Any]:
Expand Down Expand Up @@ -248,7 +248,7 @@ async def review_episode_patch(
raise NotAuthorizedException("暂不支持")

async def __reject_episode_patch(
self, patch_id: uuid.UUID, conn: PoolConnectionProxy[Record], auth: User, reason: str
self, patch_id: UUID, conn: PoolConnectionProxy[Record], auth: User, reason: str
) -> Redirect:
await conn.execute(
"""
Expand Down Expand Up @@ -336,7 +336,7 @@ class CommentReviewController(Controller):
async def handler(
self,
request: AuthorizedRequest,
patch_id: uuid.UUID,
patch_id: UUID,
data: Annotated[CommentOnPatch, Body(media_type=RequestEncodingType.URL_ENCODED)],
patch_type: Annotated[PatchType, params.Parameter(query="type")] = PatchType.Subject,
) -> Response[Any]:
Expand Down

0 comments on commit a490454

Please sign in to comment.