From bdffd2d84027cd4d962419ed199fe4523bb8d557 Mon Sep 17 00:00:00 2001 From: naiba Date: Wed, 23 Oct 2024 17:34:15 +0800 Subject: [PATCH] feat: list server api --- cmd/dashboard/controller/controller.go | 1 + cmd/dashboard/controller/server.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index e60af66..089c601 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -72,6 +72,7 @@ func routers(r *gin.Engine) { auth.PATCH("/server-group/:id", commonHandler(updateServerGroup)) auth.POST("/batch-delete/server-group", commonHandler(batchDeleteServerGroup)) + auth.GET("/server", commonHandler(listServer)) auth.PATCH("/server/:id", commonHandler(updateServer)) auth.POST("/batch-delete/server", commonHandler(batchDeleteServer)) diff --git a/cmd/dashboard/controller/server.go b/cmd/dashboard/controller/server.go index 4672902..f2789c2 100644 --- a/cmd/dashboard/controller/server.go +++ b/cmd/dashboard/controller/server.go @@ -12,6 +12,26 @@ import ( "github.com/naiba/nezha/service/singleton" ) +// List server +// @Summary List server +// @Security BearerAuth +// @Schemes +// @Description List server +// @Tags auth required +// @Produce json +// @Success 200 {object} model.CommonResponse[any] +// @Router /server [get] +func listServer(c *gin.Context) error { + var servers []model.Server + if err := singleton.DB.Find(&servers).Error; err != nil { + return newGormError("%v", err) + } + c.JSON(http.StatusOK, model.CommonResponse[any]{ + Data: servers, + }) + return nil +} + // Edit server // @Summary Edit server // @Security BearerAuth