
    =h                         d dl m Z mZ d dlmZ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mZ d dlmZmZ d dlmZ d d	lmZmZ d d
lmZmZmZmZmZ  eddg      Zej?                  dej@                  e      edededefd              Z!ejE                  dejF                  e      e ed d        eddd      fdedede$de$fd              Z%ejM                  dejF                  e      de$dedefd       Z'y )!    )datetimetimezone)OptionalList)	APIRouterQuerystatus)UserRepository)SpecialHolidayRepository)CreateHolidayRequestSpecialHolidayResponseSchema)handles_authenticationuser_dependency)db_dependency)NotFoundExceptionAuthenticationError)ResponseObjectResponseModelListResponseModelBaseResponseModelErrorResponseModelz/api/holidayszSpecial Holidays)prefixtagsz/create)status_coderesponse_modeluserrequestdbc                 <  K   t        |      }t        |      }|j                  | j                  d      d       d {   } | r| j                  st        d      |j                  | j                  |j                         d {   }|rt        j                  d      S |j                  | j                  |j                  |j                         d {   }|j                  |j                  |j                  d}t        j                  |d	      S 7 7 7 Bw)
NemailFconvert_to_entityCompanyz'A holiday already exists for this date.)message)
company_idholiday_datename)iddater'   Holiday)r
   r   get_by_emailgetdefault_companyr   get_by_company_and_dater)   r   postcreate_holidayr'   r(   )r   r   r   	user_repoholiday_repoexistingcreated_holidayret_holidays           D/var/www/html/phonemate/phone_mate_backend/app/api/holiday_router.pyr0   r0      s     r"I+B/L''(9U'SSDt++	** "99$:N:NPWP\P\]]H}}%NOO(77''\\\\ 8  O   $$$$K
 ==i00) T
 ^s5   <DDADDADD?DDDz	/read_all)ge
      d   )r7   lestartlimitc                 L  K   t        |      }t        |      }|j                  | j                  d      d       d {   } | r| j                  st        d      |j                  | j                  ||       d {   }t        j                  d|d   ||d         S 7 a7 %w)	Nr    Fr!   r#   Holidaysdatatotal_count)r'   
collection	page_sizetotal)	r
   r   r+   r,   r-   r   get_by_companyr   get_list)r   r   r<   r=   r1   r2   results          r6   get_holidaysrH   .   s      r"I+B/L''(9U'SSDt++	**..t/C/CUERRF&>]#	  T Ss!   <B$B =B$<B"=$B$"B$z/{holiday_id}
holiday_idc                 d  K   |t         t        |      }t        |      }|j                  |j	                  d      d       d {   }|r|j
                  st        d      |j                  | |j
                         d {   }|st        d      t        j                  d      S 7 e7 )w)Nr    Fr!   r#   )rI   r%   r*   )r'   )
r   r
   r   r+   r,   r-   r   delete_holidayr   delete)rI   r   r   r1   r2   deleted_holidays         r6   rK   rK   F   s      |!!r"I+B/L''(9U'SSDt++	**(77:Z^ZnZn7ooO	**??	** T ps$   AB0B,=B0B.(B0.B0N)(r   r   typingr   r   fastapir   r   r	   repositories.user_repositoryr
   'repositories.special_holiday_repositoryr   schemas.holidayr   r   utils.auth_dependencyr   r   utils.databaser   utils.exceptionsr   r   utils.responser   r   r   r   r   routerr/   HTTP_201_CREATEDr0   r,   HTTP_200_OKintrH   rL   rK        r6   <module>r]      s6   ' ! , , 7 L N I ( C r r	/1C0D	E YF$;$;L_`1 19M 1S` 1  a16 KV%7%7HYZ qQraC(	
  	  [, F,>,>O`a++
+ 	+ b+r\   