-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start api (uvicorn bloom.services.api:app --host 0.0.0.0 --reload)
- Loading branch information
herve.le-bars
committed
Apr 22, 2024
1 parent
944934a
commit 767d35c
Showing
6 changed files
with
135 additions
and
3 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
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,49 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import FastAPI, File, UploadFile | ||
|
||
from bloom.config import settings | ||
from bloom.container import UseCases | ||
from bloom.domain.vessel import Vessel | ||
from fastapi.encoders import jsonable_encoder | ||
|
||
from bloom.logger import logger | ||
|
||
import json | ||
|
||
app = FastAPI() | ||
|
||
@app.get("/vessels") | ||
async def read_vessels(): | ||
with open(settings.vessel_data) as file: | ||
return json.load(file) | ||
|
||
@app.get("/vessels/*/lastPosition") | ||
async def read_vessels_last_positions(): | ||
with open(settings.vessel_last_position_data) as file: | ||
return json.load(file) | ||
|
||
@app.get("/vessels/tracks") | ||
async def read_vessels_tracks(): | ||
with open(settings.tracks_by_vessel_and_voyage_data) as file: | ||
return json.load(file) | ||
|
||
@app.get("/vessels/tracks/by-mmsi/{mmsi}") | ||
async def read_vessels_tracks(mmsi:int): | ||
with open(settings.tracks_by_vessel_and_voyage_data) as file: | ||
return list(filter(lambda d: d ['properties']['vessel_mmsi'] in [mmsi],json.load(file))) | ||
|
||
|
||
@app.get("/vessels/by-mmsi/{mmsi}/lastPosition") | ||
async def read_vessels_last_positions(mmsi:int): | ||
with open(settings.vessel_last_position_data) as file: | ||
return list(filter(lambda d: d['vessel_mmsi'] in [mmsi],json.load(file))) | ||
|
||
@app.get("/vessels/by-mmsi/{mmsi}") | ||
async def read_vessels_by_mmsi(mmsi: int): | ||
use_cases = UseCases() | ||
vessel_repository = use_cases.vessel_repository() | ||
db = use_cases.db() | ||
with db.session() as session: | ||
db = use_cases.db() | ||
return vessel_repository.get_vessel_by_mmsi(session,mmsi) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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