o
    hx                     @   s  d dl mZmZmZ d dlm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 d dlZd dlmZ d d	lmZ e Ze Zejd
ddeeeejfdededefddZejdddeeeejfdedefddZedeeeejfde	dedefddZedeeeejfdedefddZ ejdeddeeeejfdededefddZ!dZ"d Z#ed!eefdefd"d#Z$dS )$    )	APIRouterDependsHTTPException)Session)AdminCreateAdminUpdateChangePasswordRequest)AdminService)get_db)
JWTManagerN)TblFullCourse)CustomResponsez/adminT)response_model_exclude_nonerequestdbtokenc                       t ||| I d H S N)r	   create_adminr   r   r    r   0/var/www/html/beacon-api/app/api/admin/router.pyr         r   z/admin/profilec                    s   t | | I d H S r   )r	   get_admin_profile)r   r   r   r   r   r      s   r   z/admin/change_passwordc                    r   r   )r	   change_passwordr   r   r   r   r      r   r   z/logoutc                    s"   | d}t| tdddS )Njti1zLogout successful.)statusmessage)getblacklisted_tokensaddr   )r   r   r   r   r   r   logout   s   

r"   z/admin/update)response_modelr   c                    r   r   )r	   update_adminr   r   r   r   r$   %   r   r$   z.https://lms.marinerskills.com/lmsmarinerskillsz$6598E51A-4C41-416C-821F-A50EBBBE4E99z/sync/full_course_listc              
   C   s   dt i}ztjt d|dd}|  W n tjy- } ztddt| dd }~ww | }g }|D ] }t	|
d|
d	|
d
|
dd}| | || q6|   d|iS )NKeyz/FullCourseList
   )jsontimeouti  zLMS API error: )status_codedetailProgramBatchCourseBatchCourseCode)programbatchcoursebatch_course_codestored_courses)API_KEYrequestspostLMS_BASE_URLraise_for_statusRequestExceptionr   strr'   r   r   mergeappendcommit)r   payloadrespedataresultsitemr1   r   r   r   sync_full_course_list0   s*   
rD   )%fastapir   r   r   sqlalchemy.ormr   app.api.admin.schemasr   r   r   app.api.admin.servicer	   app.database.main.mysqlr
   app.dependency.authanticationr   r5   app.models.main.full_coursesr   app.utils.schemas_utilsr   admin_routersetr    r6   verify_tokendictr   r   r   putr   r"   r$   r7   r4   rD   r   r   r   r   <module>   s2    ($($(