Skip to content

Commit

Permalink
conflicts fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrukh802 committed Jun 6, 2024
2 parents dbae6b6 + b4c58e7 commit 59d05e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/api/v1/conversations/conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@ async def conversation_messages(
return APIResponse(
data=response, message="User conversation messages returned successfully!"
)

@conversation_router.delete("/{conv_id}")
async def delete_conversation(
conv_id: UUID = Path(..., description="ID of the conversation"),
conversation_controller: ConversationController = Depends(
Factory().get_conversation_controller
),
user: UserInfo = Depends(get_current_user),

):
response = await conversation_controller.archive_conversation(
conv_id, user.id
)
return APIResponse(
data=response, message="Conversation archived successfully"
)
16 changes: 16 additions & 0 deletions server/app/controllers/conversation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from fastapi import status, HTTPException
from app.models import User, UserConversation
from app.repositories import UserRepository
from app.repositories.conversation import ConversationRepository
Expand Down Expand Up @@ -38,3 +39,18 @@ async def get_conversation_messages(
count = await self.conversation_repository.get_messages_count(conversation_id)

return ConversationMessageList(count=count, messages=conversation_messages)

async def archive_conversation(
self, conversation_id: str, user_id: str
):
user_conversation = (
await self.conversation_repository.get_by_id(conversation_id)
)
if not user_conversation:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
message=f"conversation with id: {conversation_id} was not found")
if user_conversation.user_id != user_id:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED,
message="Unauthorized to update conversation for this user")
user_conversation.valid = False
await self.conversation_repository.session.commit()

0 comments on commit 59d05e9

Please sign in to comment.