diff --git a/.gitignore b/.gitignore index a2e8876..b28675e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ __pycache__ venv + +mongo-data diff --git a/database/connection.py b/database/connection.py new file mode 100644 index 0000000..2446b7b --- /dev/null +++ b/database/connection.py @@ -0,0 +1,6 @@ +from pymongo import MongoClient +import os + +MONGODB_URI = os.getenv("MONGODB_URI") +client = MongoClient(MONGODB_URI) +db = client.get_default_database() diff --git a/docker-compose.db.yml b/docker-compose.db.yml index a1a6337..519882c 100644 --- a/docker-compose.db.yml +++ b/docker-compose.db.yml @@ -1,17 +1,17 @@ -version: '3.8' +version: "3" services: - mongo: - image: mongo:7.0.0 - container_name: mongodb_container - restart: always - environment: - MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME} - MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} - ports: - - "27017:27017" - volumes: - - mongo-data:/data/db + mongo: + image: mongo:7.0.0 + container_name: mongodb_container + restart: always + environment: + MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME} + MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} + ports: + - "27017:27017" + volumes: + - ./mongo-data:/data/db volumes: - mongo-data: \ No newline at end of file + mongo-data: diff --git a/routers/waste_management.py b/routers/waste_management.py new file mode 100644 index 0000000..1413aec --- /dev/null +++ b/routers/waste_management.py @@ -0,0 +1,16 @@ +from fastapi import APIRouter +from ..database.connection import db + +router = APIRouter() + + +class WasteItem(BaseModel): + name: str + description: str + disposal_method: str + + +@router.get("/wastes/", response_model=List[WasteItem]) +async def get_waste_items(): + waste_items = db.wastes.find() + return list(waste_items)