From 3cad2ebef2bdfb5f8d630400c979ff065a762189 Mon Sep 17 00:00:00 2001 From: uommou Date: Sat, 25 May 2024 20:53:43 +0900 Subject: [PATCH 1/2] fix: delete schedule --- app/routers/chromadb.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/routers/chromadb.py b/app/routers/chromadb.py index f204b95..4fd8775 100644 --- a/app/routers/chromadb.py +++ b/app/routers/chromadb.py @@ -31,7 +31,7 @@ async def add_schedule_endpoint(schedule_data: AddScheduleDTO, chroma_client=Dep except Exception as e: raise HTTPException(status_code=500, detail=str(e)) -@router.post("/delete_schedule", status_code=status.HTTP_204_NO_CONTENT) +@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)): try: # 직접 `add_db_data` 함수를 비동기적으로 호출합니다. @@ -39,3 +39,13 @@ async def delete_schedule_endpoint(schedule_data: DeleteScheduleDTO, chroma_clie return {"message": "Schedule delete successfully"} except Exception as e: 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)): + 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)) \ No newline at end of file From 285fbb17a70a1f19c1e3dfbfac0448ed15c8b2d8 Mon Sep 17 00:00:00 2001 From: uommou Date: Sat, 25 May 2024 21:28:52 +0900 Subject: [PATCH 2/2] feat: update schedule --- app/database/chroma_db.py | 27 ++++++++++++++++++++++++++- app/dto/db_dto.py | 12 +++++++++++- app/routers/chromadb.py | 14 +++++++------- 3 files changed, 44 insertions(+), 9 deletions(-) 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