change sql request for getPrivateMessageUser and add default profile picture for users

This commit is contained in:
2024-08-26 20:57:29 +02:00
parent 7de76b750a
commit e7aeef8288
5 changed files with 12 additions and 6 deletions

View File

@ -6,7 +6,7 @@ class User(models.Model):
mail = models.EmailField(unique=True)
password = models.CharField(max_length=100)
id42 = models.DecimalField(max_digits=15, decimal_places=0, null=True, unique=True)
pfp = models.CharField(max_length=1024)
pfp = models.CharField(max_length=1024, default="/static/default_pfp.jpg")
class Message(models.Model):
id = models.AutoField(primary_key=True)

View File

@ -6,7 +6,7 @@
# By: edbernar <edbernar@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/03 15:10:23 by edbernar #+# #+# #
# Updated: 2024/08/25 21:23:08 by tomoron ### ########.fr #
# Updated: 2024/08/26 20:07:57 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -59,7 +59,14 @@ def getPrivateListUser(socket, content=None):
# (ceux qui ont eu conversation avec l'utilisateur)
# Si user existe pas, faire ça : socket.sendError("User not found", 9008)
id = socket.scope["session"].get("id", 0)
res = User.objects.raw("SELECT DISTINCT server_user.id AS id,'online' AS status, username, pfp FROM server_user RIGHT JOIN server_message ON server_message.to_id=server_user.id WHERE sender_id=%s;", [id])
request = """
SELECT DISTINCT server_user.id AS id,'online' AS status, username, pfp
FROM server_user
LEFT JOIN server_message AS sended ON sended.to_id=server_user.id
LEFT JOIN server_message AS received ON received.sender_id=server_user.id
WHERE sended.sender_id=%s OR received.to_id=%s;
"""
res = User.objects.raw(request,[id,id])
data = []
for x in res:
data.append({"name":x.username, "status":x.status, "pfp":x.pfp, "id":x.id})

View File

@ -1,6 +1,6 @@
INSERT INTO "server_user" ("username", "mail", "password", "id42", "pfp") VALUES
('tomoron', 'a@a.com', 'a5f1efc32bcc4dc53e471f9620b78ca9', NULL, 'https://localhost/img.jpg'),
('patate', 'b@b.com', '5e547979d3f20f43c87e5e0e8406f267', NULL, 'https://localhost/pfp.jpg');
('tomoron', 'a@a.com', 'a5f1efc32bcc4dc53e471f9620b78ca9', NULL, '/static/default_pfp.jpg'),
('patate', 'b@b.com', '5e547979d3f20f43c87e5e0e8406f267', NULL, '/static/default_pfp.jpg');
INSERT INTO "server_message" ("date", "sender_id", "to_id", "content") VALUES
('2024-08-25 18:10:54.27476+00', 1, 2, 'coucou'),