o
    ׽g	                     @   s(  d dl mZmZmZmZ d dl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 e Zejdedeejeejfd	e
d
efddZejdedeejeejfd
efddZejdedeejeejfd	e
d
efddZejdejdeejeejfd
efddZdS )    )	APIRouterDependsHTTPExceptionstatus)Session)deps)CartItemCreateCartItemResponseShoppingCartResponse)shopping_cart_service)ShoppingCartz/add)response_modelreqdbc                 C   s   t ||j| j| j}|S )z
    Adds a product to the shopping cart of the logged-in user.
    If the cart does not exist, a new one is created, and if the product already exists, its quantity is updated.
    )r   add_item_to_cartid
product_idquantity)r   r   current_userZ	cart_item r   */app/app/api/v1/endpoints/shopping_cart.pyr   
   s   
r   /c                 C   s>   t | |j}|st|jd}| | |   | | |S )z
    Retrieves the shopping cart of the logged-in user.
    If the cart does not exist, an empty cart is created and returned.
    )user_id)r   Zget_user_cartr   r   addcommitrefresh)r   r   Zcartr   r   r   get_cart   s   	

r   z/removec                 C   s   t ||j| j}|S )zR
    Removes a specific product from the shopping cart of the logged-in user.
    )r   remove_item_from_cartr   r   )r   r   r   Zremoved_itemr   r   r   r   (   s   	r   z/clear)status_codec                 C   s   t | |j dS )u   
    쇼핑카트의 모든 아이템을 제거합니다.
    
    이 엔드포인트는:
    1. 사용자의 쇼핑카트를 찾습니다.
    2. 카트에 있는 모든 상품을 제거합니다.
    3. 성공 시 204 No Content를 반환합니다.
    N)r   
clear_cartr   )r   r   r   r   r   r   4   s   r   N)fastapir   r   r   r   sqlalchemy.ormr   Zapp.apir   Zapp.schemas.shopping_cartr   r	   r
   app.servicesr   Zapp.models.shopping_cartr   routerpostget_dbget_current_userr   getr   deleter   HTTP_204_NO_CONTENTr   r   r   r   r   <module>   sF    