o
    kg                     @   sN  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
 d dlmZ d dlmZ d dlmZ d dlZd d	lmZ e ZeeZG d
d de
ZG dd de
ZG dd de
Zejde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deejeejfdedefddZ!dS )    )	APIRouterDependsHTTPExceptionstatus)List)Session)	BaseModel)deps)NotificationResponse)NotificationServiceN)textc                   @      e Zd ZU eed< dS )MarkNotificationReadRequestnotification_idN__name__
__module____qualname__int__annotations__ r   r   */app/app/api/v1/endpoints/notifications.pyr         
 r   c                   @   r   )DeleteNotificationRequestr   Nr   r   r   r   r   r      r   r   c                   @   r   )SoftDeleteNotificationRequestr   Nr   r   r   r   r   r      r   r   /)response_modeldbc                 C   s   t | |j}|du rg S |S )z8
    Retrieve notifications for the logged-in user.
    N)r   get_notificationsid)r   current_usernotificationsr   r   r   get_user_notifications   s   r"   z
/mark-readreqc                 C   s2   t || j|j}|du rttjddt|S )z
    Update the read_at field of a given notification using the notification_id 
    provided in the body of a POST request.
    N(Notification not found or not authorizedstatus_codedetail)	r   mark_notification_as_readr   r   r   r   HTTP_404_NOT_FOUNDr
   from_orm)r#   r   r    updated_notificationr   r   r   mark_notification_read)   s   


r,   z/soft-deletec              
   C   s   z5t || j|j}|du rttjdd|tdd| ji	 }t
d|r+|d nd  t|W S  ty=     ty` } zt
jdt| d	d
 ttjdt| dd}~ww )un   
    알림을 소프트 삭제합니다 (실제 삭제하지 않고 data 필드에 삭제 정보 추가)
    Nr$   r%   z-SELECT data FROM notifications WHERE id = :idr   z!Verification query - Data field: r   zError in soft delete endpoint: T)exc_infozInternal server error: )r   soft_delete_notificationr   r   r   r   r)   executer   fetchoneloggerinfor
   r*   	ExceptionerrorstrHTTP_500_INTERNAL_SERVER_ERROR)r#   r   r    Zdeleted_notificationZverify_resulter   r   r   r.   =   s6   	
r.   )"fastapir   r   r   r   typingr   sqlalchemy.ormr   pydanticr   Zapp.apir	   app.schemas.notificationr
   !app.services.notification_servicer   logging
sqlalchemyr   router	getLoggerr   r1   r   r   r   getget_dbget_current_userr"   postr,   r.   r   r   r   r   <module>   sH   
