Pack Type addition
add pack_team and pack_cardset fields
This commit is contained in:
parent
d613901c97
commit
8d0b359e85
@ -248,6 +248,8 @@ db.create_tables([PackType])
|
||||
class Pack(BaseModel):
|
||||
team = ForeignKeyField(Team)
|
||||
pack_type = ForeignKeyField(PackType)
|
||||
pack_team = ForeignKeyField(Team, null=True)
|
||||
pack_cardset = ForeignKeyField(Cardset, null=True)
|
||||
open_time = DateTimeField(null=True)
|
||||
|
||||
|
||||
|
||||
29
main.py
29
main.py
@ -1880,6 +1880,8 @@ PACK ENDPOINTS
|
||||
class PackPydantic(pydantic.BaseModel):
|
||||
team_id: int
|
||||
pack_type_id: int
|
||||
pack_team_id: Optional[int] = None
|
||||
pack_cardset_id: Optional[int] = None
|
||||
open_time: Optional[str] = None
|
||||
|
||||
|
||||
@ -1890,7 +1892,8 @@ class PackModel(pydantic.BaseModel):
|
||||
@app.get('/api/v1/packs')
|
||||
async def v1_packs_get(
|
||||
team_id: Optional[int] = None, pack_type_id: Optional[int] = None, opened: Optional[bool] = None,
|
||||
limit: Optional[int] = None, new_to_old: Optional[bool] = None, csv: Optional[bool] = None):
|
||||
limit: Optional[int] = None, new_to_old: Optional[bool] = None, pack_team_id: Optional[int] = None,
|
||||
pack_cardset_id: Optional[int] = None, csv: Optional[bool] = None):
|
||||
all_packs = Pack.select()
|
||||
|
||||
if all_packs.count() == 0:
|
||||
@ -1911,6 +1914,20 @@ async def v1_packs_get(
|
||||
db.close()
|
||||
raise HTTPException(status_code=404, detail=f'No pack type found with id {pack_type_id}')
|
||||
all_packs = all_packs.where(Pack.pack_type == this_pack_type)
|
||||
if pack_team_id is not None:
|
||||
try:
|
||||
this_pack_team = Team.get_by_id(pack_type_id)
|
||||
except Exception:
|
||||
db.close()
|
||||
raise HTTPException(status_code=404, detail=f'No team found with id {pack_team_id}')
|
||||
all_packs = all_packs.where(Pack.pack_team == this_pack_team)
|
||||
if pack_cardset_id is not None:
|
||||
try:
|
||||
this_pack_cardset = Cardset.get_by_id(pack_cardset_id)
|
||||
except Exception:
|
||||
db.close()
|
||||
raise HTTPException(status_code=404, detail=f'No cardset found with id {pack_cardset_id}')
|
||||
all_packs = all_packs.where(Pack.pack_cardset == this_pack_cardset)
|
||||
if opened is not None:
|
||||
all_packs = all_packs.where(Pack.open_time.is_null(not opened))
|
||||
if limit is not None:
|
||||
@ -1985,6 +2002,8 @@ async def v1_packs_post(packs: PackModel, token: str = Depends(oauth2_scheme)):
|
||||
this_player = Pack(
|
||||
team_id=x.team_id,
|
||||
pack_type_id=x.pack_type_id,
|
||||
pack_team_id=x.pack_team_id,
|
||||
pack_cardset_id=x.pack_cardset_id,
|
||||
open_time=x.open_time if x.open_time != "" else None
|
||||
)
|
||||
new_packs.append(this_player)
|
||||
@ -2009,6 +2028,8 @@ async def v1_packs_post_one(pack: PackPydantic, token: str = Depends(oauth2_sche
|
||||
this_pack = Pack(
|
||||
team_id=pack.team_id,
|
||||
pack_type_id=pack.pack_type_id,
|
||||
pack_team_id=pack.pack_team_id,
|
||||
pack_cardset_id=pack.pack_cardset_id,
|
||||
open_time=pack.open_time
|
||||
)
|
||||
|
||||
@ -2027,7 +2048,7 @@ async def v1_packs_post_one(pack: PackPydantic, token: str = Depends(oauth2_sche
|
||||
@app.patch('/api/v1/packs/{pack_id}')
|
||||
async def v1_packs_patch(
|
||||
pack_id, team_id: Optional[int] = None, pack_type_id: Optional[int] = None, open_time: Optional[int] = None,
|
||||
token: str = Depends(oauth2_scheme)):
|
||||
pack_team_id: Optional[int] = None, pack_cardset_id: Optional[int] = None, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
db.close()
|
||||
@ -2045,6 +2066,10 @@ async def v1_packs_patch(
|
||||
this_pack.team_id = team_id
|
||||
if pack_type_id is not None:
|
||||
this_pack.pack_type_id = pack_type_id
|
||||
if pack_team_id is not None:
|
||||
this_pack.pack_team_id = pack_team_id
|
||||
if pack_cardset_id is not None:
|
||||
this_pack.pack_cardset_id = pack_cardset_id
|
||||
if open_time is not None:
|
||||
this_pack.open_time = open_time
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user