
    Fh*                        d dl mZmZmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ de
j8                  defd	Zd
edede
j>                  fdZ dede!de!dedee
j>                     f
dZ"d
ede
jF                  dede
j>                  fdZ$d
ede
jF                  dede
j>                  fdZ%d
ededdfdZ&de
jN                  dede
jP                  fdZ)dedede
jP                  fdZ*d
edefdZ+dede
jX                  dede
jP                  fdZ-dededdfdZ.de
j^                  fdZ0de
jb                  defdZ2de
jf                  de
jh                  fd Z5d!d"l6m7Z7 ded#edefd$Z8y)%    )DependsHTTPExceptionstatus)Session)ListOptional)schema)create_calendar_post0get_calendar_posts_by_calendar_id_and_date_rangeget_post_types_by_post_idpartial_update_calendar_postget_calendar_post_by_idupdate_calendar_postdelete_calendar_postcreate_calendar_post_typeget_calendar_post_type_by_idupdate_calendar_post_typedelete_calendar_post_typegenerate_text_contentgenerate_image_contentget_url_info)get_db	post_datadbc                     	 t        ||       S # t        $ r}|d }~wt        $ r'}t        dt	        |             t        dd      d }~ww xY w)NzCreate calendar post error:  zInternal Server Errorstatus_codedetail)r
   r   	Exceptionprintstr)r   r   es      A/var/www/html/hubwallet-dev/src/marketing/apps/post/controller.pycreate_calendar_post_controllerr%      sR    M#B	22  M+SV44KLLMs    	AA"AApost_idreturnc                     	 t        ||       S # t        $ r}|d }~wt        $ r)}t        t        j                  t        |            d }~ww xY wNr   )r   r   r    r   HTTP_500_INTERNAL_SERVER_ERRORr"   r&   r   r#   s      r$   "get_calendar_post_by_id_controllerr,   ,   sO    ^&r733  ^(M(MVYZ[V\]]^s    	AA$A		Acalendar_id
start_dateend_datec                     	 t        || ||      }|st        t        j                  ddg d      |S # t        $ r}|d }~wt        $ r-}t        t        j
                  dt        |      g d      d }~ww xY w)NFz0No calendar posts found for the given date rangesuccessmessagedatar   )r   r   r   HTTP_404_NOT_FOUNDr    r*   r"   )r-   r.   r/   r   resultr#   s         r$   ;get_calendar_posts_by_calendar_id_and_date_range_controllerr7   O   s    
A"kS]_gh"55$Q    
== q6
 	

s   03 	A7>A7
(A22A7c                     	 t        || |      S # t        $ r}|d }~wt        $ r)}t        t        j                  t        |            d }~ww xY wr)   )r   r   r    r   r*   r"   r&   r   r   r#   s       r$   update_calendar_post_controllerr:   r   sQ    
^#B;;  ^(M(MVYZ[V\]]^    	AA$A

Ac                     	 t        | ||      S # t        $ r}|d }~wt        $ r)}t        t        j                  t        |            d }~ww xY wr)   )r   r   r    r   r*   r"   r9   s       r$   'partial_update_calendar_post_controllerr=      sQ    ^+GYCC  ^(M(MVYZ[V\]]^r;   Nc                     	 t        ||        y # t        $ r}|d }~wt        $ r)}t        t        j                  t        |            d }~ww xY wr)   )r   r   r    r   r*   r"   r+   s      r$   delete_calendar_post_controllerr?      sL    ^R)  ^(M(MVYZ[V\]]^r;   post_type_datac                     	 t        | |      S # t        $ r)}t        t        j                  t        |            d }~ww xY wr)   )r   r    r   r   r*   r"   )r@   r   r#   s      r$   $create_calendar_post_type_controllerrB      sA    ^(<< ^(M(MVYZ[V\]]^s    	A $;A post_type_idc                     	 t        ||       }|st        t        j                  ddd d      |S # t        $ r}|d }~wt        $ r)}t        t        j
                  t        |            d }~ww xY w)NFzCalendar post type not foundr1   r   )r   r   r   r5   r    r*   r"   )rC   r   r6   r#   s       r$   'get_calendar_post_type_by_id_controllerrE      s|    ^.r<@"55$=     ^(M(MVYZ[V\]]^s   .1 	A1<A1$A,,A1c                     	 t        ||       }|st        t        j                  ddg d      |S # t        $ r}|d }~wt        $ r}t        dt        |            d }~ww xY w)NFz)No post types found for the given post IDr1   r   r   )r   r   r   r5   r    r"   )r&   r   r6   r#   s       r$   -get_calendar_post_types_by_post_id_controllerrG      sp    <+B8"55$J    <CF;;<s   .1 	A#<A#AA#c                     	 t        || |      S # t        $ r}|d }~wt        $ r)}t        t        j                  t        |            d }~ww xY wr)   )r   r   r    r   r*   r"   )rC   r@   r   r#   s       r$   $update_calendar_post_type_controllerrI      sQ    
^(\>JJ  ^(M(MVYZ[V\]]^r;   c                     	 t        | |       y # t        $ r}|d }~wt        $ r)}t        t        j                  t        |            d }~ww xY wr)   )r   r   r    r   r*   r"   )rC   r   r#   s      r$   $delete_calendar_post_type_controllerrK      sL    ^!,r2  ^(M(MVYZ[V\]]^r;   request_datac                    	 | j                   st        t        j                  ddd d      | j                  r| j                  j                         st        t        j                  ddd d      t        |       S # t        $ r}|d }~wt        $ r)}t        t        j                  t        |            d }~ww xY w)NFpost_type is requiredr1   r   z*input_text is required and cannot be empty)
	post_typer   r   HTTP_400_BAD_REQUEST
input_textstripr   r    r*   r"   )rL   r#   s     r$   generate_text_controllerrS      s    
%%"77$6   &&l.E.E.K.K.M"77$K   %\22  
==q6
 	

s$   A:A= =	B=BB=$B88B=c                    	 | j                   st        t        j                  ddd d      | j                  r| j                  j                         st        t        j                  ddd d      t        | |      S # t        $ r}|d }~wt        $ r)}t        t        j                  t        |            d }~ww xY w)NFrN   r1   r   z+input_text is required for image generation)
rO   r   r   rP   rQ   rR   r   r    r*   r"   )rL   r   r#   s      r$   generate_image_controllerrU     s    
%%"77$6   &&l.E.E.K.K.M"77$L   &lB77  
==q6
 	

s$   A;A> >	B>B		B>$B99B>url_datac                     	 t        | j                        }|st        t        j                  ddd d      |S # t        $ r}|d }~wt
        $ r}t        dt        |            d }~ww xY w)NFz)input_url is required and cannot be emptyr1   r   r   )r   urlr   r   rP   r    r"   )rV   r6   r#   s      r$   	check_urlrY   8  sr    <x||,"77$J     <CF;;<s!   7: 	A,AA,A''A,   )delete_upload_photoimage_idc                 j    t        | ||      }|st        t        j                  ddd d      dddS )	N)r   r\   rC   FzImage not Foundr1   r   TzImage deleted successfully)r2   r3   )r[   r   r   r5   )r   r\   rC   delete_photo_services       r$   delete_uplod_photo_controllerr_   P  sK    ."hT`a11$0   35 5    )9fastapir   r   r   sqlalchemy.ormr   typingr   r   src.marketing.apps.postr	   src.marketing.apps.post.servicer
   r   r   r   r   r   r   r   r   r   r   r   r   r   src.utils.dbr   CalendarPostCreater%   intCalendarPostOutr,   r"   r7   CalendarPostUpdater:   r=   r?   CalendarPostTypeCreateCalendarPostTypeOutrB   rE   rG   CalendarPostTypeUpdaterI   rK   GenerateTextContentrS   GenerateImageContentrU   URLInfoRequestURLInfoResponserY   servicer[   r_    r`   r$   <module>rt      s~   2 2 " ! *   &  Mv/H/H Mg M	^	^	^ 	^F 
 
 
  
 		 

 
&
 
 ! 
F
^
^((
^ 	
^ 	
^^S ^VE^E^ ^dk ^pv  qG  qG ^	^	^	^ 
	^ ^11^^ ^^^^ ^.<3 <G <(
^
^11
^ 	
^ 	
^	^	^	^ 
	^"
6+E+E 
H
F,G,G 
W 
L<-- <&2H2H <( )5W 5c 5s 5r`   