fixed linting issues

This commit is contained in:
c-d-p
2025-04-23 00:57:31 +02:00
parent be00f021ba
commit d5d0a24403
36 changed files with 28 additions and 56 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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")

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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,6 +18,17 @@ 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"])
@@ -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."""

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,3 @@
import pytest
from fastapi import status
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session

View File

@@ -1,4 +1,3 @@
import pytest
from fastapi.testclient import TestClient
# No database needed for this simple test

View File

@@ -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 ---

View File

@@ -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):