3030import PyMatcha .models .user_image as user_image
3131from PyMatcha .errors import ConflictError
3232from PyMatcha .errors import NotFoundError
33+ from PyMatcha .models .report import Report
3334from PyMatcha .models .tag import Tag
3435from PyMatcha .models .view import View
3536from PyMatcha .utils import create_user_table
@@ -208,27 +209,10 @@ def register(email: str, username: str, password: str, first_name: str, last_nam
208209 logging .debug ("New user {} created" .format (new_user .email ))
209210 return new_user
210211
211- def get_all_info (self ) -> Dict :
212- return {
213- "id" : self .id ,
214- "first_name" : self .first_name ,
215- "last_name" : self .last_name ,
216- "email" : self .email ,
217- "username" : self .username ,
218- "bio" : self .bio ,
219- "gender" : self .gender ,
220- "orientation" : self .orientation ,
221- "birthdate" : self .birthdate ,
222- "geohash" : self .geohash ,
223- "tags" : [t .name for t in self .get_tags ()],
224- "heat_score" : self .heat_score ,
225- "is_online" : self .is_online ,
226- "date_joined" : self .date_joined ,
227- "date_lastseen" : self .date_lastseen ,
228- "is_profile_completed" : self .is_profile_completed ,
229- "is_confirmed" : self .is_confirmed ,
230- "confirmed_on" : self .confirmed_on ,
231- }
212+ def to_dict (self ) -> Dict :
213+ returned_dict = super ().to_dict ()
214+ returned_dict ["tags" ] = [t .to_dict () for t in self .get_tags ()]
215+ return returned_dict
232216
233217 @classmethod
234218 def create_table (cls ):
@@ -254,7 +238,7 @@ def get_images(self) -> List[UserImage]:
254238 image_list .append (UserImage (image ))
255239 return image_list
256240
257- def get_base_info (self ):
241+ def get_jwt_info (self ):
258242 return {
259243 "id" : self .id ,
260244 "email" : self .email ,
@@ -302,6 +286,48 @@ def get_views(self):
302286 views_list .append (View (v ))
303287 return views_list
304288
289+ def get_reports_received (self ):
290+ logging .debug ("Getting all reports received for user {}" .format (self .id ))
291+ with self .db .cursor () as c :
292+ c .execute (
293+ """
294+ SELECT reports.id as id, reports.reported_id as reported_id,
295+ reports.reporter_id as reporter_id, reports.dt_reported as dt_reported,
296+ reports.details as details, reports.reason as reason, reports.status as status
297+ FROM users
298+ INNER JOIN reports on users.id = reports.reported_id
299+ WHERE users.id = CAST({} AS UNSIGNED)
300+ """ .format (
301+ self .id
302+ )
303+ )
304+ reports = c .fetchall ()
305+ reports_list = []
306+ for r in reports :
307+ reports_list .append (Report (r ))
308+ return reports_list
309+
310+ def get_reports_sent (self ):
311+ logging .debug ("Getting all reports sent for user {}" .format (self .id ))
312+ with self .db .cursor () as c :
313+ c .execute (
314+ """
315+ SELECT reports.id as id, reports.reported_id as reported_id,
316+ reports.reporter_id as reporter_id, reports.dt_reported as dt_reported,
317+ reports.details as details, reports.reason as reason, reports.status as status
318+ FROM users
319+ INNER JOIN reports on users.id = reports.reporter_id
320+ WHERE users.id = CAST({} AS UNSIGNED)
321+ """ .format (
322+ self .id
323+ )
324+ )
325+ reports = c .fetchall ()
326+ reports_list = []
327+ for r in reports :
328+ reports_list .append (Report (r ))
329+ return reports_list
330+
305331
306332def get_user (uid : Any [int , str ]) -> Optional [User ]:
307333 not_found = 0
0 commit comments