@@ -605,24 +605,41 @@ def get(self, user_id):
605605 ProjectUser .pinned == True ,
606606 Project .deleted == False
607607 ).all ()
608+
609+ # returns deleted projects
610+ # pagination_meta_data, projects = paginate(
611+ # user.projects, per_page, page)
608612
609- pagination_meta_data , projects = paginate (
610- user .projects , per_page , page )
611-
612- user_projects , errors = project_schema .dumps (
613- projects )
614-
613+ pagination = Project .query .filter (or_ (Project .owner_id == current_user_id , Project .users .any (
614+ ProjectUser .user_id == current_user_id ))).order_by (Project .date_created .desc ()).paginate (
615+ page = page , per_page = per_page , error_out = False )
616+
617+ projects = pagination .items
618+ if pagination :
619+ pagination_data = {
620+ 'total' : pagination .total ,
621+ 'pages' : pagination .pages ,
622+ 'page' : pagination .page ,
623+ 'per_page' : pagination .per_page ,
624+ 'next' : pagination .next_num ,
625+ 'prev' : pagination .prev_num
626+ }
627+
628+ user_projects , errors = project_schema .dumps (projects )
629+
615630 pinned_projects , errs = project_schema .dumps (pinned_projects )
616631
617- if errors and errs :
632+ parsed_pinned_projects = json .loads (pinned_projects )
633+
634+ if errors or errs :
618635 return dict (status = 'fail' , message = 'Internal server error' ), 500
619636
620637 return dict (
621638 status = 'success' ,
622639 data = dict (
623- pagination = {** pagination_meta_data ,
624- 'pinned_count' : len (pinned_projects )},
625- pinned = json . loads ( pinned_projects ) ,
640+ pagination = {** pagination_data ,
641+ 'pinned_count' : len (parsed_pinned_projects )},
642+ pinned = parsed_pinned_projects ,
626643 projects = json .loads (user_projects ),
627644 )
628645 ), 200
0 commit comments