85 lines
2.0 KiB
Go
85 lines
2.0 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"next-terminal/server/common"
|
|
"next-terminal/server/common/maps"
|
|
"next-terminal/server/model"
|
|
"next-terminal/server/repository"
|
|
"next-terminal/server/utils"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
type GatewayGroupApi struct{}
|
|
|
|
func (api GatewayGroupApi) AllEndpoint(c echo.Context) error {
|
|
items, err := repository.GatewayGroupRepository.FindAll(context.TODO())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return Success(c, items)
|
|
}
|
|
|
|
func (api GatewayGroupApi) PagingEndpoint(c echo.Context) error {
|
|
pageIndex, _ := strconv.Atoi(c.QueryParam("pageIndex"))
|
|
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
|
|
keyword := c.QueryParam("keyword")
|
|
|
|
items, total, err := repository.GatewayGroupRepository.Find(context.TODO(), pageIndex, pageSize, keyword)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return Success(c, maps.Map{
|
|
"total": total,
|
|
"items": items,
|
|
})
|
|
}
|
|
|
|
func (api GatewayGroupApi) CreateEndpoint(c echo.Context) error {
|
|
var item model.GatewayGroup
|
|
if err := c.Bind(&item); err != nil {
|
|
return err
|
|
}
|
|
item.ID = utils.UUID()
|
|
item.Created = common.NowJsonTime()
|
|
item.Updated = common.NowJsonTime()
|
|
|
|
if err := repository.GatewayGroupRepository.Create(context.TODO(), &item); err != nil {
|
|
return err
|
|
}
|
|
return Success(c, "")
|
|
}
|
|
|
|
func (api GatewayGroupApi) UpdateEndpoint(c echo.Context) error {
|
|
id := c.Param("id")
|
|
var item model.GatewayGroup
|
|
if err := c.Bind(&item); err != nil {
|
|
return err
|
|
}
|
|
item.Updated = common.NowJsonTime()
|
|
if err := repository.GatewayGroupRepository.UpdateById(context.TODO(), &item, id); err != nil {
|
|
return err
|
|
}
|
|
return Success(c, nil)
|
|
}
|
|
|
|
func (api GatewayGroupApi) DeleteEndpoint(c echo.Context) error {
|
|
id := c.Param("id")
|
|
if err := repository.GatewayGroupRepository.DeleteById(context.TODO(), id); err != nil {
|
|
return err
|
|
}
|
|
return Success(c, nil)
|
|
}
|
|
|
|
func (api GatewayGroupApi) GetEndpoint(c echo.Context) error {
|
|
id := c.Param("id")
|
|
item, err := repository.GatewayGroupRepository.FindById(context.TODO(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return Success(c, item)
|
|
}
|