Skip to content

Commit

Permalink
feat: merge to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakul Bhandare authored and Nakul Bhandare committed Feb 19, 2025
2 parents 0b07823 + 92feebe commit 1e8112a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion backend/controller/plant_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@
from services.plant_service import get_service, PlantService
from fastapi import Depends
from fastapi.responses import JSONResponse
from fastapi.security import HTTPBasic, HTTPBasicCredentials



create_plant = APIRouter()

security = HTTPBasic()

user = {
"admin": "admin",
"user": "admin"
}

def verify_credentials(credentials: HTTPBasicCredentials = Depends(security)):
username = credentials.username
password = credentials.password
if user.get(username) != password:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid credentials",
headers={"WWW-Authenticate": "Basic"},
)
return username


@create_plant.post("/api/plant/data", response_model=PlantSchema)
def create_plant_entry(plant: PlantSchema, service: PlantService = Depends(get_service)):
def create_plant_entry(plant: PlantSchema, service: PlantService = Depends(get_service), username: str = Depends(verify_credentials)):
try:
# Call the service layer to create the plant
response = service.create_plant(plant)
Expand Down

0 comments on commit 1e8112a

Please sign in to comment.