Skip to content

Commit

Permalink
move defs equal main
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasGinard committed Aug 31, 2024
1 parent 9e37914 commit f8369d6
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
allow_credentials=True,
)


@app.on_event("startup")
async def startup():
await db.connect()
Expand All @@ -44,11 +45,33 @@ async def shutdown():
await db.disconnect()


@app.post("/api/v1/providers", response_model=schemas.APIKey, tags=[models.TagsEnum.apiKeyMaster])
async def create_provider(
provider: schemas.Provider, key: APIKey = Depends(validate_master_key)
):
key = await models.Provider.create_new_key(db, provider.provider)
return schemas.APIKey(key=key)


@app.get("/api/v1/providers", tags=[models.TagsEnum.apiKeyMaster])
async def list_providers(key: APIKey = Depends(validate_master_key)):
return [
schemas.Provider.from_orm(s) for s in await models.Provider.get_providers(db)
]


@app.delete("/api/v1/providers/{provider}", tags=[models.TagsEnum.apiKeyMaster])
async def delete_provider(provider: str, key: APIKey = Depends(validate_master_key)):
return await models.Provider.revoke_all_keys(db, provider)


@app.post("/api/v1/measurements", tags=[models.TagsEnum.apiKey])
async def post(
measurements: List[schemas.Measurement], provider: str = Depends(validate_api_key)
):
await models.Measurement.store(db, [m.to_orm(provider) for m in measurements])


@app.get("/api/v1/measurements", response_model=List[schemas.Measurement], tags=[models.TagsEnum.public])
async def get(query: schemas.QueryParams = Depends(schemas.QueryParams)):
return [
Expand All @@ -74,23 +97,4 @@ async def status():
if db.connection() is None:
status.database = schemas.Status.DOWN

return status

@app.post("/api/v1/providers", response_model=schemas.APIKey, tags=[models.TagsEnum.apiKeyMaster])
async def create_provider(
provider: schemas.Provider, key: APIKey = Depends(validate_master_key)
):
key = await models.Provider.create_new_key(db, provider.provider)
return schemas.APIKey(key=key)


@app.get("/api/v1/providers", tags=[models.TagsEnum.apiKeyMaster])
async def list_providers(key: APIKey = Depends(validate_master_key)):
return [
schemas.Provider.from_orm(s) for s in await models.Provider.get_providers(db)
]


@app.delete("/api/v1/providers/{provider}", tags=[models.TagsEnum.apiKeyMaster])
async def delete_provider(provider: str, key: APIKey = Depends(validate_master_key)):
return await models.Provider.revoke_all_keys(db, provider)
return status

0 comments on commit f8369d6

Please sign in to comment.