Skip to content
Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions project/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 46 additions & 1 deletion project/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,51 @@ def AddChat(message,senderId):
except Exception as error:
print(error)
return 'Fail'
#################################################################
class LikeModel(BaseModel):
id = AutoField()
messageId = ForeignKeyField(ChatModel, backref='likes')
count = IntegerField(default=0)

class Meta:
db_table = 'like'

def display_all_users():
try:
users = UserModel.select()
user_list = []

for user in users:
last_message = ChatModel.select().where(ChatModel.senderId == user.id).order_by(
ChatModel.time.desc()).first()
if last_message:
last_message_time = last_message.time
else:
last_message_time = "No messages found"

user_data = {
"id": user.id,
"name": user.name,
"last_message_time": last_message_time
}
user_list.append(user_data)

print(f"Total users: {len(user_list)}")
print("User list:", user_list)
except Exception as error:
print(f"An error occurred while fetching users: {error}")


CreateTable.create()

class LikeManage:
@staticmethod
def like_message(messageId):
try:
like, created = LikeModel.get_or_create(messageId=messageId, defaults={'count': 0})
if not created:
like.count += 1
like.save()
return like.count
except Exception as error:
print(f"An error occurred: {error}")
return None