Initial commit

This commit is contained in:
2023-12-14 01:18:57 +01:00
commit 17c50e321c
17 changed files with 1433 additions and 0 deletions

96
classes/exceptions.py Normal file
View File

@@ -0,0 +1,96 @@
from fastapi import HTTPException
class LocationNotFoundError(HTTPException):
"""Raises HTTP 404 if no location with this ID found."""
def __init__(self, id: int):
self.id = id
self.openapi = {
"description": "Location Does Not Exist",
"content": {
"application/json": {
"example": {"detail": "Could not find location with id '{id}'."}
}
},
}
class EntrySearchQueryEmptyError(HTTPException):
"""Raises HTTP 422 if no entry search query provided."""
def __init__(self):
self.openapi = {
"description": "Invalid Query",
"content": {
"application/json": {
"example": {
"detail": "You must provide location and date(s) to look for entries."
}
}
},
}
super().__init__(
status_code=422,
detail=self.openapi["content"]["application/json"]["example"]["detail"],
)
class LocationSearchQueryEmptyError(HTTPException):
"""Raises HTTP 422 if no location search query provided."""
def __init__(self):
self.openapi = {
"description": "Invalid Query",
"content": {
"application/json": {
"example": {
"detail": "You must provide name or coordinates to look for location."
}
}
},
}
super().__init__(
status_code=422,
detail=self.openapi["content"]["application/json"]["example"]["detail"],
)
class SearchLimitInvalidError(HTTPException):
"""Raises HTTP 400 if search results limit not in valid range."""
def __init__(self):
self.openapi = {
"description": "Invalid Limit",
"content": {
"application/json": {
"example": {
"detail": "Parameter 'limit' must be greater or equal to 1."
}
}
},
}
super().__init__(
status_code=400,
detail=self.openapi["content"]["application/json"]["example"]["detail"],
)
class SearchPageInvalidError(HTTPException):
"""Raises HTTP 400 if page or page size are not in valid range."""
def __init__(self):
self.openapi = {
"description": "Invalid Page",
"content": {
"application/json": {
"example": {
"detail": "Parameters 'page' and 'page_size' must be greater or equal to 1."
}
}
},
}
super().__init__(
status_code=400,
detail=self.openapi["content"]["application/json"]["example"]["detail"],
)

25
classes/models.py Normal file
View File

@@ -0,0 +1,25 @@
from typing import List, Literal
from pydantic import BaseModel
class CollectionEntry(BaseModel):
locations: List[int]
garbage_type: Literal[0, 1, 2, 3, 4, 5]
date: str
class Location(BaseModel):
id: int
name: str
location: List[int]
country: int
timezone: str
class SearchResultsCollectionEntry(BaseModel):
results: List[CollectionEntry]
class SearchResultsLocation(BaseModel):
results: List[Location]