still fixing i40 vtl issue
This commit is contained in:
Binary file not shown.
@@ -175,3 +175,209 @@ func (h *Handler) ListClients(c *gin.Context) {
|
||||
"total": len(clients),
|
||||
})
|
||||
}
|
||||
|
||||
// GetDashboardStats returns dashboard statistics
|
||||
func (h *Handler) GetDashboardStats(c *gin.Context) {
|
||||
stats, err := h.service.GetDashboardStats(c.Request.Context())
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to get dashboard stats", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to get dashboard stats"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, stats)
|
||||
}
|
||||
|
||||
// ListStoragePools lists all storage pools
|
||||
func (h *Handler) ListStoragePools(c *gin.Context) {
|
||||
pools, err := h.service.ListStoragePools(c.Request.Context())
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to list storage pools", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list storage pools"})
|
||||
return
|
||||
}
|
||||
|
||||
if pools == nil {
|
||||
pools = []StoragePool{}
|
||||
}
|
||||
|
||||
h.logger.Info("Listed storage pools", "count", len(pools))
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"pools": pools,
|
||||
"total": len(pools),
|
||||
})
|
||||
}
|
||||
|
||||
// ListStorageVolumes lists all storage volumes
|
||||
func (h *Handler) ListStorageVolumes(c *gin.Context) {
|
||||
poolName := c.Query("pool_name")
|
||||
|
||||
volumes, err := h.service.ListStorageVolumes(c.Request.Context(), poolName)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to list storage volumes", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list storage volumes"})
|
||||
return
|
||||
}
|
||||
|
||||
if volumes == nil {
|
||||
volumes = []StorageVolume{}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"volumes": volumes,
|
||||
"total": len(volumes),
|
||||
})
|
||||
}
|
||||
|
||||
// ListStorageDaemons lists all storage daemons
|
||||
func (h *Handler) ListStorageDaemons(c *gin.Context) {
|
||||
daemons, err := h.service.ListStorageDaemons(c.Request.Context())
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to list storage daemons", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list storage daemons"})
|
||||
return
|
||||
}
|
||||
|
||||
if daemons == nil {
|
||||
daemons = []StorageDaemon{}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"daemons": daemons,
|
||||
"total": len(daemons),
|
||||
})
|
||||
}
|
||||
|
||||
// CreateStoragePool creates a new storage pool
|
||||
func (h *Handler) CreateStoragePool(c *gin.Context) {
|
||||
var req CreatePoolRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
pool, err := h.service.CreateStoragePool(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to create storage pool", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, pool)
|
||||
}
|
||||
|
||||
// DeleteStoragePool deletes a storage pool
|
||||
func (h *Handler) DeleteStoragePool(c *gin.Context) {
|
||||
idStr := c.Param("id")
|
||||
if idStr == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "pool ID is required"})
|
||||
return
|
||||
}
|
||||
|
||||
var poolID int
|
||||
if _, err := fmt.Sscanf(idStr, "%d", &poolID); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid pool ID"})
|
||||
return
|
||||
}
|
||||
|
||||
err := h.service.DeleteStoragePool(c.Request.Context(), poolID)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to delete storage pool", "error", err, "pool_id", poolID)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "pool deleted successfully"})
|
||||
}
|
||||
|
||||
// CreateStorageVolume creates a new storage volume
|
||||
func (h *Handler) CreateStorageVolume(c *gin.Context) {
|
||||
var req CreateVolumeRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
volume, err := h.service.CreateStorageVolume(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to create storage volume", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, volume)
|
||||
}
|
||||
|
||||
// UpdateStorageVolume updates a storage volume
|
||||
func (h *Handler) UpdateStorageVolume(c *gin.Context) {
|
||||
idStr := c.Param("id")
|
||||
if idStr == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "volume ID is required"})
|
||||
return
|
||||
}
|
||||
|
||||
var volumeID int
|
||||
if _, err := fmt.Sscanf(idStr, "%d", &volumeID); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid volume ID"})
|
||||
return
|
||||
}
|
||||
|
||||
var req UpdateVolumeRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
volume, err := h.service.UpdateStorageVolume(c.Request.Context(), volumeID, req)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to update storage volume", "error", err, "volume_id", volumeID)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, volume)
|
||||
}
|
||||
|
||||
// DeleteStorageVolume deletes a storage volume
|
||||
func (h *Handler) DeleteStorageVolume(c *gin.Context) {
|
||||
idStr := c.Param("id")
|
||||
if idStr == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "volume ID is required"})
|
||||
return
|
||||
}
|
||||
|
||||
var volumeID int
|
||||
if _, err := fmt.Sscanf(idStr, "%d", &volumeID); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid volume ID"})
|
||||
return
|
||||
}
|
||||
|
||||
err := h.service.DeleteStorageVolume(c.Request.Context(), volumeID)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to delete storage volume", "error", err, "volume_id", volumeID)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "volume deleted successfully"})
|
||||
}
|
||||
|
||||
// ListMedia lists all media from bconsole "list media" command
|
||||
func (h *Handler) ListMedia(c *gin.Context) {
|
||||
media, err := h.service.ListMedia(c.Request.Context())
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to list media", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if media == nil {
|
||||
media = []Media{}
|
||||
}
|
||||
|
||||
h.logger.Info("Listed media", "count", len(media))
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"media": media,
|
||||
"total": len(media),
|
||||
})
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -346,10 +346,20 @@ func NewRouter(cfg *config.Config, db *database.DB, log *logger.Logger) *gin.Eng
|
||||
backupGroup := protected.Group("/backup")
|
||||
backupGroup.Use(requirePermission("backup", "read"))
|
||||
{
|
||||
backupGroup.GET("/dashboard/stats", backupHandler.GetDashboardStats)
|
||||
backupGroup.GET("/jobs", backupHandler.ListJobs)
|
||||
backupGroup.GET("/jobs/:id", backupHandler.GetJob)
|
||||
backupGroup.POST("/jobs", requirePermission("backup", "write"), backupHandler.CreateJob)
|
||||
backupGroup.GET("/clients", backupHandler.ListClients)
|
||||
backupGroup.GET("/storage/pools", backupHandler.ListStoragePools)
|
||||
backupGroup.POST("/storage/pools", requirePermission("backup", "write"), backupHandler.CreateStoragePool)
|
||||
backupGroup.DELETE("/storage/pools/:id", requirePermission("backup", "write"), backupHandler.DeleteStoragePool)
|
||||
backupGroup.GET("/storage/volumes", backupHandler.ListStorageVolumes)
|
||||
backupGroup.POST("/storage/volumes", requirePermission("backup", "write"), backupHandler.CreateStorageVolume)
|
||||
backupGroup.PUT("/storage/volumes/:id", requirePermission("backup", "write"), backupHandler.UpdateStorageVolume)
|
||||
backupGroup.DELETE("/storage/volumes/:id", requirePermission("backup", "write"), backupHandler.DeleteStorageVolume)
|
||||
backupGroup.GET("/media", backupHandler.ListMedia)
|
||||
backupGroup.GET("/storage/daemons", backupHandler.ListStorageDaemons)
|
||||
backupGroup.POST("/console/execute", requirePermission("backup", "write"), backupHandler.ExecuteBconsoleCommand)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user