diff --git a/backend/alembic/env.py b/backend/alembic/env.py index 4770a9c..c9fe209 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -7,22 +7,15 @@ from sqlalchemy import pool from alembic import context +from core.database import Base # Import your Base + + # --- Add project root to sys.path --- # This assumes alembic/env.py is one level down from the project root (backend/) PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, PROJECT_DIR) # ----------------------------------- -# --- Import Base and Models --- -from core.database import Base # Import your Base -# Import all your models here so Base registers them -from modules.auth.models import User # Example: Import User model -from modules.calendar.models import CalendarEvent # Example: Import CalendarEvent model -from modules.nlp.models import ChatMessage # Import the new ChatMessage model -from modules.todo.models import Todo # Import the new Todo model -# Add imports for any other models you have -# ---------------------------- - # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config diff --git a/backend/alembic/versions/69069d6184b3_initial_migration_with_existing_tables.py b/backend/alembic/versions/69069d6184b3_initial_migration_with_existing_tables.py index c74bf5b..6dece1c 100644 --- a/backend/alembic/versions/69069d6184b3_initial_migration_with_existing_tables.py +++ b/backend/alembic/versions/69069d6184b3_initial_migration_with_existing_tables.py @@ -7,8 +7,6 @@ Create Date: 2025-04-21 01:14:33.233195 """ from typing import Sequence, Union -from alembic import op -import sqlalchemy as sa # revision identifiers, used by Alembic. diff --git a/backend/alembic/versions/9a82960db482_add_todo_table.py b/backend/alembic/versions/9a82960db482_add_todo_table.py index fea09ee..c264d75 100644 --- a/backend/alembic/versions/9a82960db482_add_todo_table.py +++ b/backend/alembic/versions/9a82960db482_add_todo_table.py @@ -7,8 +7,6 @@ Create Date: 2025-04-21 20:33:27.028529 """ from typing import Sequence, Union -from alembic import op -import sqlalchemy as sa # revision identifiers, used by Alembic. diff --git a/backend/core/__pycache__/config.cpython-312.pyc b/backend/core/__pycache__/config.cpython-312.pyc index 1ae3b10..fbfe8fd 100644 Binary files a/backend/core/__pycache__/config.cpython-312.pyc and b/backend/core/__pycache__/config.cpython-312.pyc differ diff --git a/backend/core/__pycache__/database.cpython-312.pyc b/backend/core/__pycache__/database.cpython-312.pyc index bd6580d..300d627 100644 Binary files a/backend/core/__pycache__/database.cpython-312.pyc and b/backend/core/__pycache__/database.cpython-312.pyc differ diff --git a/backend/core/config.py b/backend/core/config.py index 05f3642..c6b88b2 100644 --- a/backend/core/config.py +++ b/backend/core/config.py @@ -1,6 +1,5 @@ # core/config.py from pydantic_settings import BaseSettings -from pydantic import Field # Import Field for potential default values if needed import os DOTENV_PATH = os.path.join(os.path.dirname(__file__), "../.env") diff --git a/backend/core/database.py b/backend/core/database.py index 33c63f6..4897177 100644 --- a/backend/core/database.py +++ b/backend/core/database.py @@ -19,7 +19,7 @@ def get_engine(): _engine = create_engine(settings.DB_URL) try: _engine.connect() - except Exception as e: + except Exception: raise Exception("Database connection failed. Is the database server running?") Base.metadata.create_all(_engine) # Create tables here return _engine diff --git a/backend/main.py b/backend/main.py index 29719b3..5af39b7 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,7 +1,7 @@ # main.py from contextlib import _AsyncGeneratorContextManager, asynccontextmanager from typing import Any, Callable -from fastapi import FastAPI, Depends +from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from core.database import get_engine, Base from modules import router @@ -9,9 +9,6 @@ import logging # import all models to ensure they are registered before create_all -from modules.calendar.models import CalendarEvent -from modules.auth.models import User -from modules.todo.models import Todo # Import the new Todo model logging.getLogger('passlib').setLevel(logging.ERROR) # fix bc package logging is broken diff --git a/backend/modules/admin/__pycache__/api.cpython-312.pyc b/backend/modules/admin/__pycache__/api.cpython-312.pyc index 06c11ba..6207da4 100644 Binary files a/backend/modules/admin/__pycache__/api.cpython-312.pyc and b/backend/modules/admin/__pycache__/api.cpython-312.pyc differ diff --git a/backend/modules/admin/api.py b/backend/modules/admin/api.py index 63990fa..120ab82 100644 --- a/backend/modules/admin/api.py +++ b/backend/modules/admin/api.py @@ -1,10 +1,9 @@ # modules/admin/api.py from typing import Annotated -from fastapi import APIRouter, Depends, Body # Import Body +from fastapi import APIRouter, Depends # Import Body from pydantic import BaseModel # Import BaseModel from sqlalchemy.orm import Session -from core.database import Base, get_db -from modules.auth.models import User, UserRole +from core.database import get_db from modules.auth.dependencies import admin_only from .tasks import cleardb diff --git a/backend/modules/auth/__pycache__/api.cpython-312.pyc b/backend/modules/auth/__pycache__/api.cpython-312.pyc index edff5ae..b69dc64 100644 Binary files a/backend/modules/auth/__pycache__/api.cpython-312.pyc and b/backend/modules/auth/__pycache__/api.cpython-312.pyc differ diff --git a/backend/modules/auth/__pycache__/dependencies.cpython-312.pyc b/backend/modules/auth/__pycache__/dependencies.cpython-312.pyc index b6e718c..bce2297 100644 Binary files a/backend/modules/auth/__pycache__/dependencies.cpython-312.pyc and b/backend/modules/auth/__pycache__/dependencies.cpython-312.pyc differ diff --git a/backend/modules/auth/api.py b/backend/modules/auth/api.py index 696c8c6..d959e6b 100644 --- a/backend/modules/auth/api.py +++ b/backend/modules/auth/api.py @@ -1,5 +1,5 @@ # modules/auth/api.py -from fastapi import APIRouter, Cookie, Depends, HTTPException, status, Request, Response +from fastapi import APIRouter, Depends, HTTPException, status from fastapi.security import OAuth2PasswordRequestForm from jose import JWTError from modules.auth.models import User @@ -7,7 +7,7 @@ from modules.auth.schemas import UserCreate, UserResponse, Token, RefreshTokenRe from modules.auth.services import create_user from modules.auth.security import TokenType, get_current_user, oauth2_scheme, create_access_token, create_refresh_token, verify_token, authenticate_user, blacklist_tokens from sqlalchemy.orm import Session -from typing import Annotated, Optional +from typing import Annotated from core.database import get_db from datetime import timedelta from core.config import settings # Assuming settings is defined in core.config diff --git a/backend/modules/auth/dependencies.py b/backend/modules/auth/dependencies.py index ee42a7b..b8eb91c 100644 --- a/backend/modules/auth/dependencies.py +++ b/backend/modules/auth/dependencies.py @@ -1,5 +1,5 @@ # modules/auth/dependencies.py -from fastapi import Depends, HTTPException, status +from fastapi import Depends from modules.auth.security import get_current_user from modules.auth.schemas import UserRole from modules.auth.models import User diff --git a/backend/modules/calendar/__pycache__/api.cpython-312.pyc b/backend/modules/calendar/__pycache__/api.cpython-312.pyc index b276969..2c590a4 100644 Binary files a/backend/modules/calendar/__pycache__/api.cpython-312.pyc and b/backend/modules/calendar/__pycache__/api.cpython-312.pyc differ diff --git a/backend/modules/calendar/__pycache__/service.cpython-312.pyc b/backend/modules/calendar/__pycache__/service.cpython-312.pyc index 4b3a1bc..725eba9 100644 Binary files a/backend/modules/calendar/__pycache__/service.cpython-312.pyc and b/backend/modules/calendar/__pycache__/service.cpython-312.pyc differ diff --git a/backend/modules/calendar/api.py b/backend/modules/calendar/api.py index 81ecc15..fdf079c 100644 --- a/backend/modules/calendar/api.py +++ b/backend/modules/calendar/api.py @@ -5,7 +5,6 @@ from datetime import datetime from typing import List, Optional from modules.auth.dependencies import get_current_user from core.database import get_db -from core.exceptions import not_found_exception from modules.auth.models import User from modules.calendar.schemas import CalendarEventCreate, CalendarEventUpdate, CalendarEventResponse from modules.calendar.service import create_calendar_event, get_calendar_event_by_id, get_calendar_events, update_calendar_event, delete_calendar_event diff --git a/backend/modules/calendar/service.py b/backend/modules/calendar/service.py index 5b2c27f..d973aca 100644 --- a/backend/modules/calendar/service.py +++ b/backend/modules/calendar/service.py @@ -46,9 +46,9 @@ def get_calendar_events(db: Session, user_id: int, start: datetime | None, end: query = query.filter( or_( # Case 1: Event has duration and overlaps - (CalendarEvent.end != None) & (CalendarEvent.start < end) & (CalendarEvent.end > start), + (CalendarEvent.end is not None) & (CalendarEvent.start < end) & (CalendarEvent.end > start), # Case 2: Event is a point event within the range - (CalendarEvent.end == None) & (CalendarEvent.start >= start) & (CalendarEvent.start < end) + (CalendarEvent.end is None) & (CalendarEvent.start >= start) & (CalendarEvent.start < end) ) ) # If only start is provided, filter events starting on or after start @@ -63,9 +63,9 @@ def get_calendar_events(db: Session, user_id: int, start: datetime | None, end: query = query.filter( or_( # Event ends before the specified end time - (CalendarEvent.end != None) & (CalendarEvent.end <= end), + (CalendarEvent.end is not None) & (CalendarEvent.end <= end), # Point event occurs before the specified end time - (CalendarEvent.end == None) & (CalendarEvent.start < end) + (CalendarEvent.end is None) & (CalendarEvent.start < end) ) ) # Alternative interpretation for "ending before end": include events that *start* before end diff --git a/backend/modules/nlp/__pycache__/api.cpython-312.pyc b/backend/modules/nlp/__pycache__/api.cpython-312.pyc index 054df8c..b18dfb9 100644 Binary files a/backend/modules/nlp/__pycache__/api.cpython-312.pyc and b/backend/modules/nlp/__pycache__/api.cpython-312.pyc differ diff --git a/backend/modules/nlp/__pycache__/models.cpython-312.pyc b/backend/modules/nlp/__pycache__/models.cpython-312.pyc index 9536465..4eebfa5 100644 Binary files a/backend/modules/nlp/__pycache__/models.cpython-312.pyc and b/backend/modules/nlp/__pycache__/models.cpython-312.pyc differ diff --git a/backend/modules/nlp/api.py b/backend/modules/nlp/api.py index 8f0587c..14e3b8a 100644 --- a/backend/modules/nlp/api.py +++ b/backend/modules/nlp/api.py @@ -11,7 +11,6 @@ from modules.auth.models import User from modules.nlp.service import process_request, ask_ai, save_chat_message, get_chat_history, MessageSender # Import the response schema and the new ChatMessage model for response type hinting from modules.nlp.schemas import ProcessCommandRequest, ProcessCommandResponse -from modules.nlp.models import ChatMessage # Import ChatMessage model from modules.calendar.service import create_calendar_event, get_calendar_events, update_calendar_event, delete_calendar_event from modules.calendar.models import CalendarEvent from modules.calendar.schemas import CalendarEventCreate, CalendarEventUpdate @@ -19,7 +18,18 @@ from modules.calendar.schemas import CalendarEventCreate, CalendarEventUpdate from modules.todo import service as todo_service from modules.todo.models import Todo from modules.todo.schemas import TodoCreate, TodoUpdate +from pydantic import BaseModel +from datetime import datetime +class ChatMessageResponse(BaseModel): + id: int + sender: MessageSender # Use the enum directly + text: str + timestamp: datetime + + class Config: + from_attributes = True # Allow Pydantic to work with ORM models + router = APIRouter(prefix="/nlp", tags=["nlp"]) # Helper to format calendar events (expects list of CalendarEvent models) @@ -217,20 +227,6 @@ def process_command(request_data: ProcessCommandRequest, current_user: User = De # ---------------------------------- return ProcessCommandResponse(responses=[error_response]) -# --- New Endpoint for Chat History --- -# Define a Pydantic schema for the response (optional but good practice) -from pydantic import BaseModel -from datetime import datetime - -class ChatMessageResponse(BaseModel): - id: int - sender: MessageSender # Use the enum directly - text: str - timestamp: datetime - - class Config: - from_attributes = True # Allow Pydantic to work with ORM models - @router.get("/history", response_model=List[ChatMessageResponse]) def read_chat_history(current_user: User = Depends(get_current_user), db: Session = Depends(get_db)): """Retrieves the last 50 chat messages for the current user.""" diff --git a/backend/modules/nlp/models.py b/backend/modules/nlp/models.py index b92a1bc..ddeba47 100644 --- a/backend/modules/nlp/models.py +++ b/backend/modules/nlp/models.py @@ -1,6 +1,6 @@ \ # /home/cdp/code/MAIA/backend/modules/nlp/models.py -from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, Enum as SQLEnum +from sqlalchemy import Column, Integer, Text, DateTime, ForeignKey, Enum as SQLEnum from sqlalchemy.orm import relationship from sqlalchemy.sql import func import enum diff --git a/backend/modules/todo/__pycache__/models.cpython-312.pyc b/backend/modules/todo/__pycache__/models.cpython-312.pyc index 32eb8e9..54ad666 100644 Binary files a/backend/modules/todo/__pycache__/models.cpython-312.pyc and b/backend/modules/todo/__pycache__/models.cpython-312.pyc differ diff --git a/backend/modules/todo/models.py b/backend/modules/todo/models.py index 2b09fdd..dc702b5 100644 --- a/backend/modules/todo/models.py +++ b/backend/modules/todo/models.py @@ -2,7 +2,6 @@ from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey from sqlalchemy.orm import relationship from core.database import Base -import datetime class Todo(Base): __tablename__ = "todos" diff --git a/backend/modules/user/__pycache__/api.cpython-312.pyc b/backend/modules/user/__pycache__/api.cpython-312.pyc index 73019e3..8b37d05 100644 Binary files a/backend/modules/user/__pycache__/api.cpython-312.pyc and b/backend/modules/user/__pycache__/api.cpython-312.pyc differ diff --git a/backend/modules/user/api.py b/backend/modules/user/api.py index 964b891..1804394 100644 --- a/backend/modules/user/api.py +++ b/backend/modules/user/api.py @@ -4,7 +4,7 @@ from fastapi import APIRouter, Depends from sqlalchemy.orm import Session from core.database import get_db -from core.exceptions import unauthorized_exception, not_found_exception, forbidden_exception +from core.exceptions import not_found_exception, forbidden_exception from modules.auth.schemas import UserPatch, UserResponse from modules.auth.dependencies import get_current_user from modules.auth.models import User diff --git a/backend/tests/__pycache__/test_admin.cpython-312-pytest-8.3.5.pyc b/backend/tests/__pycache__/test_admin.cpython-312-pytest-8.3.5.pyc index c7f94ca..04cfef1 100644 Binary files a/backend/tests/__pycache__/test_admin.cpython-312-pytest-8.3.5.pyc and b/backend/tests/__pycache__/test_admin.cpython-312-pytest-8.3.5.pyc differ diff --git a/backend/tests/__pycache__/test_calendar.cpython-312-pytest-8.3.5.pyc b/backend/tests/__pycache__/test_calendar.cpython-312-pytest-8.3.5.pyc index c5e6041..fa50012 100644 Binary files a/backend/tests/__pycache__/test_calendar.cpython-312-pytest-8.3.5.pyc and b/backend/tests/__pycache__/test_calendar.cpython-312-pytest-8.3.5.pyc differ diff --git a/backend/tests/__pycache__/test_main.cpython-312-pytest-8.3.5.pyc b/backend/tests/__pycache__/test_main.cpython-312-pytest-8.3.5.pyc index 57e4dd2..06dff4a 100644 Binary files a/backend/tests/__pycache__/test_main.cpython-312-pytest-8.3.5.pyc and b/backend/tests/__pycache__/test_main.cpython-312-pytest-8.3.5.pyc differ diff --git a/backend/tests/__pycache__/test_nlp.cpython-312-pytest-8.3.5.pyc b/backend/tests/__pycache__/test_nlp.cpython-312-pytest-8.3.5.pyc index 454d395..b0d485d 100644 Binary files a/backend/tests/__pycache__/test_nlp.cpython-312-pytest-8.3.5.pyc and b/backend/tests/__pycache__/test_nlp.cpython-312-pytest-8.3.5.pyc differ diff --git a/backend/tests/__pycache__/test_todo.cpython-312-pytest-8.3.5.pyc b/backend/tests/__pycache__/test_todo.cpython-312-pytest-8.3.5.pyc index c7a6b6e..32d3066 100644 Binary files a/backend/tests/__pycache__/test_todo.cpython-312-pytest-8.3.5.pyc and b/backend/tests/__pycache__/test_todo.cpython-312-pytest-8.3.5.pyc differ diff --git a/backend/tests/test_admin.py b/backend/tests/test_admin.py index 3885fd2..3dc906a 100644 --- a/backend/tests/test_admin.py +++ b/backend/tests/test_admin.py @@ -1,11 +1,9 @@ -import pytest from fastapi import status from fastapi.testclient import TestClient from sqlalchemy.orm import Session from unittest.mock import patch from tests.helpers import generators -from modules.auth.models import UserRole # Test admin routes require admin privileges diff --git a/backend/tests/test_calendar.py b/backend/tests/test_calendar.py index da0eec6..5e250d9 100644 --- a/backend/tests/test_calendar.py +++ b/backend/tests/test_calendar.py @@ -1,4 +1,3 @@ -import pytest from fastapi import status from fastapi.testclient import TestClient from sqlalchemy.orm import Session diff --git a/backend/tests/test_main.py b/backend/tests/test_main.py index 2401a93..22c5cf6 100644 --- a/backend/tests/test_main.py +++ b/backend/tests/test_main.py @@ -1,4 +1,3 @@ -import pytest from fastapi.testclient import TestClient # No database needed for this simple test diff --git a/backend/tests/test_nlp.py b/backend/tests/test_nlp.py index 28f39e3..ab770fd 100644 --- a/backend/tests/test_nlp.py +++ b/backend/tests/test_nlp.py @@ -6,7 +6,7 @@ from unittest.mock import patch, MagicMock from datetime import datetime from tests.helpers import generators -from modules.nlp.schemas import ProcessCommandRequest, ProcessCommandResponse +from modules.nlp.schemas import ProcessCommandResponse from modules.nlp.models import MessageSender, ChatMessage # Import necessary models/enums # --- Mocks --- diff --git a/backend/tests/test_todo.py b/backend/tests/test_todo.py index 573ea76..7497a57 100644 --- a/backend/tests/test_todo.py +++ b/backend/tests/test_todo.py @@ -1,11 +1,9 @@ -import pytest from fastapi import status from fastapi.testclient import TestClient from sqlalchemy.orm import Session from datetime import date from tests.helpers import generators -from modules.todo import schemas # Import schemas # Helper Function def _login_user(db: Session, client: TestClient):