diff --git a/backend/app/api/routes/organization.py b/backend/app/api/routes/organization.py index 099494ee5..29f6f62aa 100644 --- a/backend/app/api/routes/organization.py +++ b/backend/app/api/routes/organization.py @@ -1,3 +1,4 @@ +import logging from typing import Any, List from fastapi import APIRouter, Depends, HTTPException @@ -18,6 +19,7 @@ from app.crud.organization import create_organization, get_organization_by_id from app.utils import APIResponse +logger = logging.getLogger(__name__) router = APIRouter(prefix="/organizations", tags=["organizations"]) @@ -59,6 +61,7 @@ def read_organization(*, session: SessionDep, org_id: int): """ org = get_organization_by_id(session=session, org_id=org_id) if org is None: + logger.error(f"[read_organization] Organization not found | org_id={org_id}") raise HTTPException(status_code=404, detail="Organization not found") return APIResponse.success_response(org) @@ -74,6 +77,9 @@ def update_organization( ): org = get_organization_by_id(session=session, org_id=org_id) if org is None: + logger.error( + f"[update_organization] Organization not found | 'org_id': {org_id}" + ) raise HTTPException(status_code=404, detail="Organization not found") org_data = org_in.model_dump(exclude_unset=True) @@ -82,7 +88,9 @@ def update_organization( session.add(org) session.commit() session.flush() - + logger.info( + f"[update_organization] Organization Updated Successfully | 'org_id': {org.id}" + ) return APIResponse.success_response(org) @@ -96,9 +104,14 @@ def update_organization( def delete_organization(session: SessionDep, org_id: int): org = get_organization_by_id(session=session, org_id=org_id) if org is None: + logger.error( + f"[delete_organization] Organization not found | 'org_id': {org_id}" + ) raise HTTPException(status_code=404, detail="Organization not found") session.delete(org) session.commit() - + logger.info( + f"[delete_organization] Organization Deleted Successfully | 'org_id': {org_id}" + ) return APIResponse.success_response(None) diff --git a/backend/app/api/routes/project.py b/backend/app/api/routes/project.py index d50918abe..7be763a75 100644 --- a/backend/app/api/routes/project.py +++ b/backend/app/api/routes/project.py @@ -1,3 +1,4 @@ +import logging from typing import Any, List from fastapi import APIRouter, Depends, HTTPException, Query @@ -6,17 +7,16 @@ from app.models import Project, ProjectCreate, ProjectUpdate, ProjectPublic from app.api.deps import ( - CurrentUser, SessionDep, get_current_active_superuser, ) from app.crud.project import ( create_project, get_project_by_id, - get_projects_by_organization, ) from app.utils import APIResponse +logger = logging.getLogger(__name__) router = APIRouter(prefix="/projects", tags=["projects"]) @@ -62,6 +62,7 @@ def read_project(*, session: SessionDep, project_id: int): """ project = get_project_by_id(session=session, project_id=project_id) if project is None: + logger.error(f"[read_project] Project not found | project_id={project_id}") raise HTTPException(status_code=404, detail="Project not found") return APIResponse.success_response(project) @@ -75,6 +76,7 @@ def read_project(*, session: SessionDep, project_id: int): def update_project(*, session: SessionDep, project_id: int, project_in: ProjectUpdate): project = get_project_by_id(session=session, project_id=project_id) if project is None: + logger.error(f"[update_project] Project not found | project_id={project_id}") raise HTTPException(status_code=404, detail="Project not found") project_data = project_in.model_dump(exclude_unset=True) @@ -83,6 +85,9 @@ def update_project(*, session: SessionDep, project_id: int, project_in: ProjectU session.add(project) session.commit() session.flush() + logger.info( + f"[update_project] Project updated successfully | project_id={project.id}" + ) return APIResponse.success_response(project) @@ -95,9 +100,12 @@ def update_project(*, session: SessionDep, project_id: int, project_in: ProjectU def delete_project(session: SessionDep, project_id: int): project = get_project_by_id(session=session, project_id=project_id) if project is None: + logger.error(f"[delete_project] Project not found | project_id={project_id}") raise HTTPException(status_code=404, detail="Project not found") session.delete(project) session.commit() - + logger.info( + f"[delete_project] Project deleted successfully | project_id={project_id}" + ) return APIResponse.success_response(None) diff --git a/backend/app/crud/organization.py b/backend/app/crud/organization.py index 598311c34..a95c843b6 100644 --- a/backend/app/crud/organization.py +++ b/backend/app/crud/organization.py @@ -1,3 +1,4 @@ +import logging from typing import Any, Optional from datetime import datetime, timezone from sqlmodel import Session, select @@ -6,6 +7,8 @@ from app.models import Organization, OrganizationCreate from app.core.util import now +logger = logging.getLogger(__name__) + def create_organization( *, session: Session, org_create: OrganizationCreate @@ -16,6 +19,9 @@ def create_organization( session.add(db_org) session.commit() session.refresh(db_org) + logger.info( + f"[create_organization] Organization Created Successfully | 'org_id': {db_org.id}, 'name': {db_org.name}" + ) return db_org @@ -37,9 +43,15 @@ def validate_organization(session: Session, org_id: int) -> Organization: """ organization = get_organization_by_id(session, org_id) if not organization: + logger.error( + f"[validate_organization] Organization not found | 'org_id': {org_id}" + ) raise HTTPException(404, "Organization not found") if not organization.is_active: + logger.error( + f"[validate_organization] Organization is not active | 'org_id': {org_id}" + ) raise HTTPException("Organization is not active") return organization diff --git a/backend/app/crud/project.py b/backend/app/crud/project.py index f64ee7816..31bdb845c 100644 --- a/backend/app/crud/project.py +++ b/backend/app/crud/project.py @@ -1,3 +1,4 @@ +import logging from typing import List, Optional from datetime import datetime, timezone from sqlmodel import Session, select @@ -6,6 +7,8 @@ from app.models import Project, ProjectCreate, Organization from app.core.util import now +logger = logging.getLogger(__name__) + def create_project(*, session: Session, project_create: ProjectCreate) -> Project: db_project = Project.model_validate(project_create) @@ -14,6 +17,9 @@ def create_project(*, session: Session, project_create: ProjectCreate) -> Projec session.add(db_project) session.commit() session.refresh(db_project) + logger.info( + f"[create_project] Project Created Successfully | 'project_id': {db_project.id}, 'name': {db_project.name}" + ) return db_project @@ -33,9 +39,15 @@ def validate_project(session: Session, project_id: int) -> Project: """ project = get_project_by_id(session=session, project_id=project_id) if not project: + logger.error( + f"[validate_project] Project not found | 'project_id': {project_id}" + ) raise HTTPException(404, "Project not found") if not project.is_active: + logger.error( + f"[validate_project] Project is not active | 'project_id': {project_id}" + ) raise HTTPException(404, "Project is not active") return project