Skip to content

Commit

Permalink
[+] planets and sectors api
Browse files Browse the repository at this point in the history
  • Loading branch information
gmankab committed Jun 20, 2024
1 parent 4b3a5f6 commit 3e18b36
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions galaxy_backend/api/planets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,41 @@ async def sector_list() -> list[dict]:
})
return sectors_list


@api.routers.planet.get('/list')
async def planet_list() -> list[dict]:
'''
list planets
'''
planets_list: list[dict] = []
planets_models = await models.db.Planet.all().prefetch_related('sector')
for planet in planets_models:
planets_list.append({
'id': planet.id,
'sector': planet.sector.id,
'total_resources': planet.total_resources,
'mined_resources': planet.mined_resources,
'available': planet.available,
})
return planets_list


@api.routers.sector.get('/get')
async def sector_get(
sector_id: int
) -> list[dict]:
'''
get planets from sector
'''
planets_list: list[dict] = []
planets_models = await models.db.Planet.filter(sector_id=sector_id).prefetch_related('sector')
for planet in planets_models:
planets_list.append({
'id': planet.id,
'sector': planet.sector.id,
'total_resources': planet.total_resources,
'mined_resources': planet.mined_resources,
'available': planet.available,
})
return planets_list

0 comments on commit 3e18b36

Please sign in to comment.