
    h                     *   d dl Z d dlmZmZmZ d dlmZ d dlmZ d dl	m
Z
  e       Z e         e j                  dd      Zej                  d       ee      fd	ed
ee   defd       Zej                  d       ee      fded
ee   defd       Zy)    N)	APIRouterDependsHTTPException)"disable_installed_extensions_check)check_user_is_admin)modelsFILE_STORAGE_PATHfilesz&/programs/{program_id}/reorder-courses
program_idorderdependenciesc                   	 |\  }}|j                  t        j                        j                  t        j                  j                  | k(        j                         }|st        dd      |D cg c]  }|j                   }}t        |      t        |      k7  rt        dd      t        |      D ]   \  }	t        	fd|D              }||_        " |j                          ddiS c c}w )N  z!No courses found for this program  zInvalid course orderc              3   B   K   | ]  }|j                   k(  s|  y w)N)	course_id).0pcr   s     g/Users/theessential/Documents/Github/KofAcademy/kof-academy-backend/app/routers/admins/organisations.py	<genexpr>z"reorder_courses.<locals>.<genexpr>*   s     L",,)2K"Ls   messagezCourses reordered successfully)queryr   CourseProgramfilterr   allr   r   set	enumeratenextr   commit)
r   r   r   dbadminprogram_coursesr   pivot_course_idsindexr   s
            @r   reorder_coursesr%      s     IB hhv334 4 4 ? ?: MN  C!DEE 0????
5zS)**C!788 &e, yLLL IIK788 @s   0C*z$/courses/{course_id}/reorder-modulesr   c                    K   |\  }}|j                  t        j                        j                  t        j                  j                  | k(        j                         }|st        dd      |D cg c]  }|j                   }}t        |      t        |      k7  rt        dd      |D ci c]  }|j                  | }}t        |      D ]  \  }	}
|	||
   _
         |j                          ddiS c c}w c c}w w)Nr   z No modules found for this courser   zInvalid module orderr   zModules reordered successfully)r   r   Moduler   r   r   r   idr   r   r   r   )r   r   r   r    r!   modulesm
module_idsmodules_dictr$   	module_ids              r   reorder_modulesr.   1   s      IB hhv}}%,,V]]-D-D	-QRVVXGC!CDD '(1!$$(J( 5zS_$C!788 &--ADD!G-L- &e, .y(-Y%. IIK788! ) .s   A/C>1C4)C>-C9=C>)osfastapir   r   r   fastapi_pagination.utilsr   app.utils.authentificationr   appr   routergetenvr	   postintlisttupler%   r.        r   <module>r<      s    	 5 5 G :  
 " $BII17; 56 ""569999 9 798 34 ""569999 9 59r;   