@@ -27,6 +27,10 @@ async def create_student(self, telegram_user_id: int, telegram_username: str) ->
2727 async def get_student_by_telegram_user_id (self , telegram_user_id : int ) -> StudentDTO :
2828 raise NotImplementedError
2929
30+ @abstractmethod
31+ async def get_student_by_github_username (self , github_username : str ) -> StudentDTO :
32+ raise NotImplementedError
33+
3034 @abstractmethod
3135 async def set_github_username (self , telegram_user_id : int , github_username : str ) -> None :
3236 raise NotImplementedError
@@ -73,21 +77,44 @@ async def create_student(self, telegram_user_id: int, telegram_username: str) ->
7377 print (content )
7478
7579 async def get_student_by_telegram_user_id (self , telegram_user_id : int ) -> StudentDTO :
76- get_student_endpoint = f"{ self ._endpoint } /api/students/{ telegram_user_id } "
80+ get_student_endpoint = f"{ self ._endpoint } /api/students/telegram/ { telegram_user_id } "
7781 async with aiohttp .ClientSession () as session :
7882 async with session .get (get_student_endpoint ) as res :
7983 if res .status == 404 :
8084 raise StudentNotFoundError (telegram_user_id )
8185 content = await res .text (encoding = "utf-8" )
82- print (content )
86+ data = json .loads (content )
87+ return StudentDTO (
88+ telegram_user_id = data ["telegramUserId" ],
89+ telegram_username = data ["telegramUsername" ],
90+ github_username = data ["githubUsername" ],
91+ joined_at = data ["registeredAt" ],
92+ has_enabled_notifications = True
93+ )
94+
95+ async def get_student_by_github_username (self , github_username : str ) -> StudentDTO :
96+ get_student_endpoint = f"{ self ._endpoint } /api/students/github/{ github_username } "
97+ async with aiohttp .ClientSession () as session :
98+ async with session .get (get_student_endpoint ) as res :
99+ if res .status == 404 :
100+ raise StudentNotFoundError (github_username )
101+ content = await res .text (encoding = "utf-8" )
102+ data = json .loads (content )
103+ return StudentDTO (
104+ telegram_user_id = data ["telegramUserId" ],
105+ telegram_username = data ["telegramUsername" ],
106+ github_username = data ["githubUsername" ],
107+ joined_at = data ["registeredAt" ],
108+ has_enabled_notifications = True
109+ )
83110
84111 async def set_github_username (self , telegram_user_id : int , github_username : str ) -> None :
85112 set_student_github_endpoint = f"{ self ._endpoint } /api/students/{ telegram_user_id } "
86113 async with aiohttp .ClientSession () as session :
87114 data = {
88115 "githubUsername" : github_username
89116 }
90- async with session .post (set_student_github_endpoint , json = data ) as res :
117+ async with session .put (set_student_github_endpoint , json = data ) as res :
91118 if res .status == 404 :
92119 raise StudentNotFoundError (telegram_user_id )
93120 content = await res .text (encoding = "utf-8" )
0 commit comments