messenger finalizat
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
from fastapi import APIRouter
|
||||
from .send import send
|
||||
from .get_conversation import get_conversation
|
||||
from .get_conversation_url import get_conversation_url
|
||||
from app.models import Message
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/get_conversation_url/{id_user1}/{id_user2}")
|
||||
async def get_conversation_url_router(id_user1: str, id_user2: str):
|
||||
return await get_conversation_url(id_user1, id_user2)
|
||||
|
||||
|
||||
@router.post("/send")
|
||||
async def send_router(message: Message):
|
||||
return await send(message)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,9 @@
|
||||
from fastapi import HTTPException, status
|
||||
from database.queries.messages import find_conversation
|
||||
from database.queries.messages import find_conversation_db
|
||||
|
||||
|
||||
async def get_conversation(conversation_url: str):
|
||||
conversation = find_conversation(conversation_url)
|
||||
conversation = find_conversation_db(conversation_url)
|
||||
if conversation is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Conversation not found")
|
||||
return conversation
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
from database.queries.messages import get_conversation_url_db
|
||||
from database.queries.user import get_user_by_id
|
||||
from fastapi import HTTPException
|
||||
|
||||
|
||||
async def get_conversation_url(id_user1: str, id_user2: str):
|
||||
if get_user_by_id(id_user1) is None or get_user_by_id(id_user2) is None:
|
||||
raise HTTPException(status_code=404, detail="Users not in the system.")
|
||||
|
||||
conversation_url = get_conversation_url_db(id_user1, id_user2)
|
||||
return {'conversation_url': conversation_url}
|
||||
@@ -1,17 +1,12 @@
|
||||
from fastapi import HTTPException
|
||||
from app.models import Message
|
||||
from database.queries.messages import create_conversation, send_message_to_mongodb
|
||||
from database.queries.messages import send_message_db
|
||||
|
||||
|
||||
async def send(message: Message):
|
||||
conversation_url = create_conversation(message.sender, message.receiver)
|
||||
success = send_message_db(message)
|
||||
|
||||
if conversation_url is not None:
|
||||
success = send_message_to_mongodb(conversation_url, message.sender, message.conversation)
|
||||
|
||||
if success:
|
||||
return {"success": True, "message": "Message sent successfully"}
|
||||
raise HTTPException(status_code=500, detail="Internal Server Error")
|
||||
|
||||
raise HTTPException(status_code=500, detail="Error creating conversation")
|
||||
if success:
|
||||
return {"success": True, "message": "Message sent successfully"}
|
||||
raise HTTPException(status_code=500, detail="Internal Server Error")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user