
    hh                        d dl mZmZmZ d dl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 d dlmZ d dlmZ  e       Zej+                  d	e
       ee      fdedefd       Zej1                  d	ee   
       ee      fdefd       Zej1                  de
       ee      fdedefd       Zej9                  de
       ee      fdededefd       Zej=                  de
       ee      fdedefd       Zy)    )	APIRouterDependsHTTPException)Pagepaginate)Session)List)CategoryCategoryCreate)r
   )check_token_validity)get_db )response_modelcategorydependenciesc                     |\  }}t        | j                        }|j                  |       |j                          |j	                  |       |S )N)name)CategoryModelr   addcommitrefresh)r   r   dbuserdb_categorys        M/Users/theessential/Documents/Github/Lekema-Backend/app/routers/categories.pycreate_categoryr      s@    HBX]]3KFF;IIKJJ{    c                 h    | \  }}|j                  t              j                         }t        |      S )N)queryr   allr   )r   r   r   
categoriess       r   read_categoriesr"      s-    HB-(,,.JJr   z/{category_id}category_idc                     |\  }}|j                  t              j                  t        j                  | k(        j	                         }|t        dd      |S Ni  zCategory not found)status_codedetail)r   r   filteridfirstr   r#   r   r   r   r   s        r   read_categoryr,      sR    HB((=)001A1A[1PQWWYK4HIIr   c                    |\  }}|j                  t              j                  t        j                  | k(        j	                         }|t        dd      |j                  |_        |j                          |j                  |       |S r%   )	r   r   r(   r)   r*   r   r   r   r   )r#   r   r   r   r   r   s         r   update_categoryr.   '   ss    HB((=)001A1A[1PQWWYK4HII}}KIIKJJ{r   c                     |\  }}|j                  t              j                  t        j                  | k(        j	                         }|t        dd      |j                  |       |j                          |S r%   )r   r   r(   r)   r*   r   deleter   r+   s        r   delete_categoryr1   3   sg    HB((=)001A1A[1PQWWYK4HIIIIkIIKr   N) fastapir   r   r   fastapi_paginationr   r   sqlalchemy.ormr   typingr	   app.schemas.categoryr
   r   app.models.categoryr   app.utils.authentificationr   app.utils.databaser   routerposttupler   getr"   intr,   putr.   r0   r1    r   r   <module>rA      sF   5 5 - "  9 9 ; %	 R)DKL`Da n E  * BX/+23G+H  5   0  X6:ABV:W s %  7 X6V]^rVs   e  7 9<CDX<Y  E  :r   