package factura import ( "errors" "net/http" "strconv" "github.com/gin-gonic/gin" "gorm.io/gorm" dto_directors "repuestera_back/dto/Builders/Directors" r "repuestera_back/repositorios" ) func ObtenerFactura(c *gin.Context) { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "id inválido"}) return } factura, err := r.ObtenerRepositorios(c).Factura.ObtenerConRelaciones(uint(id)) if errors.Is(err, gorm.ErrRecordNotFound) { c.JSON(http.StatusNotFound, gin.H{"error": "factura no encontrada"}) return } if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } respuesta, err := dto_directors.NewFacturaDirector().DesdeFactura(factura) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, respuesta) }