feat: 接入swagger功能

This commit is contained in:
TsMask
2025-01-07 17:12:35 +08:00
parent bbc2fe5900
commit 92f6ae8787
11 changed files with 1103 additions and 403 deletions

View File

@@ -25,6 +25,15 @@ type ChartGraphController struct {
// 获取关系图组名
//
// GET /groups
//
// @Tags chart
// @Accept json
// @Produce json
// @Success 200 {object} map[string]any "data"
// @Security ApiKeyAuth
// @Summary Get relationship graph group name
// @Description Get relationship graph group name
// @Router /chart/graph/groups [get]
func (s *ChartGraphController) GroupNames(c *gin.Context) {
data := s.chartGraphService.SelectGroup()
c.JSON(200, result.OkData(data))
@@ -33,6 +42,17 @@ func (s *ChartGraphController) GroupNames(c *gin.Context) {
// 获取关系图数据
//
// GET /
//
// @Tags chart
// @Accept json
// @Produce json
// @Param group query string true "Group"
// @Param type query string true "Type oneof=node edge combo" Enums(node, edge, combo)
// @Success 200 {object} map[string]any "data"
// @Security ApiKeyAuth
// @Summary Getting Relationship Map Data
// @Description Getting Relationship Map Data
// @Router /chart/graph [get]
func (s *ChartGraphController) Load(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var querys struct {
@@ -51,6 +71,16 @@ func (s *ChartGraphController) Load(c *gin.Context) {
// 保存关系图数据
//
// POST /
//
// @Tags chart
// @Accept json
// @Produce json
// @Param data body map[string]any true "{group:'',data:{nodes:[],edges:[],combos:[]}}"
// @Success 200 {object} map[string]any "data"
// @Security ApiKeyAuth
// @Summary Saving Relationship Diagram Data
// @Description Saving Relationship Diagram Data
// @Router /chart/graph/ [post]
func (s *ChartGraphController) Save(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
@@ -83,6 +113,16 @@ func (s *ChartGraphController) Save(c *gin.Context) {
// 删除关系图数据
//
// DELETE /:group
//
// @Tags chart
// @Accept json
// @Produce json
// @Param group path string true "Group"
// @Success 200 {object} map[string]any "data"
// @Security ApiKeyAuth
// @Summary Deleting Relationship Diagram Data
// @Description Deleting Relationship Diagram Data
// @Router /chart/graph/:group [delete]
func (s *ChartGraphController) Delete(c *gin.Context) {
language := ctx.AcceptLanguage(c)
group := c.Param("group")

View File

@@ -20,6 +20,14 @@ type IndexController struct{}
// 根路由
//
// GET /
//
// @Tags common
// @Accept json
// @Produce json
// @Success 200 {object} map[string]any "data"
// @Summary Root Route
// @Description Root Route
// @Router / [get]
func (s *IndexController) Handler(c *gin.Context) {
name := "OMC"
version := libGlobal.Version

View File

@@ -7,6 +7,8 @@ import (
"runtime"
"strings"
"github.com/gin-gonic/gin"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/file"
@@ -14,8 +16,6 @@ import (
"be.ems/src/framework/utils/ssh"
"be.ems/src/framework/vo/result"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeActionController 结构体
@@ -34,6 +34,15 @@ type NeActionController struct {
// 从本地到网元发送文件
//
// POST /pushFile
//
// @Tags network_element
// @Accept json
// @Produce json
// @Success 200 {object} map[string]any{} "data"
// @Security ApiKeyAuth
// @Summary Sending files from local to network elements
// @Description Sending files from local to network elements
// @Router /ne/action/pushFile [post]
func (s *NeActionController) PushFile(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
@@ -42,7 +51,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
UploadPath string `json:"uploadPath" binding:"required"`
DelTemp bool `json:"delTemp"` // 删除本地临时文件
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -331,7 +340,7 @@ func (s *NeActionController) Service(c *gin.Context) {
NeID string `json:"neId" binding:"required"`
Action string `json:"action" binding:"required,oneof=start restart stop reboot poweroff"` // 操作行为
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}