-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from eodcgmbh/add-collections-endpoints
Add collections endpoints
- Loading branch information
Showing
8 changed files
with
735 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
|
||
import aiohttp | ||
from fastapi import APIRouter | ||
from starlette.responses import JSONResponse | ||
|
||
from openeo_fastapi.client.models import Collection, Collections | ||
|
||
router_collections = APIRouter() | ||
|
||
|
||
async def get_collections(): | ||
""" | ||
Basic metadata for all datasets | ||
""" | ||
|
||
async with aiohttp.ClientSession() as client: | ||
async with client.get(os.getenv("STAC_API_URL") + "collections") as response: | ||
resp = await response.json() | ||
if response.status == 200 and resp.get("collections"): | ||
return Collections(collections=resp["collections"], links=resp["links"]) | ||
else: | ||
return resp | ||
|
||
|
||
async def get_collection(collection_id): | ||
""" | ||
Metadata for specific datasets | ||
""" | ||
|
||
async with aiohttp.ClientSession() as client: | ||
async with client.get( | ||
os.getenv("STAC_API_URL") + f"collections/{collection_id}" | ||
) as response: | ||
resp = await response.json() | ||
if response.status == 200 and resp.get("id"): | ||
return Collection(**resp) | ||
else: | ||
return resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.