alexander1010 commited on
Commit
ca78935
verified
1 Parent(s): 0965c0c

update router delete

Browse files
src/expon/presentation/interfaces/rest/controllers/presentation_controller.py CHANGED
@@ -1,7 +1,7 @@
1
- from fastapi import APIRouter, UploadFile, File, Depends, HTTPException
2
  from sqlalchemy.orm import Session
3
- from starlette.datastructures import UploadFile as StarletteUploadFile
4
- from uuid import UUID # 馃憟 Agregado
5
 
6
  from src.expon.shared.infrastructure.dependencies import get_db
7
  from src.expon.iam.infrastructure.authorization.sfs.auth_bearer import get_current_user
@@ -67,6 +67,7 @@ def upload_presentation(
67
  except Exception as e:
68
  raise HTTPException(status_code=500, detail=f"Error al procesar el archivo: {str(e)}")
69
 
 
70
  @router.get("/summary", response_model=list[PresentationSummaryResponse])
71
  def get_presentations_summary(
72
  db: Session = Depends(get_db),
@@ -86,9 +87,10 @@ def get_presentations_summary(
86
  ) for p in presentations
87
  ]
88
 
 
89
  @router.get("/{presentation_id}", response_model=PresentationResponse)
90
  def get_presentation_by_id(
91
- presentation_id: UUID, # 馃憟 Cambiado de int a UUID
92
  db: Session = Depends(get_db),
93
  current_user=Depends(get_current_user)
94
  ):
@@ -115,3 +117,21 @@ def get_presentation_by_id(
115
  )
116
 
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter, UploadFile, File, Depends, HTTPException, status
2
  from sqlalchemy.orm import Session
3
+ from uuid import UUID
4
+ import os
5
 
6
  from src.expon.shared.infrastructure.dependencies import get_db
7
  from src.expon.iam.infrastructure.authorization.sfs.auth_bearer import get_current_user
 
67
  except Exception as e:
68
  raise HTTPException(status_code=500, detail=f"Error al procesar el archivo: {str(e)}")
69
 
70
+
71
  @router.get("/summary", response_model=list[PresentationSummaryResponse])
72
  def get_presentations_summary(
73
  db: Session = Depends(get_db),
 
87
  ) for p in presentations
88
  ]
89
 
90
+
91
  @router.get("/{presentation_id}", response_model=PresentationResponse)
92
  def get_presentation_by_id(
93
+ presentation_id: UUID,
94
  db: Session = Depends(get_db),
95
  current_user=Depends(get_current_user)
96
  ):
 
117
  )
118
 
119
 
120
+ @router.delete("/{presentation_id}", status_code=status.HTTP_204_NO_CONTENT)
121
+ def delete_presentation(
122
+ presentation_id: UUID,
123
+ db: Session = Depends(get_db),
124
+ current_user=Depends(get_current_user)
125
+ ):
126
+ repository = PresentationRepository(db)
127
+ presentation = repository.get_by_id_and_user(presentation_id, current_user.id)
128
+
129
+ if presentation is None:
130
+ raise HTTPException(status_code=404, detail="Presentaci贸n no encontrada")
131
+
132
+ # Eliminar archivo local
133
+ storage_service = LocalStorageService()
134
+ storage_service.delete(presentation.filename)
135
+
136
+ # Eliminar de base de datos
137
+ repository.delete(presentation)