teldrive/routes/upload.go

55 lines
935 B
Go
Raw Normal View History

2023-08-13 04:15:19 +08:00
package routes
import (
"net/http"
2023-08-16 05:53:02 +08:00
"github.com/divyam234/teldrive/database"
"github.com/divyam234/teldrive/services"
2023-08-13 04:15:19 +08:00
"github.com/gin-gonic/gin"
)
func addUploadRoutes(rg *gin.RouterGroup) {
r := rg.Group("/uploads")
r.Use(Authmiddleware)
2023-09-20 03:20:44 +08:00
uploadService := services.UploadService{Db: database.DB}
2023-08-13 04:15:19 +08:00
r.GET("/:id", func(c *gin.Context) {
res, err := uploadService.GetUploadFileById(c)
if err != nil {
c.AbortWithError(http.StatusNotFound, err.Error)
return
}
c.JSON(http.StatusOK, res)
})
r.POST("/:id", func(c *gin.Context) {
res, err := uploadService.UploadFile(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
})
r.DELETE("/:id", func(c *gin.Context) {
err := uploadService.DeleteUploadFile(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusOK, gin.H{"message": "upload deleted"})
})
}