initial_commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import Session as DBSession
|
||||
|
||||
from app.db.database import get_db
|
||||
from app.db.models import Memory
|
||||
|
||||
router = APIRouter(prefix="/memory", tags=["memory"])
|
||||
|
||||
|
||||
class MemoryResponse(BaseModel):
|
||||
id: int
|
||||
session_id: str
|
||||
summary: str
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
@router.get("/{session_id}", response_model=list[MemoryResponse])
|
||||
def get_memories(session_id: str, db: DBSession = Depends(get_db)):
|
||||
return db.query(Memory).filter(Memory.session_id == session_id).order_by(Memory.created_at).all()
|
||||
|
||||
|
||||
@router.delete("/{memory_id}", status_code=204)
|
||||
def delete_memory(memory_id: int, db: DBSession = Depends(get_db)):
|
||||
memory = db.get(Memory, memory_id)
|
||||
if not memory:
|
||||
raise HTTPException(status_code=404, detail="Memory not found")
|
||||
db.delete(memory)
|
||||
db.commit()
|
||||
Reference in New Issue
Block a user