
    k)i                        d Z ddlmZmZmZmZ ddlmZmZm	Z	m
Z
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mZ  e       Zej=                  d       ee      ddd ee      ddedede de dedeeef   fd       Z!ej=                  dd       e	d       ee       ee      ddededee   defd       Z"ej=                  d       ee       ee      d d!e dededeeef   fd"       Z#ejI                  d#       ed$       ed%&       ee       ee      d'd(e
d)edededeeef   f
d*       Z%ejI                  d+       ed$       ed%&       ee       ee      d,d-ee
   d)edededeeef   f
d.       Z&ejO                  d       ee       ee      d d!e dededeeef   fd/       Z(y)0z
Files router module.

This module provides API endpoints for file management operations including
upload, download, listing, and deletion of files.
    )ListDictAnyOptional)	APIRouterDependsQuery
UploadFileFileFormHTTPExceptionstatus)Session)Response)get_db)get_current_active_user)User)file_services)	FileTypes/       )dbidspageper_pagecurrent_userr   r   r   r   r   returnc                    K   	 t        j                  | ||dz
  |z  ||       d{   }|ddS 7 	# t        $ r)}t        t        j
                  t        |            d}~ww xY ww)z;
    List all available files for the requesting user.
    r   )r   r   skiplimit
created_byNz	File listdatamessagestatus_codedetail)r   list_user_files	Exceptionr   r   HTTP_400_BAD_REQUESTstr)r   r   r   r   r   responsees          S/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/src/apps/files/router.py
list_filesr1      sx     
&66!8x'#
 
 ![99
  
33q6
 	

s0   A(#3 13 A(3 	A%$A  A%%A(z	/downloadN)response_modelzPath of the file to download)description)filepathr   r   r4   c                    K   	 t        j                  || |      }|S # t        $ r)}t        t        j
                  t        |            d}~ww xY ww)z5
    Download a file by its path or storage key.
    )r   pathr   r'   N)r   download_file_by_pathr+   r   r   HTTP_404_NOT_FOUNDr-   )r4   r   r   r.   r/   s        r0   r7   r7   2   sU     	
 66|
  
11q6
 	

s$   A A	A$AAAz
/{file_id})r   r   file_idc                    K   	 t        j                  || |       d{   }|ddS 7 	# t        $ r)}t        t        j
                  t        |            d}~ww xY ww)z*
    Fetch a file resource by its ID.
    r   r9   r#   NzFile detailsr$   r'   )r   get_file_by_idr+   r   r   r8   r-   r9   r   r   r.   r/   s        r0   r<   r<   H   sg     	
&557|
 
 !^<<
  
11q6
 	

0   A + )+ A + 	A$AAA z/upload-one.document)default)file	file_typer   r   rA   rB   c                   K   	  G d d      } |t        |j                              }t        j                  || |||       d{   }|ddS 7 	# t        $ r)}t        t        j                  t        |            d}~ww xY ww)z-
    Upload a single file to the server.
    c                       e Zd ZdefdZy)*upload_single_file.<locals>.SimpleMerchantmerchant_idc                     || _         y NrF   selfrF   s     r0   __init__z3upload_single_file.<locals>.SimpleMerchant.__init__l   
    #.     N__name__
__module____qualname__r-   rL    rN   r0   SimpleMerchantrE   k       /C /rN   rT   )r   rA   rB   r#   merchantNzFile uploaded successfullyr$   r'   )r-   idr   upload_single_filer+   r   r   r,   )rA   rB   r   r   rT   rV   r.   r/   s           r0   rX   rX   ^   s     
	/ 	/
 "#loo"67&99#
 
 !-IJJ
  
33q6
 	

;   BAA AA BA 	B$A??BBz/upload-many)filesrB   r   r   rZ   c                   K   	  G d d      } |t        |j                              }t        j                  || |||       d{   }|ddS 7 	# t        $ r)}t        t        j                  t        |            d}~ww xY ww)z.
    Upload multiple files to the server.
    c                       e Zd ZdefdZy)-upload_multiple_files.<locals>.SimpleMerchantrF   c                     || _         y rH   rI   rJ   s     r0   rL   z6upload_multiple_files.<locals>.SimpleMerchant.__init__   rM   rN   NrO   rS   rN   r0   rT   r]      rU   rN   rT   )r   rZ   rB   r#   rV   NzFiles uploaded successfullyr$   r'   )r-   rW   r   upload_multiple_filesr+   r   r   r,   )rZ   rB   r   r   rT   rV   r.   r/   s           r0   r_   r_      s     
	/ 	/
 "#loo"67&<<#
 
 !-JKK
  
33q6
 	

rY   c                    K   	 t        j                  || |       d{   }|ddS 7 	# t        $ r)}t        t        j
                  t        |            d}~ww xY ww)z+
    Delete a file resource by its ID.
    r;   NzFile removed successfullyr$   r'   )r   delete_file_by_idr+   r   r   r8   r-   r=   s        r0   ra   ra      sh     	
&887|
 
 !-HII
  
11q6
 	

r>   ))__doc__typingr   r   r   r   fastapir   r   r	   r
   r   r   r   r   sqlalchemy.ormr   starlette.responsesr   src.core.databaser   src.apps.auth.utils.authr   src.apps.users.models.userr   src.apps.filesr   src.core.utils.enumsr   routergetr-   intr1   r7   r<   postrX   r_   deletera   rS   rN   r0   <module>rq      s   - , \ \ \ " ( $ < + ( *	 C &/ !89

 

 	

 
 
 
#s(^
 
6 K- &DE&/#*+B#C	

 	
 4.	

 
 .
* L &/ !89	

 	
 	

 
#s(^
 
* ] Cy*-&/ !89


 
 		

 
 
#s(^
 
D ^ #3i*-&/ !89


 
 		

 
 
#s(^
 
D | &/ !89	

 	
 	

 
#s(^
 
rN   