Make class names singular

This commit is contained in:
Fitti 2021-06-22 16:42:50 +02:00
parent 7066f4d11a
commit 010d59caac
2 changed files with 12 additions and 12 deletions

View File

@ -1,5 +1,5 @@
from . import db from . import db
from .models import Donations, Services from .models import Donation, Service
from ..satspay.crud import delete_charge from ..satspay.crud import delete_charge
@ -32,7 +32,7 @@ async def create_donation(
amount: float, amount: float,
service: int, service: int,
posted: bool = False, posted: bool = False,
) -> Donations: ) -> Donation:
await db.execute( await db.execute(
""" """
INSERT INTO Donations ( INSERT INTO Donations (
@ -81,7 +81,7 @@ async def create_service(
wallet: str, wallet: str,
servicename: str, servicename: str,
onchain: str = None, onchain: str = None,
) -> Services: ) -> Service:
result = await db.execute( result = await db.execute(
""" """
INSERT INTO Services ( INSERT INTO Services (
@ -110,12 +110,12 @@ async def create_service(
return service return service
async def get_service(service_id: int) -> Optional[Services]: async def get_service(service_id: int) -> Optional[Service]:
row = await db.fetchone( row = await db.fetchone(
"SELECT * FROM Services WHERE id = ?", "SELECT * FROM Services WHERE id = ?",
(service_id,) (service_id,)
) )
return Services.from_row(row) if row else None return Service.from_row(row) if row else None
async def authenticate_service(service_id, code, redirect_uri): async def authenticate_service(service_id, code, redirect_uri):
@ -160,17 +160,17 @@ async def delete_service(service_id: int) -> None:
await delete_donation(row["id"]) await delete_donation(row["id"])
async def get_donation(donation_id: str) -> Optional[Donations]: async def get_donation(donation_id: str) -> Optional[Donation]:
row = await db.fetchone( row = await db.fetchone(
"SELECT * FROM Donations WHERE id = ?", "SELECT * FROM Donations WHERE id = ?",
(donation_id,) (donation_id,)
) )
return Donations.from_row(row) if row else None return Donation.from_row(row) if row else None
async def delete_donation(donation_id: str) -> None: async def delete_donation(donation_id: str) -> None:
await db.execute( await db.execute(
"DELETE FROM Donatoins WHERE id = ?", "DELETE FROM Donations WHERE id = ?",
(donation_id,) (donation_id,)
) )
await delete_charge(donation_id) await delete_charge(donation_id)

View File

@ -2,7 +2,7 @@ from sqlite3 import Row
from typing import NamedTuple, Optional from typing import NamedTuple, Optional
class Donations(NamedTuple): class Donation(NamedTuple):
id: str id: str
name: str name: str
cur_code: str cur_code: str
@ -12,11 +12,11 @@ class Donations(NamedTuple):
posted: bool posted: bool
@classmethod @classmethod
def from_row(cls, row: Row) -> "Donations": def from_row(cls, row: Row) -> "Donation":
return cls(**dict(row)) return cls(**dict(row))
class Services(NamedTuple): class Service(NamedTuple):
id: int id: int
twitchuser: str twitchuser: str
client_id: str client_id: str
@ -28,5 +28,5 @@ class Services(NamedTuple):
token: Optional[int] token: Optional[int]
@classmethod @classmethod
def from_row(cls, row: Row) -> "Services": def from_row(cls, row: Row) -> "Service":
return cls(**dict(row)) return cls(**dict(row))