Skip to content

Commit

Permalink
Merge pull request #58 from studio-recoding/feat/crud
Browse files Browse the repository at this point in the history
feat: delete schedule 추가
  • Loading branch information
uommou authored May 24, 2024
2 parents 638159c + a1986d2 commit 1929e7a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
11 changes: 10 additions & 1 deletion app/database/chroma_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/dto/db_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions app/routers/chromadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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))

0 comments on commit 1929e7a

Please sign in to comment.