diff --git a/app/database/chroma_db.py b/app/database/chroma_db.py index 0abe634..677854a 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, DeleteScheduleDTO, RecommendationMainRequestDTO, ReportTagsRequestDTO +from app.dto.db_dto import AddScheduleDTO, DeleteScheduleDTO, UpdateScheduleDTO, RecommendationMainRequestDTO, ReportTagsRequestDTO load_dotenv() CHROMA_DB_IP_ADDRESS = os.getenv("CHROMA_DB_IP_ADDRESS") @@ -70,6 +70,31 @@ async def delete_db_data(schedule_data: DeleteScheduleDTO): ) return True +# 데이터베이스 업데이트 함수 정의 +async def update_db_data(schedule_data: UpdateScheduleDTO): + schedule_date = schedule_data.schedule_datetime_start.split("T")[0] + year = int(schedule_date.split("-")[0]) + month = int(schedule_date.split("-")[1]) + date = int(schedule_date.split("-")[2]) + + # 기존 스케줄 업데이트 로직 + schedules.update( + documents=[schedule_data.data], + ids=[str(schedule_data.schedule_id)], + metadatas=[{ + "year": year, + "month": month, + "date": date, + "datetime_start": schedule_data.schedule_datetime_start, + "datetime_end": schedule_data.schedule_datetime_end, + "member": schedule_data.member_id, + "category": schedule_data.category, + "location": schedule_data.location, + "person": schedule_data.person + }] + ) + 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 5d84981..cac7dc9 100644 --- a/app/dto/db_dto.py +++ b/app/dto/db_dto.py @@ -7,7 +7,7 @@ class AddScheduleDTO(BaseModel): schedule_datetime_end: str schedule_id: int member_id: int - category: int + category: str location: str person: str @@ -15,6 +15,16 @@ class DeleteScheduleDTO(BaseModel): schedule_id: int member_id: int +class UpdateScheduleDTO(BaseModel): + data: str + schedule_datetime_start: str + schedule_datetime_end: str + schedule_id: int + member_id: int + category: str + location: str + person: str + class RecommendationMainRequestDTO(BaseModel): member_id: int user_persona: str diff --git a/app/routers/chromadb.py b/app/routers/chromadb.py index 4fd8775..6bca24f 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, DeleteScheduleDTO -from app.database.chroma_db import add_db_data, delete_db_data, get_chroma_client +from app.dto.db_dto import AddScheduleDTO, DeleteScheduleDTO, UpdateScheduleDTO +from app.database.chroma_db import add_db_data, delete_db_data, update_db_data, get_chroma_client router = APIRouter( prefix="/chromadb", @@ -41,11 +41,11 @@ async def delete_schedule_endpoint(schedule_data: DeleteScheduleDTO, chroma_clie raise HTTPException(status_code=500, detail=str(e)) -@router.delete("/delete_schedule", status_code=status.HTTP_204_NO_CONTENT) -async def delete_schedule_endpoint(schedule_data: DeleteScheduleDTO, chroma_client=Depends(get_chroma_client)): +@router.put("/update_schedule", status_code=status.HTTP_200_OK) +async def update_schedule_endpoint(schedule_data: UpdateScheduleDTO, chroma_client=Depends(get_chroma_client)): try: - # 직접 `add_db_data` 함수를 비동기적으로 호출합니다. - await delete_db_data(schedule_data) - return {"message": "Schedule delete successfully"} + # 데이터베이스 업데이트 함수 호출 + await update_db_data(schedule_data) + return {"message": "Schedule updated successfully"} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) \ No newline at end of file