-
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.
- Loading branch information
Showing
10 changed files
with
234 additions
and
20 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
git clone with --recurse-submodules | ||
git clone with --recurse-submodules | ||
remeber to git submodule update!! |
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,62 @@ | ||
version: '3.8' | ||
|
||
services: | ||
db: | ||
container_name: postgres | ||
image: postgres | ||
expose: | ||
- "5432" | ||
environment: | ||
POSTGRES_USER: placeholder_superuser | ||
POSTGRES_PASSWORD: placeholder_pw | ||
PGDATA: /data/postgres | ||
POSTGRES_DB: fishsense_db | ||
volumes: | ||
- db:/data/postgres | ||
ports: | ||
- "5332:5432" | ||
networks: | ||
- fishsense_network | ||
restart: always | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -d $$POSTGRES_DB -U $$POSTGRES_USER"] | ||
interval: 30s | ||
timeout: 10s | ||
retries: 5 | ||
|
||
fishsense-database: | ||
build: | ||
context: ./fishsense-database | ||
environment: | ||
DB_HOST: db | ||
DB_NAME: fishsense_db | ||
DB_USER: placeholder_superuser | ||
DB_PASSWORD: placeholder_pw | ||
networks: | ||
- fishsense_network | ||
depends_on: | ||
- db | ||
|
||
fishsense-services: | ||
build: | ||
context: ./ | ||
environment: | ||
DB_HOST: db | ||
DB_NAME: fishsense_db | ||
DB_USER: placeholder_superuser | ||
DB_PASSWORD: placeholder_pw | ||
PYTHONPATH: /app:/app/fishsense-database:/app/fishsense-database/fishsense_database | ||
ports: | ||
- "8000:8000" # fishsense-services port | ||
networks: | ||
- fishsense_network | ||
depends_on: | ||
- db | ||
- fishsense-database | ||
|
||
networks: | ||
fishsense_network: | ||
driver: bridge | ||
|
||
volumes: | ||
db: |
Submodule fishsense-database
updated
4 files
+1 −1 | README.md | |
+3 −3 | fishsense_database/database.py | |
+178 −1 | poetry.lock | |
+1 −0 | pyproject.toml |
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
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,76 @@ | ||
from fishsense_database.user import create_user, get_user, update_user, delete_user, get_all_users | ||
from fastapi import APIRouter, Request, HTTPException | ||
from fastapi.responses import JSONResponse | ||
from fastapi.encoders import jsonable_encoder | ||
|
||
usr_router = APIRouter() | ||
|
||
@usr_router.post("/create", status_code=200) | ||
async def create_usr(request: Request): | ||
|
||
data = await request.json() | ||
username = data["username"] | ||
email = data["email"] | ||
|
||
try: | ||
id = create_user(username, email) | ||
|
||
if not id: | ||
raise ValueError("User with this username or email already exists.") | ||
|
||
return JSONResponse( | ||
status_code=200, | ||
content={"message": "User created successfully."} | ||
) | ||
|
||
except ValueError as e: | ||
print(f"ValueError caught in FastAPI: {e}") # Log the error for debugging | ||
return JSONResponse( | ||
status_code=400, | ||
content={"detail": str(e)} # Send the error message as string | ||
) | ||
|
||
|
||
|
||
|
||
@usr_router.get("/user={username}", status_code=200) | ||
async def get_usr(username: str): | ||
|
||
try: | ||
if not username: | ||
raise ValueError("Must provide a username.") | ||
user = get_user(username) | ||
|
||
if not user: | ||
raise ValueError("User does not exist.") | ||
|
||
return JSONResponse( | ||
status_code=200, | ||
content={"user details": jsonable_encoder(user)} | ||
) | ||
|
||
except ValueError as e: | ||
|
||
return JSONResponse( | ||
status_code=400, | ||
content={"detail": str(e)} # Send the error message as string | ||
) | ||
|
||
@usr_router.get("/", status_code=200) | ||
async def all_usrs(): | ||
|
||
try: | ||
users = get_all_users() | ||
|
||
return JSONResponse( | ||
status_code=200, | ||
content={"users": jsonable_encoder(users)} | ||
) | ||
|
||
except ValueError as e: | ||
|
||
return JSONResponse( | ||
status_code=400, | ||
content={"detail": str(e)} # Send the error message as string | ||
) | ||
|
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