API and Database Deployment Update
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"clickploy/internal/db"
|
||||
"clickploy/internal/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (h *Handler) RegisterAdminRoutes(r *gin.Engine) {
|
||||
admin := r.Group("/api/admin", AuthMiddleware(), AdminMiddleware())
|
||||
{
|
||||
@@ -17,7 +13,6 @@ func (h *Handler) RegisterAdminRoutes(r *gin.Engine) {
|
||||
admin.GET("/stats", h.adminGetStats)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) adminListUsers(c *gin.Context) {
|
||||
var users []models.User
|
||||
if err := db.DB.Preload("Projects").Find(&users).Error; err != nil {
|
||||
@@ -26,7 +21,6 @@ func (h *Handler) adminListUsers(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
||||
func (h *Handler) adminDeleteUser(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if err := db.DB.Where("id = ?", id).Delete(&models.User{}).Error; err != nil {
|
||||
@@ -35,16 +29,13 @@ func (h *Handler) adminDeleteUser(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "deleted"})
|
||||
}
|
||||
|
||||
func (h *Handler) adminGetStats(c *gin.Context) {
|
||||
var userCount int64
|
||||
var projectCount int64
|
||||
var deploymentCount int64
|
||||
|
||||
db.DB.Model(&models.User{}).Count(&userCount)
|
||||
db.DB.Model(&models.Project{}).Count(&projectCount)
|
||||
db.DB.Model(&models.Deployment{}).Count(&deploymentCount)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"users": userCount,
|
||||
"projects": projectCount,
|
||||
|
||||
Reference in New Issue
Block a user