fixed linting issues
This commit is contained in:
@@ -7,22 +7,15 @@ from sqlalchemy import pool
|
|||||||
|
|
||||||
from alembic import context
|
from alembic import context
|
||||||
|
|
||||||
|
from core.database import Base # Import your Base
|
||||||
|
|
||||||
|
|
||||||
# --- Add project root to sys.path ---
|
# --- Add project root to sys.path ---
|
||||||
# This assumes alembic/env.py is one level down from the project root (backend/)
|
# 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__)))
|
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
sys.path.insert(0, PROJECT_DIR)
|
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
|
# this is the Alembic Config object, which provides
|
||||||
# access to the values within the .ini file in use.
|
# access to the values within the .ini file in use.
|
||||||
config = context.config
|
config = context.config
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ Create Date: 2025-04-21 01:14:33.233195
|
|||||||
"""
|
"""
|
||||||
from typing import Sequence, Union
|
from typing import Sequence, Union
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ Create Date: 2025-04-21 20:33:27.028529
|
|||||||
"""
|
"""
|
||||||
from typing import Sequence, Union
|
from typing import Sequence, Union
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,5 @@
|
|||||||
# core/config.py
|
# core/config.py
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
from pydantic import Field # Import Field for potential default values if needed
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
DOTENV_PATH = os.path.join(os.path.dirname(__file__), "../.env")
|
DOTENV_PATH = os.path.join(os.path.dirname(__file__), "../.env")
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ def get_engine():
|
|||||||
_engine = create_engine(settings.DB_URL)
|
_engine = create_engine(settings.DB_URL)
|
||||||
try:
|
try:
|
||||||
_engine.connect()
|
_engine.connect()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
raise Exception("Database connection failed. Is the database server running?")
|
raise Exception("Database connection failed. Is the database server running?")
|
||||||
Base.metadata.create_all(_engine) # Create tables here
|
Base.metadata.create_all(_engine) # Create tables here
|
||||||
return _engine
|
return _engine
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# main.py
|
# main.py
|
||||||
from contextlib import _AsyncGeneratorContextManager, asynccontextmanager
|
from contextlib import _AsyncGeneratorContextManager, asynccontextmanager
|
||||||
from typing import Any, Callable
|
from typing import Any, Callable
|
||||||
from fastapi import FastAPI, Depends
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from core.database import get_engine, Base
|
from core.database import get_engine, Base
|
||||||
from modules import router
|
from modules import router
|
||||||
@@ -9,9 +9,6 @@ import logging
|
|||||||
|
|
||||||
|
|
||||||
# import all models to ensure they are registered before create_all
|
# 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
|
logging.getLogger('passlib').setLevel(logging.ERROR) # fix bc package logging is broken
|
||||||
|
|||||||
Binary file not shown.
@@ -1,10 +1,9 @@
|
|||||||
# modules/admin/api.py
|
# modules/admin/api.py
|
||||||
from typing import Annotated
|
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 pydantic import BaseModel # Import BaseModel
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from core.database import Base, get_db
|
from core.database import get_db
|
||||||
from modules.auth.models import User, UserRole
|
|
||||||
from modules.auth.dependencies import admin_only
|
from modules.auth.dependencies import admin_only
|
||||||
from .tasks import cleardb
|
from .tasks import cleardb
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
# modules/auth/api.py
|
# 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 fastapi.security import OAuth2PasswordRequestForm
|
||||||
from jose import JWTError
|
from jose import JWTError
|
||||||
from modules.auth.models import User
|
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.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 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 sqlalchemy.orm import Session
|
||||||
from typing import Annotated, Optional
|
from typing import Annotated
|
||||||
from core.database import get_db
|
from core.database import get_db
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from core.config import settings # Assuming settings is defined in core.config
|
from core.config import settings # Assuming settings is defined in core.config
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# modules/auth/dependencies.py
|
# 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.security import get_current_user
|
||||||
from modules.auth.schemas import UserRole
|
from modules.auth.schemas import UserRole
|
||||||
from modules.auth.models import User
|
from modules.auth.models import User
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -5,7 +5,6 @@ from datetime import datetime
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from modules.auth.dependencies import get_current_user
|
from modules.auth.dependencies import get_current_user
|
||||||
from core.database import get_db
|
from core.database import get_db
|
||||||
from core.exceptions import not_found_exception
|
|
||||||
from modules.auth.models import User
|
from modules.auth.models import User
|
||||||
from modules.calendar.schemas import CalendarEventCreate, CalendarEventUpdate, CalendarEventResponse
|
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
|
from modules.calendar.service import create_calendar_event, get_calendar_event_by_id, get_calendar_events, update_calendar_event, delete_calendar_event
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ def get_calendar_events(db: Session, user_id: int, start: datetime | None, end:
|
|||||||
query = query.filter(
|
query = query.filter(
|
||||||
or_(
|
or_(
|
||||||
# Case 1: Event has duration and overlaps
|
# 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
|
# 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
|
# 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(
|
query = query.filter(
|
||||||
or_(
|
or_(
|
||||||
# Event ends before the specified end time
|
# 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
|
# 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
|
# Alternative interpretation for "ending before end": include events that *start* before end
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -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
|
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
|
# Import the response schema and the new ChatMessage model for response type hinting
|
||||||
from modules.nlp.schemas import ProcessCommandRequest, ProcessCommandResponse
|
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.service import create_calendar_event, get_calendar_events, update_calendar_event, delete_calendar_event
|
||||||
from modules.calendar.models import CalendarEvent
|
from modules.calendar.models import CalendarEvent
|
||||||
from modules.calendar.schemas import CalendarEventCreate, CalendarEventUpdate
|
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 import service as todo_service
|
||||||
from modules.todo.models import Todo
|
from modules.todo.models import Todo
|
||||||
from modules.todo.schemas import TodoCreate, TodoUpdate
|
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"])
|
router = APIRouter(prefix="/nlp", tags=["nlp"])
|
||||||
|
|
||||||
# Helper to format calendar events (expects list of CalendarEvent models)
|
# 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])
|
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])
|
@router.get("/history", response_model=List[ChatMessageResponse])
|
||||||
def read_chat_history(current_user: User = Depends(get_current_user), db: Session = Depends(get_db)):
|
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."""
|
"""Retrieves the last 50 chat messages for the current user."""
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
\
|
\
|
||||||
# /home/cdp/code/MAIA/backend/modules/nlp/models.py
|
# /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.orm import relationship
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
import enum
|
import enum
|
||||||
|
|||||||
Binary file not shown.
@@ -2,7 +2,6 @@
|
|||||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey
|
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from core.database import Base
|
from core.database import Base
|
||||||
import datetime
|
|
||||||
|
|
||||||
class Todo(Base):
|
class Todo(Base):
|
||||||
__tablename__ = "todos"
|
__tablename__ = "todos"
|
||||||
|
|||||||
Binary file not shown.
@@ -4,7 +4,7 @@ from fastapi import APIRouter, Depends
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from core.database import get_db
|
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.schemas import UserPatch, UserResponse
|
||||||
from modules.auth.dependencies import get_current_user
|
from modules.auth.dependencies import get_current_user
|
||||||
from modules.auth.models import User
|
from modules.auth.models import User
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,11 +1,9 @@
|
|||||||
import pytest
|
|
||||||
from fastapi import status
|
from fastapi import status
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from tests.helpers import generators
|
from tests.helpers import generators
|
||||||
from modules.auth.models import UserRole
|
|
||||||
|
|
||||||
# Test admin routes require admin privileges
|
# Test admin routes require admin privileges
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import pytest
|
|
||||||
from fastapi import status
|
from fastapi import status
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import pytest
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
# No database needed for this simple test
|
# No database needed for this simple test
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from unittest.mock import patch, MagicMock
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from tests.helpers import generators
|
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
|
from modules.nlp.models import MessageSender, ChatMessage # Import necessary models/enums
|
||||||
|
|
||||||
# --- Mocks ---
|
# --- Mocks ---
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import pytest
|
|
||||||
from fastapi import status
|
from fastapi import status
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from tests.helpers import generators
|
from tests.helpers import generators
|
||||||
from modules.todo import schemas # Import schemas
|
|
||||||
|
|
||||||
# Helper Function
|
# Helper Function
|
||||||
def _login_user(db: Session, client: TestClient):
|
def _login_user(db: Session, client: TestClient):
|
||||||
|
|||||||
Reference in New Issue
Block a user