proiect finalizat
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
'''
|
||||
The 'queries' package contains functions which are used by the API to execute database operations. This package contains
|
||||
implementations for 'messages' and 'users' requirements. The list of the functions is:
|
||||
- create_conversation_db()
|
||||
- find_conversation_db()
|
||||
- get_conversation_url_db()
|
||||
- send_message_db
|
||||
'''
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -5,6 +5,16 @@ from datetime import datetime
|
||||
|
||||
|
||||
def create_conversation_db(user1_id, user2_id):
|
||||
"""
|
||||
Creates the conversation identifier for two users.
|
||||
|
||||
Args:
|
||||
user1_id (str): ID of first user.
|
||||
user1_id (str): ID of second user.
|
||||
|
||||
Returns:
|
||||
str: Conversation identifier/URL
|
||||
"""
|
||||
current_datetime = datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
unique_id = str(uuid.uuid4()).replace('-', '')
|
||||
conversation_url = f"{current_datetime}_{unique_id}"
|
||||
@@ -20,6 +30,15 @@ def create_conversation_db(user1_id, user2_id):
|
||||
|
||||
|
||||
def find_conversation_db(conversation_url):
|
||||
"""
|
||||
Retrieves the conversation from MongoDB
|
||||
|
||||
Args:
|
||||
conversation_url (str): conversation identifier
|
||||
|
||||
Returns:
|
||||
dic: conversation
|
||||
"""
|
||||
collection = mongo_db_handler.get_collection()
|
||||
query = {'name': conversation_url}
|
||||
result_set = collection.find_one(query)
|
||||
|
||||
@@ -2,6 +2,15 @@ from database import postgresql_db_handler
|
||||
|
||||
|
||||
def get_user_by_id(user_id):
|
||||
"""
|
||||
Creates the conversation identifier for two users.
|
||||
|
||||
Args:
|
||||
user_id (str): user id
|
||||
|
||||
Returns:
|
||||
User: information about the user if exists
|
||||
"""
|
||||
query = """
|
||||
SELECT * FROM users WHERE id = %s;
|
||||
"""
|
||||
@@ -15,6 +24,15 @@ def get_user_by_id(user_id):
|
||||
|
||||
|
||||
def get_user_by_email(email):
|
||||
"""
|
||||
Creates the conversation identifier for two users.
|
||||
|
||||
Args:
|
||||
email (str): email of the user
|
||||
|
||||
Returns:
|
||||
User: information about the user if exists
|
||||
"""
|
||||
query = """
|
||||
SELECT * FROM users WHERE email = %s;
|
||||
"""
|
||||
@@ -28,6 +46,17 @@ def get_user_by_email(email):
|
||||
|
||||
|
||||
def create_user_db(username, password, email):
|
||||
"""
|
||||
Creates used based on provided information
|
||||
|
||||
Args:
|
||||
username (str)
|
||||
password (str)
|
||||
email (str)
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
query = """
|
||||
INSERT INTO users (username, password, email)
|
||||
VALUES (%s, %s, %s);
|
||||
@@ -37,6 +66,19 @@ def create_user_db(username, password, email):
|
||||
|
||||
|
||||
def update_user_db(user_id, new_username, new_password, new_email):
|
||||
"""
|
||||
Updates user based on the new information
|
||||
|
||||
Args:
|
||||
user_id (int)
|
||||
new_username (str)
|
||||
new_password (str)
|
||||
new_email (str)
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
|
||||
query = """
|
||||
UPDATE users
|
||||
SET username = %s, password = %s, email = %s
|
||||
@@ -48,6 +90,15 @@ def update_user_db(user_id, new_username, new_password, new_email):
|
||||
|
||||
|
||||
def delete_user_db(user_id):
|
||||
"""
|
||||
Deletes a user
|
||||
|
||||
Args:
|
||||
user_id: int
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
query = """
|
||||
DELETE FROM users WHERE id = %s;
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user