Skip to content

Commit

Permalink
fix: Aliases are now not required thus they work
Browse files Browse the repository at this point in the history
  • Loading branch information
wikipop committed Oct 7, 2024
1 parent 9b2fb05 commit cddd46c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
22 changes: 10 additions & 12 deletions backend/routers/report_router.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import timedelta, datetime
from datetime import datetime, timedelta

import structlog
from fastapi import APIRouter, BackgroundTasks, Depends
Expand All @@ -8,8 +8,12 @@
from backend import models, schemas
from backend.database import get_db
from backend.schemas.landsat.landsat_item_advanced import LandsatAdvancedItem
from backend.schemas.structures.report_result import ReportResultError, ReportResultProcess, ReportResultSuccess, \
ReportResult
from backend.schemas.structures.report_result import (
ReportResult,
ReportResultError,
ReportResultProcess,
ReportResultSuccess,
)
from backend.tasks.write_report import write_report_to_db
from backend.utils.auth import get_current_user

Expand All @@ -29,15 +33,11 @@ async def generate_report(scene_id: str, background_tasks: BackgroundTasks, db:
is_processed=report.is_processed,
scene_id=report.scene_id,
created_at=report.created_at,
data=LandsatAdvancedItem.model_validate(report.raw_data)
data=LandsatAdvancedItem.model_validate(report.raw_data),
)

if datetime.now() - report.created_at < timedelta(minutes=10):
return ReportResultProcess(
is_processed=False,
scene_id=report.scene_id,
created_at=report.created_at
)
return ReportResultProcess(is_processed=False, scene_id=report.scene_id, created_at=report.created_at)

if datetime.now() - report.created_at > timedelta(minutes=10):
db.delete(report)
Expand Down Expand Up @@ -82,8 +82,6 @@ async def get_report(scene_id: str, db: Session = Depends(get_db)) -> ReportResu
@report_router.get("/get_reports", response_model=list[schemas.Report])
async def get_reports(user: UserResponse = Depends(get_current_user), db: Session = Depends(get_db)):
# todo: return only user reports
reports = (
db.query(models.Report).all()
)
reports = db.query(models.Report).all()

return reports
6 changes: 3 additions & 3 deletions backend/schemas/structures/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pydantic import BaseModel, Field
from pydantic import AliasChoices, BaseModel, Field


class Coordinates(BaseModel):
latitude: float = Field(..., alias="lat", ge=-90, le=90)
longitude: float = Field(..., alias="lon", ge=-180, le=180)
latitude: float = Field(..., validation_alias=AliasChoices("lat", "latitude"), ge=-90, le=90)
longitude: float = Field(..., validation_alias=AliasChoices("lon", "longitude"), ge=-180, le=180)

def to_list(self):
return [self.latitude, self.longitude]
1 change: 0 additions & 1 deletion backend/schemas/structures/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ class Report(BaseModel):

class Config:
from_attributes = True

6 changes: 3 additions & 3 deletions backend/schemas/structures/wrs_coordinates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel, Field
from pydantic import AliasChoices, BaseModel, Field


class WrsCoordinates(BaseModel):
wrs_path: int = Field(..., alias="path", ge=1, le=233)
wrs_row: int = Field(..., alias="row", ge=1, le=248)
wrs_path: int = Field(..., validation_alias=AliasChoices("path", "wrs_path"), ge=1, le=233)
wrs_row: int = Field(..., validation_alias=AliasChoices("row", "wrs_row"), ge=1, le=248)
2 changes: 1 addition & 1 deletion frontend/openapi/api/openapi.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions frontend/pages/panel/report/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
<script setup lang="ts">
const route = useRoute();
const { data, error } = useApi("/report/get_report", {
query: {
scene_id: route.params.id.toString()
}
});
// data.value.
console.log(data, error)
console.log(data, error);
</script>
8 changes: 6 additions & 2 deletions frontend/pages/panel/reports.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
<TableCell>{{ report.is_processed }}</TableCell>
<TableCell>{{ report.created_at }}</TableCell>
<TableCell>{{ report.scene_id }}</TableCell>
<TableCell><NuxtLink :to="`/panel/report/${report.scene_id}`"><img class="i-material-symbols-light:open-in-new" text-2xl></NuxtLink></TableCell>
<TableCell>
<NuxtLink :to="`/panel/report/${report.scene_id}`">
<img class="i-material-symbols-light:open-in-new" text-2xl>
</NuxtLink>
</TableCell>
<TableCell>
<button class="text-red-500 hover:text-red-700">
DELETE
Expand All @@ -43,7 +47,7 @@ const reports = ref<{
raw_data: string | null
}[]>();
const { data, error } = useApi("/report/get_reports", {
const { data, _ } = useApi("/report/get_reports", {
headers: {
Authorization: `Bearer ${useSupabaseSession().value?.access_token}`
}
Expand Down

0 comments on commit cddd46c

Please sign in to comment.