Skip to content

Commit

Permalink
feat: add mongo db data
Browse files Browse the repository at this point in the history
  • Loading branch information
gunh0 committed Aug 19, 2023
1 parent 1377cc6 commit 3f15f7c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

__pycache__
venv

mongo-data
6 changes: 6 additions & 0 deletions database/connection.py
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 13 additions & 13 deletions docker-compose.db.yml
Original file line number Diff line number Diff line change
@@ -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:
mongo-data:
16 changes: 16 additions & 0 deletions routers/waste_management.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 3f15f7c

Please sign in to comment.