Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add group endpoints #121

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,9 @@ class ServiceStatus(BaseModel):
title="Database",
description="Operational status of the database",
)


class TagsEnum(str, Enum):
apiKeyMaster = "Requests with Master apiKey 🔑"
apiKey = "Requests with apiKey 🔑"
public = "Requests Public 🌎"
34 changes: 26 additions & 8 deletions app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,52 +43,70 @@ async def lifespan(app: FastAPI):
)


LucasGinard marked this conversation as resolved.
Show resolved Hide resolved
@app.post("/api/v1/providers", response_model=schemas.APIKey)
LucasGinard marked this conversation as resolved.
Show resolved Hide resolved
@app.post(
"/api/v1/providers",
response_model=schemas.APIKey,
tags=[schemas.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")
@app.get("/api/v1/providers", tags=[schemas.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}")
@app.delete("/api/v1/providers/{provider}", tags=[schemas.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")
@app.post("/api/v1/measurements", tags=[schemas.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])
@app.get(
"/api/v1/measurements",
response_model=List[schemas.Measurement],
tags=[schemas.TagsEnum.public],
)
async def get(query: schemas.QueryParams = Depends(schemas.QueryParams)):
return [
schemas.Measurement.from_orm(m)
for m in await models.Measurement.retrieve(db, query)
]


@app.get("/api/v1/aqi", response_model=List[schemas.Report])
@app.get(
"/api/v1/aqi", response_model=List[schemas.Report], tags=[schemas.TagsEnum.public]
)
async def aqi(query: schemas.QueryParams = Depends(schemas.QueryParams)):
return await reports.AQI.generate(db, query)


@app.get("/api/v1/stats", response_model=List[schemas.ReportStats])
@app.get(
"/api/v1/stats",
response_model=List[schemas.ReportStats],
tags=[schemas.TagsEnum.public],
)
async def stats(query: schemas.QueryParams = Depends(schemas.QueryParams)):
return await reports.Stats.generate(db, query)


@app.get("/api/v1/status", response_model=schemas.ServiceStatus)
@app.get(
"/api/v1/status",
response_model=schemas.ServiceStatus,
tags=[schemas.TagsEnum.public],
)
async def status():
status = schemas.ServiceStatus()

Expand Down
Loading