From 67b7a241d7eb91a51534e3a3dab0afe7af88dff8 Mon Sep 17 00:00:00 2001 From: andrei-mihnea-cerbu Date: Sat, 13 Jan 2024 12:59:19 +0200 Subject: [PATCH] proiect finalizat --- messenger_app.sh | 5 ++ messenger_app/api/__init__.py | 3 ++ .../api/__pycache__/__init__.cpython-310.pyc | Bin 155 -> 279 bytes .../api/v1/endpoints/auth/__init__.py | 4 ++ messenger_app/api/v1/endpoints/auth/login.py | 9 ++++ messenger_app/api/v1/endpoints/auth/signup.py | 9 ++++ .../api/v1/endpoints/messages/__init__.py | 4 ++ .../__pycache__/__init__.cpython-310.pyc | Bin 1008 -> 1012 bytes .../get_conversation.cpython-310.pyc | Bin 592 -> 746 bytes .../messages/__pycache__/send.cpython-310.pyc | Bin 588 -> 715 bytes .../v1/endpoints/messages/get_conversation.py | 9 ++++ .../messages/get_conversation_url.py | 10 ++++ .../api/v1/endpoints/messages/send.py | 9 ++++ .../api/v1/endpoints/users/__init__.py | 4 ++ .../__pycache__/__init__.cpython-310.pyc | Bin 1079 -> 1083 bytes .../users/__pycache__/create.cpython-310.pyc | Bin 769 -> 922 bytes .../users/__pycache__/delete.cpython-310.pyc | Bin 538 -> 682 bytes .../api/v1/endpoints/users/create.py | 9 ++++ .../api/v1/endpoints/users/delete.py | 11 +++- .../api/v1/endpoints/users/get_all.py | 9 ++++ messenger_app/app/__init__.py | 3 ++ .../app/__pycache__/__init__.cpython-310.pyc | Bin 155 -> 288 bytes messenger_app/app/models/__init__.py | 7 +++ .../__pycache__/__init__.cpython-310.pyc | Bin 269 -> 271 bytes .../__pycache__/message.cpython-310.pyc | Bin 508 -> 477 bytes messenger_app/app/models/message.py | 1 - .../database/mongodb_database/__init__.py | 9 +++- .../__pycache__/__init__.cpython-310.pyc | Bin 309 -> 311 bytes .../database/postgresql_database/__init__.py | 10 +++- .../__pycache__/__init__.cpython-310.pyc | Bin 323 -> 325 bytes messenger_app/database/queries/__init__.py | 8 +++ .../__pycache__/__init__.cpython-310.pyc | Bin 168 -> 506 bytes .../__pycache__/messages.cpython-310.pyc | Bin 2081 -> 2499 bytes .../queries/__pycache__/user.cpython-310.pyc | Bin 1717 -> 2630 bytes messenger_app/database/queries/messages.py | 19 +++++++ messenger_app/database/queries/user.py | 51 ++++++++++++++++++ messenger_gui.sh | 5 ++ messenger_gui/app/__init__.py | 12 ++++- messenger_gui/app/http/__init__.py | 6 +++ messenger_gui/app/http/request_builder.py | 23 ++++++-- messenger_gui/app/http/request_handler.py | 14 ++++- .../app/{main.py => main_application.py} | 4 -- messenger_gui/app/models/__init__.py | 6 +++ .../app/models/http_models/__init__.py | 4 ++ .../app/models/view_models/__init__.py | 5 ++ messenger_gui/app/views/__init__.py | 8 +++ messenger_gui/app/views/chat.py | 13 +++++ messenger_gui/app/views/initial.py | 3 ++ messenger_gui/app/views/login.py | 11 ++++ messenger_gui/app/views/main_page.py | 6 +++ messenger_gui/app/views/message.py | 3 ++ messenger_gui/app/views/signup.py | 9 ++++ messenger_gui/app/views/user_frame.py | 5 +- 53 files changed, 321 insertions(+), 19 deletions(-) create mode 100755 messenger_app.sh create mode 100755 messenger_gui.sh rename messenger_gui/app/{main.py => main_application.py} (97%) diff --git a/messenger_app.sh b/messenger_app.sh new file mode 100755 index 0000000..333801c --- /dev/null +++ b/messenger_app.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +source venv/bin/activate +cd messenger_app +uvicorn app.main:app --reload diff --git a/messenger_app/api/__init__.py b/messenger_app/api/__init__.py index e69de29..8679f25 100644 --- a/messenger_app/api/__init__.py +++ b/messenger_app/api/__init__.py @@ -0,0 +1,3 @@ +""" +The 'api' package contains the logic behind the endpoints of the backend. The main version of the api is 'v1'. +""" \ No newline at end of file diff --git a/messenger_app/api/__pycache__/__init__.cpython-310.pyc b/messenger_app/api/__pycache__/__init__.cpython-310.pyc index 9cedb6093e2c4006e08ecac681274b16eaea249f..00997ff5a82893889021ae9c5be8669200277905 100644 GIT binary patch delta 178 zcmbQuIGu?%pO=@50SLYXElMq$$SYgV0pz4GL@}f=1~X_fRTXfBWTYynCl+L?D-DqGm{mPQZq91QosVKc_{_?nRz9}3i)YZfh3?dprD=t z$fR7LMuoD}qT0>3hHHs>Uv^aewvK8*yH0<@{{A^S27ea0o_x?G|@SX HiGu+EcDXf) delta 53 zcmbQvG@Fq(pO=@50SI`C=cF=Br|V&eWVCKd(&_SOjt diff --git a/messenger_app/api/v1/endpoints/auth/__init__.py b/messenger_app/api/v1/endpoints/auth/__init__.py index d6f48e0..c6c59a2 100644 --- a/messenger_app/api/v1/endpoints/auth/__init__.py +++ b/messenger_app/api/v1/endpoints/auth/__init__.py @@ -6,6 +6,10 @@ from .signup import signup router = APIRouter() +""" +The 'auth' packages contains the router configuration for the 'Authentication' endpoints. +""" + @router.post("/login") async def login_router(login_info: Login): diff --git a/messenger_app/api/v1/endpoints/auth/login.py b/messenger_app/api/v1/endpoints/auth/login.py index 8a9bff0..1d6331b 100644 --- a/messenger_app/api/v1/endpoints/auth/login.py +++ b/messenger_app/api/v1/endpoints/auth/login.py @@ -4,6 +4,15 @@ from database.queries.user import get_user_by_email async def login(login_info: Login): + """ + Verify user credentials + + Args: + login_info (Login) + + Returns: + dict : full user information besides password + """ result = get_user_by_email(login_info.email) if not result: raise HTTPException(status_code=404, detail='User not in system.') diff --git a/messenger_app/api/v1/endpoints/auth/signup.py b/messenger_app/api/v1/endpoints/auth/signup.py index f021b67..8bea246 100644 --- a/messenger_app/api/v1/endpoints/auth/signup.py +++ b/messenger_app/api/v1/endpoints/auth/signup.py @@ -4,6 +4,15 @@ from database.queries.user import get_user_by_email, create_user_db async def signup(user: User): + """ + Verify user credentials + + Args: + user (User) + + Returns: + dict : full user information besides password + """ result = get_user_by_email(user.email) if result: raise HTTPException(status_code=409, detail='User already exists.') diff --git a/messenger_app/api/v1/endpoints/messages/__init__.py b/messenger_app/api/v1/endpoints/messages/__init__.py index 6bc83ab..77729f6 100644 --- a/messenger_app/api/v1/endpoints/messages/__init__.py +++ b/messenger_app/api/v1/endpoints/messages/__init__.py @@ -4,6 +4,10 @@ from .get_conversation import get_conversation from .get_conversation_url import get_conversation_url from app.models import Message +''' +The 'messages' packages contains the router configuration for the 'Messages' endpoints. +''' + router = APIRouter() diff --git a/messenger_app/api/v1/endpoints/messages/__pycache__/__init__.cpython-310.pyc b/messenger_app/api/v1/endpoints/messages/__pycache__/__init__.cpython-310.pyc index ed97ff21ef5aad7aa0f8282696b55fc5249c014b..127008def02f3bcc2d1e226850539d8aec995984 100644 GIT binary patch delta 84 zcmeys{)L?{pO=@50SG#L7Nv49PvnzfoHbF~o{@87<`zaqzR7Y-HH^ZOXEQBel$dP8 eJWW9csFa6+hY@`{x&pO=@50SNy4ElL$&n#gy!p0SjnNT7tVgei+Tg(-!(m#K-dhB25ylcj0~ zmjV<7rIr+Brk14^E0koUDx{U>x5i7_z$f(xMy%6OH1MB29!ApjD+sd1$&kLP7!*f=d!hN{hj!O?>s1k!$h|#tHyz C%sW>A delta 58 zcmaFGdVz&6pO=@50SLZ|EK1E~oXB@rlA)BLNT7tVgei+Tg)xPxm#K-dhB25ylX-Fr M<6B0?$wf>R0J#_s3;+NC diff --git a/messenger_app/api/v1/endpoints/messages/__pycache__/send.cpython-310.pyc b/messenger_app/api/v1/endpoints/messages/__pycache__/send.cpython-310.pyc index 9fa2b1fafc2095bb76f4e0de0cd6cbada52d3f05..54d957f7b57bd148b96e316726543ade881f9fc7 100644 GIT binary patch delta 160 zcmX@Za+;MlpO=@50SNrP7p1IC^Yha4 zU7Wb!N*s&Qi>=^1kUp4d4PS^hO@!j0)RNMoJT&zlAt3<@!6k_$rNtm~7!@YIc*Mvx I`7~oA0Fyu}>;M1& delta 33 ncmX@jdWMBJpO=@50SJDIEJ{tA$a{;?Z*n^0BSyx_UQCSuox=&i diff --git a/messenger_app/api/v1/endpoints/messages/get_conversation.py b/messenger_app/api/v1/endpoints/messages/get_conversation.py index 032536b..e7ae5fd 100644 --- a/messenger_app/api/v1/endpoints/messages/get_conversation.py +++ b/messenger_app/api/v1/endpoints/messages/get_conversation.py @@ -3,6 +3,15 @@ from database.queries.messages import find_conversation_db async def get_conversation(conversation_url: str): + """ + Retrieves the full context of the conversation + + Args: + conversation_url (str) + + Returns: + HTTP Status + """ conversation = find_conversation_db(conversation_url) if conversation is None: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Conversation not found") diff --git a/messenger_app/api/v1/endpoints/messages/get_conversation_url.py b/messenger_app/api/v1/endpoints/messages/get_conversation_url.py index 7bead34..746f10c 100644 --- a/messenger_app/api/v1/endpoints/messages/get_conversation_url.py +++ b/messenger_app/api/v1/endpoints/messages/get_conversation_url.py @@ -4,6 +4,16 @@ from fastapi import HTTPException async def get_conversation_url(id_user1: str, id_user2: str): + """ + Retrieves the conversation identifier + + Args: + id_user1 (str) + id_user2 (str) + + Returns: + (str) : conversation_url + """ 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.") diff --git a/messenger_app/api/v1/endpoints/messages/send.py b/messenger_app/api/v1/endpoints/messages/send.py index 023914a..0d7ecdd 100644 --- a/messenger_app/api/v1/endpoints/messages/send.py +++ b/messenger_app/api/v1/endpoints/messages/send.py @@ -4,6 +4,15 @@ from database.queries.messages import send_message_db async def send(message: Message): + """ + Stores message in MongoDB + + Args: + message (Message) + + Returns: + HTTP Status + """ success = send_message_db(message) if success: diff --git a/messenger_app/api/v1/endpoints/users/__init__.py b/messenger_app/api/v1/endpoints/users/__init__.py index 38f3693..2bab1eb 100644 --- a/messenger_app/api/v1/endpoints/users/__init__.py +++ b/messenger_app/api/v1/endpoints/users/__init__.py @@ -5,6 +5,10 @@ from .update import update_user from .delete import delete_user from .get_all import get_all_users +''' +The 'messages' packages contains the router configuration for the 'Messages' endpoints. +''' + router = APIRouter() diff --git a/messenger_app/api/v1/endpoints/users/__pycache__/__init__.cpython-310.pyc b/messenger_app/api/v1/endpoints/users/__pycache__/__init__.cpython-310.pyc index 65c93d69948ecb810492289c87822e01f285e5e5..fe9dbe86baa91716b19a20c38946ec82c7af3370 100644 GIT binary patch delta 96 zcmdnav73W0pO=@50SGSoElL$;p2#P|xMiZYHzVi9(sD*d{>g6{n;1nV7cgZpN>0Ab kRLCed*_Zj4ni5b04+9S)3^FmXv2ZYRF>6qe3z+^ gQEIY3^Dz|#pmH7t9!3~sW8z@uV&q^EfMYIJ073W>!vFvP diff --git a/messenger_app/api/v1/endpoints/users/__pycache__/create.cpython-310.pyc b/messenger_app/api/v1/endpoints/users/__pycache__/create.cpython-310.pyc index d5b05a4859091a4cafae924d11d300c33c2028f4..05d0df168038ee801cb2e87baefe8222da82cc0a 100644 GIT binary patch delta 190 zcmZox6N7$mQt5eg(V5z2y6OG=CK&{QVp=N9ComZU;7p5*^+Q?_f$mqBECZjeZBjaRN=BWUfhzNlI diff --git a/messenger_app/api/v1/endpoints/users/__pycache__/delete.cpython-310.pyc b/messenger_app/api/v1/endpoints/users/__pycache__/delete.cpython-310.pyc index 769936d86dc0e0988632f5c3ecf03e10acfaa071..44a04b9679aabf11c6f6f07f3d2bf70a545ac115 100644 GIT binary patch delta 307 zcmbQmvWitZpO=@50SI3EEJ{7e$iVOz#6bp3K#l_t7i&z^R^&-xX<>+BO<@gY&}5q! zXEAZUc0FS$LlJ)oV+vCWa|%l@QxjteQw>8iBO^l!BTyA<)jTc*C~!&5Ni9h&R!CGR zElw@sf{QyAr59Vlc_76g`S{Ef1&!j8B29$CpwyDmqC8Z!4hqTnxdkAD!MYSO^V0H* zauZ83^Ye6ooaCI+l+3(zh0GKnFHNDiG&wo7xHzpe2X5cQmkyk_*r7H~)?+N^=i*@G Z0m33~ptt=r*(Psc)Svu<(SV7E833v|N*n+H delta 165 zcmZ3*I*Ua+pO=@50SK=2FHBWsWMFs<;vfTNAjbiSi}faID+;BurZJ_kq_DQIM6so? z1v6-}PmHkOyv1HxoLUs0nKE&Lwmd^ALlJ)oV+vymQwno0QxjteQw>8iBO^l!15iE7 w@-i9+#gc<1P01_>}zQ`1q9! RMNB}46){b84rAhA001XjIFJAU delta 53 zcmZ3$G@Fq(pO=@50SMAF=cF=Br|V&aJ~CKd(&1)&LU diff --git a/messenger_app/app/models/__init__.py b/messenger_app/app/models/__init__.py index cd9848d..aa3f23b 100644 --- a/messenger_app/app/models/__init__.py +++ b/messenger_app/app/models/__init__.py @@ -1,3 +1,10 @@ from .user import User from .message import Message from .login import Login + +''' +The 'models' package contains the schematics for the API body structures. In more detail: + - 'Login' model is used for the auth/login endpoint + - 'User' model is used for the auto/signup and users endpoints + - 'Message' model is used for the messages/send endpoint +''' \ No newline at end of file diff --git a/messenger_app/app/models/__pycache__/__init__.cpython-310.pyc b/messenger_app/app/models/__pycache__/__init__.cpython-310.pyc index 51f665084e7b8e8057b58b625a67059b4fe2ee2b..41c79879afb96b22876200a381c63d99265595ab 100644 GIT binary patch delta 35 ncmeBW>SyB1=jG*M00Jx5MXBkG6ZyXKZ~%Ec3_OfHj4Vt5cufU_ delta 33 mcmeBY>Sf}~=jG*M0D>zI7N+_#Oyv8@#RlZ@Fz_%6FaiLA@dlRw diff --git a/messenger_app/app/models/__pycache__/message.cpython-310.pyc b/messenger_app/app/models/__pycache__/message.cpython-310.pyc index ba8040aa168c03d9dea00229efbf08d3789e5895..539d72e954e88ef6d713f82c074ee7189e0d12c6 100644 GIT binary patch delta 187 zcmeyve3zLwpO=@50SHoE7Nzz~av7r-85!IeQkYVhTNqN9QyH6? zqnJ`yf*CYfUxM^#GT!2JN-R$G%}+_qnOJp}jSnbT#5dWO(JPJ_$YcTHVvy-v3>=Ig z$ir9!68F<&zQs{cnUa`Sl9^n@1QY=a7eTaxxL_7Pkadg0CO1E&G$+-L5y&eBnaIN+ G!VCb(93r0p delta 218 zcmcc1{D+x0pO=@50SLYcFG^iCkykcA2gpfbNMX!j$YqRTWCXF9a+q?NqL>&N+!<1s zQ&?IUQdm+Mo0+4SQ&@u;G}&H)^lLKS;&e(ZPW8=CNzDOrI8qWzQcE&(Qzs^!W#b1b zDB_=N%IKBK0%WoRaWTkNE(Q)p5aeMj0*U)+vfSb*s7y)BE6GeQVgia3F@p$@ToJ?! fI7MiFKJ$=@mp diff --git a/messenger_app/app/models/message.py b/messenger_app/app/models/message.py index f208f49..b043897 100644 --- a/messenger_app/app/models/message.py +++ b/messenger_app/app/models/message.py @@ -1,5 +1,4 @@ from pydantic import BaseModel -from datetime import datetime class Message(BaseModel): diff --git a/messenger_app/database/mongodb_database/__init__.py b/messenger_app/database/mongodb_database/__init__.py index 2dd56b3..3ea4c72 100644 --- a/messenger_app/database/mongodb_database/__init__.py +++ b/messenger_app/database/mongodb_database/__init__.py @@ -1,4 +1,11 @@ from .connection import MONGODB_CONFIG, MongoDbHandler mongo_db_handler = MongoDbHandler(**MONGODB_CONFIG) -mongo_db_handler.connect() \ No newline at end of file +mongo_db_handler.connect() + +''' +The 'mongodb_database' package contains the definition of the 'MongoDbHandler' class which connects to the MongoDB +database used for storing the messages between the clients. + +The object 'mongo_db_handler' is created inside this file and can be used throughout the lifetime of the application +''' \ No newline at end of file diff --git a/messenger_app/database/mongodb_database/__pycache__/__init__.cpython-310.pyc b/messenger_app/database/mongodb_database/__pycache__/__init__.cpython-310.pyc index f3c79720c081873347055487603976db1a704545..6915e76101974a99e3587f91cf5c07e6a70aeddd 100644 GIT binary patch delta 36 pcmdnWw4I4BpO=@50SH*!7Nu@s+{h=($io5T3NY|7aWJwl0RVp+1vmfz delta 34 ncmdnaw3Uf3pO=@50SG?#FHCJ?*vKc#$i)Wa3NY|7@h}1aime7Z diff --git a/messenger_app/database/postgresql_database/__init__.py b/messenger_app/database/postgresql_database/__init__.py index 20bd1fd..8eb2199 100644 --- a/messenger_app/database/postgresql_database/__init__.py +++ b/messenger_app/database/postgresql_database/__init__.py @@ -1,4 +1,12 @@ from .connection import POSTGRESQL_CONFIG, PostgreSQLHandler postgresql_db_handler = PostgreSQLHandler(**POSTGRESQL_CONFIG) -postgresql_db_handler.connect() \ No newline at end of file +postgresql_db_handler.connect() + +''' +The 'postgresql_database' package contains the definition of the 'PostgreSQlHandler' class which connects to the MongoDB +database used for storing information about the users and the existing chats + +The object 'postgresql_db_handler' is created inside this file and can be used throughout the lifetime +of the application +''' \ No newline at end of file diff --git a/messenger_app/database/postgresql_database/__pycache__/__init__.cpython-310.pyc b/messenger_app/database/postgresql_database/__pycache__/__init__.cpython-310.pyc index baa338dd4594c2f685af357f76fa9346686c2771..427540af873c86c940e2a6fb997c33470b6de25c 100644 GIT binary patch delta 36 pcmX@ibd-rNpO=@50SFx27NtIC+{mZR$io5T3NY|7aWJwl0RW8d1 zA`WDj%*&fMlkwAOCfLR|Z@3r<@zGxnjdS9H4^7w^@hHsbLCnVLih*odBjoFZ!6N0* zDgC4>1npf^))AD+>1aJiFSXS*sDO|N4Xid0nR43DWVhtODx;LD+feT$Y(GhjOb z9Z*G-JjOFu7!;&g9nW@fX`T5OtT6t@QfLmzgiPKw%K7YWHrgIZX}p&5U4$`z^58yi zi`utX@FW3kaqV^L$EBj@qN_0MBdNNs`1!nIw~j(e>ui*A-fgy%v(}r`;Ca7I>P05v E3%6>X`Tzg` delta 55 zcmeyxyn>N0pO=@50SGGk7p5{WOyrZ1WC8M07=jrz8U0o=6fpvMP-5~_#$+ZI1^_XU B3Ge^_ diff --git a/messenger_app/database/queries/__pycache__/messages.cpython-310.pyc b/messenger_app/database/queries/__pycache__/messages.cpython-310.pyc index f3f1091bdca443629a0e761dbe0016514c35adba..7ab432271fe39d69b0f384dddab00e2ac97541f2 100644 GIT binary patch delta 515 zcmZ1|a9EfxpO=@50SF$uFG_vJwUN(=vA*gxmjV1Etent+p_|l>r znBS4bVWH^>3{HeuSiO{znQVm;6L7cQV#!O)O})jEoRL`KH`$yyi(3I0t;IY*f`e=G c8s>S7jK-V2S!I|QT_$I+Z()_>5Ec>y0FPplC;$Ke delta 95 zcmX>syikBIpO=@50SF$8EJ`)x+{kCd$mq9Om#LGHk#X{N<|rYCUJ6RYANOc5*&=1{aEKQGAe9-%O=CbXgHaRa|E*uS5Ryfm$gV&Z-T^~)JAMllGMr^?7>eU zIeOB&M^AeYc40yN41!-o*eBDPQCpA|a|nbd&&%)sPp-0m^EsZ)dLyuIzFm-U?=*MQ zb$^T$lfkuz`fFJbtcXOaLC{am4vCOhQO*$c2~)IAi9mHOkm_*MmJprwZ0?fSlO=mH z1Z56?M6nbep-_}jTP3P3*sH89$SNVqpii^c9PjeB3THAE5v?O~M5U6p+3EeF zQ`M8srQ_*4XRezJ{@B>ZB9SJh2Twq~1FzfB`e>`bUi$zv{pfrJuFtWuGp>(gE8Q5_ z6%T$5uz@T-+QnuEuUdj1f?xh~4I|Nq+r)5_^ssDk<6sL*+2NvZ;qr^vGby6#L$Rw| zH7MH)v-NGP222z2we%c3MVW*xkHH5|_y#Fc zMO)giL6IF(`U$-u2IDXJ2h!gwLHq}?iZL0yYuO7JDI1?-7|;jg(M#>qzb8gYAo~V EAA1=iRR910 delta 189 zcmX>mvXz%FpO=@50SJVjFHDVQo5**PjUkvplhtqXTtd`d7q!G^m&jNU$(Y-pm>TmS*vr{En@8 zauItLw>n6g10wyLJpd-Xg2R)uNE|4v$y~%SxrSA4vLq)Tw-J(JBhJ~3)|1b1=5z9L M@N#f+aPx2i0Ek~GLI3~& diff --git a/messenger_app/database/queries/messages.py b/messenger_app/database/queries/messages.py index 35060ba..fd98fd4 100644 --- a/messenger_app/database/queries/messages.py +++ b/messenger_app/database/queries/messages.py @@ -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) diff --git a/messenger_app/database/queries/user.py b/messenger_app/database/queries/user.py index 6449d77..a522493 100644 --- a/messenger_app/database/queries/user.py +++ b/messenger_app/database/queries/user.py @@ -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; """ diff --git a/messenger_gui.sh b/messenger_gui.sh new file mode 100755 index 0000000..819d336 --- /dev/null +++ b/messenger_gui.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +source venv/bin/activate +cd messenger_gui +python main.py diff --git a/messenger_gui/app/__init__.py b/messenger_gui/app/__init__.py index 6f6baf2..ff6490a 100644 --- a/messenger_gui/app/__init__.py +++ b/messenger_gui/app/__init__.py @@ -1,2 +1,10 @@ -from .main import MainApplication -app = MainApplication() \ No newline at end of file +from .main_application import MainApplication +app = MainApplication() + +''' +The 'app' package contains all the UI and network components to run the application'. This package contains the +following packages: + - http (tools to make HTTP requests to the API) + - models (schematics for the HTTP requests and user info validation) + - views (UI design) +''' \ No newline at end of file diff --git a/messenger_gui/app/http/__init__.py b/messenger_gui/app/http/__init__.py index a8938f4..d3c06ac 100644 --- a/messenger_gui/app/http/__init__.py +++ b/messenger_gui/app/http/__init__.py @@ -1,3 +1,9 @@ from .request_builder import RequestBuilder request_builder = RequestBuilder() + +""" +The 'http' package contains the tools for making HTTP requests to the backend. This package contains: + - request_builder: class through which the request is build + - request_handler: object resulted from the builder and can be used to make requests. +""" diff --git a/messenger_gui/app/http/request_builder.py b/messenger_gui/app/http/request_builder.py index d43c589..5d7dbfa 100644 --- a/messenger_gui/app/http/request_builder.py +++ b/messenger_gui/app/http/request_builder.py @@ -2,6 +2,18 @@ from .request_handler import _HttpRequestHandler class RequestBuilder: + """ + A Builder for HTTP Request class + + Attributes: + __url (str): URL at which the request is made + __headers (dict): + __body (dict): + __params (dict): Query params + __method (str): HTTP method (GET, POST, ...) + """ + + def __init__(self): self.__url = "" self.__headers = {} @@ -9,26 +21,27 @@ class RequestBuilder: self.__params = None self.__method = "GET" - def set_url(self, url=str): + def set_url(self, url): self.__url = url return self - def set_headers(self, headers=dict): + def set_headers(self, headers): self.__headers = headers return self - def set_body(self, body=dict): + def set_body(self, body): self.__body = body return self - def set_params(self, params=dict): + def set_params(self, params): self.__params = params return self - def set_method(self, method=str): + def set_method(self, method): self.__method = method return self def build(self): + """Based on the set parameters it returns a Request Handler object""" return _HttpRequestHandler(url=self.__url, method=self.__method, body=self.__body, params=self.__params, headers=self.__headers) diff --git a/messenger_gui/app/http/request_handler.py b/messenger_gui/app/http/request_handler.py index 8458204..82dd11c 100644 --- a/messenger_gui/app/http/request_handler.py +++ b/messenger_gui/app/http/request_handler.py @@ -3,16 +3,26 @@ import requests class _HttpRequestHandler: + """ + A Builder for HTTP Request class + + Attributes: + url (str): URL at which the request is made + headers (dict): + body (dict): + params (dict): Query params + method (str): HTTP method (GET, POST, ...) + """ + def __init__(self, url, method="GET", params=None, headers=None, body=None): self.url = url self.method = method self.headers = headers - print(body) self.body = json.dumps(body) self.params = params def make_request(self): - print(self.body) + """Make HTTP request and returns the answer""" response = requests.request(method=self.method, url=self.url, params=self.params, data=self.body, headers=self.headers) return response diff --git a/messenger_gui/app/main.py b/messenger_gui/app/main_application.py similarity index 97% rename from messenger_gui/app/main.py rename to messenger_gui/app/main_application.py index 1cd0ec3..b0b66d4 100644 --- a/messenger_gui/app/main.py +++ b/messenger_gui/app/main_application.py @@ -1,6 +1,5 @@ import json import tkinter as tk -from PIL import Image, ImageTk from app.views.login import LoginView from app.views.initial import InitialView from app.views.signup import SignupView @@ -52,6 +51,3 @@ class MainApplication(tk.Tk): self.current_logged_user['id'] = data['info']['id'] self.current_logged_user['username'] = data['info']['username'] self.current_logged_user['email'] = data['info']['email'] - - - diff --git a/messenger_gui/app/models/__init__.py b/messenger_gui/app/models/__init__.py index e69de29..753b716 100644 --- a/messenger_gui/app/models/__init__.py +++ b/messenger_gui/app/models/__init__.py @@ -0,0 +1,6 @@ +""" +The 'models' package contains schematics for the HTTP requests and validations for the information provided by the +user during the authentication. The package contains: + - http_models + - view_models +""" \ No newline at end of file diff --git a/messenger_gui/app/models/http_models/__init__.py b/messenger_gui/app/models/http_models/__init__.py index 5dd9f36..baa2b18 100644 --- a/messenger_gui/app/models/http_models/__init__.py +++ b/messenger_gui/app/models/http_models/__init__.py @@ -1,2 +1,6 @@ from .login import LoginRequestModel from .signup import SignupRequestModel + +""" +The 'http_models' package contains the schematics for the body data when making HTTP requests +""" \ No newline at end of file diff --git a/messenger_gui/app/models/view_models/__init__.py b/messenger_gui/app/models/view_models/__init__.py index d698275..bea3e7a 100644 --- a/messenger_gui/app/models/view_models/__init__.py +++ b/messenger_gui/app/models/view_models/__init__.py @@ -1,2 +1,7 @@ from .login import LoginModel from .signup import SignupModel + +""" +The 'view models' package contains the validations for the information the user provides during the authentication +(login/sign up) +""" \ No newline at end of file diff --git a/messenger_gui/app/views/__init__.py b/messenger_gui/app/views/__init__.py index e69de29..cbd4544 100644 --- a/messenger_gui/app/views/__init__.py +++ b/messenger_gui/app/views/__init__.py @@ -0,0 +1,8 @@ +""" +The 'views' package contains all the UI implementation of the app. The app contains the following views: + - InitialView + - LoginView + - SingUpView + - MainPageView + - ChatView +""" \ No newline at end of file diff --git a/messenger_gui/app/views/chat.py b/messenger_gui/app/views/chat.py index 3d07477..a8a9b4b 100644 --- a/messenger_gui/app/views/chat.py +++ b/messenger_gui/app/views/chat.py @@ -5,6 +5,10 @@ from app.views.message import MessageView class ChatWindow(tk.Toplevel): + """ + This view is opened in a separate window and takes care of the communication between the two users. It receives + both the users' information and retrieves the conversation_url. + """ def __init__(self, master=None, user_data=None, current_logged_user=None): super().__init__(master) @@ -48,6 +52,7 @@ class ChatWindow(tk.Toplevel): } def create_widgets(self, conversation): + """Creates the UI of this view""" # Create a frame for displaying messages self.messages_frame = tk.Frame(self) self.messages_frame.pack() @@ -70,6 +75,10 @@ class ChatWindow(tk.Toplevel): self.send_button.pack(side=tk.RIGHT) def update_chat(self): + """ + This function is scheduled each second to make a request to the API to retrieve the latest chat between the + users + """ self.messages_frame.destroy() self.messages_frame = tk.Frame(self) self.messages_frame.pack() @@ -85,7 +94,9 @@ class ChatWindow(tk.Toplevel): pass def send_message(self): + """At the submit button, the text is sent to the database""" message = self.entry_widget.get() + self.define_send_message_params(message, "text") if not message: return @@ -101,6 +112,7 @@ class ChatWindow(tk.Toplevel): self.update_chat() def get_conversation_url(self): + """Fetches the conversation_url""" request_builder.set_url(self.url) request_builder.set_body(self.body) request_builder.set_headers(self.headers) @@ -113,6 +125,7 @@ class ChatWindow(tk.Toplevel): return data['conversation_url'] def get_conversation(self): + """Fetches the conversation between the users""" request_builder.set_url(self.url) request_builder.set_body(self.body) request_builder.set_headers(self.headers) diff --git a/messenger_gui/app/views/initial.py b/messenger_gui/app/views/initial.py index 3326d2d..06089d8 100644 --- a/messenger_gui/app/views/initial.py +++ b/messenger_gui/app/views/initial.py @@ -2,6 +2,9 @@ import tkinter as tk class InitialView(tk.Frame): + """ + This class is the first rendered view of the application. This offers the options to Login or sign Up + """ def __init__(self, master=None): super().__init__(master) self.create_widgets() diff --git a/messenger_gui/app/views/login.py b/messenger_gui/app/views/login.py index c5f771d..cc678e0 100644 --- a/messenger_gui/app/views/login.py +++ b/messenger_gui/app/views/login.py @@ -14,6 +14,10 @@ def hash_password(password): class LoginView(tk.Frame): + """ + This view takes care of the validation of the user in the system. This class receives the login information and + validates them. The response is shown to the user. + """ def __init__(self, master=None): super().__init__(master) self.form_frame = None @@ -27,6 +31,9 @@ class LoginView(tk.Frame): self.params = None def create_widgets(self): + """ + Creates the layout of the view + """ # Create a frame to hold the entry fields and labels self.form_frame = tk.Frame(self) @@ -71,6 +78,10 @@ class LoginView(tk.Frame): self.master.change_to_initial_view() def on_login(self): + """ + After login button pressed, the validation of the provided information starts and will redirect the + user to next view if everything is accepted + """ # Retrieve values from entry fields email = self.email_entry.get() password = self.password_entry.get() diff --git a/messenger_gui/app/views/main_page.py b/messenger_gui/app/views/main_page.py index 0cbe766..0bac8f0 100644 --- a/messenger_gui/app/views/main_page.py +++ b/messenger_gui/app/views/main_page.py @@ -6,6 +6,10 @@ from app.views.user_frame import UserFrame class MainPageView(tk.Frame): + """ + This is the view from which the user will open a chat with anyone which is registered in the system. Each chat is + shown as a box with a photo, the username and the email. + """ def __init__(self, master=None): super().__init__(master) self.form_frame = None @@ -20,6 +24,7 @@ class MainPageView(tk.Frame): self.body = None def create_widgets(self): + """Takes care of the creation of the UI""" # Create a main frame to center the user frame and button frame main_frame = tk.Frame(self.master) main_frame.pack(expand=True) @@ -57,6 +62,7 @@ class MainPageView(tk.Frame): self.master.change_to_initial_view() def open_chat(self, user_data): + """Opens a chat in a different window""" # Pass both the clicked user data and the current logged user info to ChatWindow chat_window = ChatWindow(self, user_data, self.master.current_logged_user) chat_window.mainloop() # Main loop for the new window diff --git a/messenger_gui/app/views/message.py b/messenger_gui/app/views/message.py index db7642a..874611a 100644 --- a/messenger_gui/app/views/message.py +++ b/messenger_gui/app/views/message.py @@ -7,6 +7,9 @@ import base64 class MessageView(tk.Frame): + """ + This view is the message that appears in main windows of the chat. This is configured to hold text and images. + """ def __init__(self, master, message, current_logged_user, user_data, *args, **kwargs): super().__init__(master, *args, **kwargs) self.current_logged_user = current_logged_user diff --git a/messenger_gui/app/views/signup.py b/messenger_gui/app/views/signup.py index 8e22a3e..ed8fcd5 100644 --- a/messenger_gui/app/views/signup.py +++ b/messenger_gui/app/views/signup.py @@ -14,6 +14,10 @@ def hash_password(password): class SignupView(tk.Frame): + """ + This view takes care of the registration of the user in the system. This class receives the sing up + information and validates them. The response is shown to the user. + """ def __init__(self, master=None): super().__init__(master) self.form_frame = None @@ -27,6 +31,7 @@ class SignupView(tk.Frame): self.params = None def create_widgets(self): + """Creates the layout of the view""" # Create a frame to hold the entry fields and labels self.form_frame = tk.Frame(self) @@ -78,6 +83,10 @@ class SignupView(tk.Frame): self.master.change_to_initial_view() def on_signup(self): + """ + After sign up button pressed, the validation of the provided information starts and will redirect the + user to next view if everything is accepted + """ # Retrieve values from entry fields username = self.username_entry.get() email = self.email_entry.get() diff --git a/messenger_gui/app/views/user_frame.py b/messenger_gui/app/views/user_frame.py index 492387e..8a38dd2 100644 --- a/messenger_gui/app/views/user_frame.py +++ b/messenger_gui/app/views/user_frame.py @@ -3,11 +3,13 @@ from PIL import Image, ImageTk class UserFrame(tk.Frame): + """ + This class takes care of the aspect of the user blocks from the MainPageView. + """ def __init__(self, master, user_data, current_logged_user, click_callback, *args, **kwargs): super().__init__(master, *args, **kwargs) self.current_logged_user = current_logged_user - print(user_data) self.user_data = { 'id': user_data[0], @@ -45,7 +47,6 @@ class UserFrame(tk.Frame): # Bind the click event to the user frame user_frame.bind("", lambda event, user_data=self.user_data, current_logged_user=self.current_logged_user: self.on_user_click(user_data, current_logged_user)) - # Pack the user frame user_frame.pack(side=tk.LEFT, padx=10, pady=10)