Skip to content

Commit

Permalink
I dont remember what I was coding
Browse files Browse the repository at this point in the history
  • Loading branch information
Furrior committed Feb 7, 2025
1 parent 75efc80 commit 91232dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion app/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
def init() -> None:
init_db()


if __name__ == "__main__":
init()
19 changes: 10 additions & 9 deletions app/routes/v1/donate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import logging
from fastapi import APIRouter, Depends, HTTPException, Request, status
from sqlmodel import select
Expand All @@ -15,28 +16,28 @@

router = APIRouter(prefix="/donate", tags=["Donate"])

def filter_donations(selection: SelectOfScalar[Donation], ckey: str | None = None, discord_id: str | None = None, valid_only: bool = True) -> SelectOfScalar[Donation]:
def filter_donations(selection: SelectOfScalar[Donation], ckey: str | None = None, discord_id: str | None = None, active_only: bool = True) -> SelectOfScalar[Donation]:
if ckey:
selection = selection.where(Player.ckey == ckey)
if discord_id:
selection = selection.where(Player.discord_id == discord_id)
if valid_only:
selection = selection.where(Donation.valid)
if active_only:
selection = selection.where(Donation.valid).where(Donation.expiration_time > datetime.datetime.now())
return selection


@router.get("", status_code=status.HTTP_200_OK)
@router.get("s", status_code=status.HTTP_200_OK)
async def get_donations(session: SessionDep,
request: Request,
ckey: str | None = None,
discord_id: str | None = None,
valid_only: bool = True,
active_only: bool = True,
page: int = 1,
page_size: int = 50) -> PaginatedResponse[Donation]:
selection = select(Donation).join(
Player, Player.id == Donation.player_id)

selection = filter_donations(selection, ckey, discord_id, valid_only)
selection = filter_donations(selection, ckey, discord_id, active_only)

return paginate_selection(session, selection, request, page, page_size)

Expand All @@ -56,9 +57,9 @@ async def create_donation(session: SessionDep, donation: Donation) -> Donation:
}

@router.post("/by-discord", status_code=status.HTTP_201_CREATED, dependencies=[Depends(verify_bearer)], responses=WHITELIST_POST_RESPONSES)
async def create_donation_by_discord(session: SessionDep, donation: NewDonationDiscord) -> Donation:
async def create_donation_by_discord(session: SessionDep, new_donation: NewDonationDiscord) -> Donation:
player = session.exec(
select(Player).where(Player.discord_id == donation.discord_id)
select(Player).where(Player.discord_id == new_donation.discord_id)
).first()

if player is None:
Expand All @@ -67,7 +68,7 @@ async def create_donation_by_discord(session: SessionDep, donation: NewDonationD

donation = Donation(
player_id=player.id,
tier=donation.tier
tier=new_donation.tier
)

return await create_donation(session, donation)
Expand Down

0 comments on commit 91232dc

Please sign in to comment.