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
35+ from PyMatcha .models .view import View
3436from PyMatcha .utils import create_user_table
3537from PyMatcha .utils import hash_password
3638from PyMatcha .utils .orm import Field
@@ -207,27 +209,13 @@ def register(email: str, username: str, password: str, first_name: str, last_nam
207209 logging .debug ("New user {} created" .format (new_user .email ))
208210 return new_user
209211
210- def get_all_info (self ) -> Dict :
211- return {
212- "id" : self .id ,
213- "first_name" : self .first_name ,
214- "last_name" : self .last_name ,
215- "email" : self .email ,
216- "username" : self .username ,
217- "bio" : self .bio ,
218- "gender" : self .gender ,
219- "orientation" : self .orientation ,
220- "birthdate" : self .birthdate ,
221- "geohash" : self .geohash ,
222- "tags" : [t .name for t in self .get_tags ()],
223- "heat_score" : self .heat_score ,
224- "is_online" : self .is_online ,
225- "date_joined" : self .date_joined ,
226- "date_lastseen" : self .date_lastseen ,
227- "is_profile_completed" : self .is_profile_completed ,
228- "is_confirmed" : self .is_confirmed ,
229- "confirmed_on" : self .confirmed_on ,
230- }
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+ returned_dict ["reports" ] = {"sent" : [], "received" : []}
216+ returned_dict ["reports" ]["sent" ] = [r .to_dict () for r in self .get_reports_sent ()]
217+ returned_dict ["reports" ]["received" ] = [r .to_dict () for r in self .get_reports_received ()]
218+ return returned_dict
231219
232220 @classmethod
233221 def create_table (cls ):
@@ -253,7 +241,7 @@ def get_images(self) -> List[UserImage]:
253241 image_list .append (UserImage (image ))
254242 return image_list
255243
256- def get_base_info (self ):
244+ def get_jwt_info (self ):
257245 return {
258246 "id" : self .id ,
259247 "email" : self .email ,
@@ -281,6 +269,68 @@ def get_tags(self):
281269 tags_list .append (Tag (t ))
282270 return tags_list
283271
272+ def get_views (self ):
273+ logging .debug ("Getting all views for user profile {}" .format (self .id ))
274+ with self .db .cursor () as c :
275+ c .execute (
276+ """
277+ SELECT views.id as id, views.profile_id as profile_id,
278+ views.viewer_id as viewer_id, views.dt_seen as dt_seen
279+ FROM users
280+ INNER JOIN views on users.id = views.profile_id
281+ WHERE users.id = CAST({} AS UNSIGNED)
282+ """ .format (
283+ self .id
284+ )
285+ )
286+ views = c .fetchall ()
287+ views_list = []
288+ for v in views :
289+ views_list .append (View (v ))
290+ return views_list
291+
292+ def get_reports_received (self ):
293+ logging .debug ("Getting all reports received for user {}" .format (self .id ))
294+ with self .db .cursor () as c :
295+ c .execute (
296+ """
297+ SELECT reports.id as id, reports.reported_id as reported_id,
298+ reports.reporter_id as reporter_id, reports.dt_reported as dt_reported,
299+ reports.details as details, reports.reason as reason, reports.status as status
300+ FROM users
301+ INNER JOIN reports on users.id = reports.reported_id
302+ WHERE users.id = CAST({} AS UNSIGNED)
303+ """ .format (
304+ self .id
305+ )
306+ )
307+ reports = c .fetchall ()
308+ reports_list = []
309+ for r in reports :
310+ reports_list .append (Report (r ))
311+ return reports_list
312+
313+ def get_reports_sent (self ):
314+ logging .debug ("Getting all reports sent for user {}" .format (self .id ))
315+ with self .db .cursor () as c :
316+ c .execute (
317+ """
318+ SELECT reports.id as id, reports.reported_id as reported_id,
319+ reports.reporter_id as reporter_id, reports.dt_reported as dt_reported,
320+ reports.details as details, reports.reason as reason, reports.status as status
321+ FROM users
322+ INNER JOIN reports on users.id = reports.reporter_id
323+ WHERE users.id = CAST({} AS UNSIGNED)
324+ """ .format (
325+ self .id
326+ )
327+ )
328+ reports = c .fetchall ()
329+ reports_list = []
330+ for r in reports :
331+ reports_list .append (Report (r ))
332+ return reports_list
333+
284334
285335def get_user (uid : Any [int , str ]) -> Optional [User ]:
286336 not_found = 0
0 commit comments