diff --git a/app/database/chroma_db.py b/app/database/chroma_db.py index d474f1e..0abe634 100644 --- a/app/database/chroma_db.py +++ b/app/database/chroma_db.py @@ -10,7 +10,7 @@ import os import datetime from dotenv import load_dotenv -from app.dto.db_dto import AddScheduleDTO, RecommendationMainRequestDTO, ReportTagsRequestDTO +from app.dto.db_dto import AddScheduleDTO, DeleteScheduleDTO, RecommendationMainRequestDTO, ReportTagsRequestDTO load_dotenv() CHROMA_DB_IP_ADDRESS = os.getenv("CHROMA_DB_IP_ADDRESS") @@ -61,6 +61,15 @@ async def add_db_data(schedule_data: AddScheduleDTO): return True # 메인페이지 한 줄 추천 기능에 사용하는 함수 +async def delete_db_data(schedule_data: DeleteScheduleDTO): + member_id = schedule_data.member_id + schedule_id = schedule_data.schedule_id + schedules.delete( + ids=[str(schedule_id)], + where={"member": {"$eq": int(member_id)}} + ) + return True + # 유저의 id, 해당 날짜로 필터링 async def db_daily_schedule(user_data: RecommendationMainRequestDTO): member = user_data.member_id diff --git a/app/dto/db_dto.py b/app/dto/db_dto.py index 8be0800..5d84981 100644 --- a/app/dto/db_dto.py +++ b/app/dto/db_dto.py @@ -11,6 +11,10 @@ class AddScheduleDTO(BaseModel): location: str person: str +class DeleteScheduleDTO(BaseModel): + schedule_id: int + member_id: int + class RecommendationMainRequestDTO(BaseModel): member_id: int user_persona: str diff --git a/app/routers/chromadb.py b/app/routers/chromadb.py index 99ce84a..f204b95 100644 --- a/app/routers/chromadb.py +++ b/app/routers/chromadb.py @@ -4,8 +4,8 @@ from dotenv import load_dotenv from fastapi import APIRouter, HTTPException, Depends, status -from app.dto.db_dto import AddScheduleDTO -from app.database.chroma_db import add_db_data, get_chroma_client +from app.dto.db_dto import AddScheduleDTO, DeleteScheduleDTO +from app.database.chroma_db import add_db_data, delete_db_data, get_chroma_client router = APIRouter( prefix="/chromadb", @@ -30,3 +30,12 @@ async def add_schedule_endpoint(schedule_data: AddScheduleDTO, chroma_client=Dep return {"message": "Schedule added successfully"} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) + +@router.post("/delete_schedule", status_code=status.HTTP_204_NO_CONTENT) +async def delete_schedule_endpoint(schedule_data: DeleteScheduleDTO, chroma_client=Depends(get_chroma_client)): + try: + # 직접 `add_db_data` 함수를 비동기적으로 호출합니다. + await delete_db_data(schedule_data) + return {"message": "Schedule delete successfully"} + except Exception as e: + raise HTTPException(status_code=500, detail=str(e))