修复 「1.2.2 用户管理-用户列表勾选单一用户会全选 」 close #216
This commit is contained in:
@ -1,17 +1,21 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/repository"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func CommandCreateEndpoint(c echo.Context) error {
|
||||
type CommandApi struct{}
|
||||
|
||||
func (api CommandApi) CommandCreateEndpoint(c echo.Context) error {
|
||||
var item model.Command
|
||||
if err := c.Bind(&item); err != nil {
|
||||
return err
|
||||
@ -22,20 +26,23 @@ func CommandCreateEndpoint(c echo.Context) error {
|
||||
item.ID = utils.UUID()
|
||||
item.Created = utils.NowJsonTime()
|
||||
|
||||
if err := commandRepository.Create(&item); err != nil {
|
||||
if err := repository.CommandRepository.Create(context.TODO(), &item); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return Success(c, item)
|
||||
}
|
||||
|
||||
func CommandAllEndpoint(c echo.Context) error {
|
||||
func (api CommandApi) CommandAllEndpoint(c echo.Context) error {
|
||||
account, _ := GetCurrentAccount(c)
|
||||
items, _ := commandRepository.FindByUser(account)
|
||||
items, err := repository.CommandRepository.FindByUser(context.TODO(), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, items)
|
||||
}
|
||||
|
||||
func CommandPagingEndpoint(c echo.Context) error {
|
||||
func (api CommandApi) CommandPagingEndpoint(c echo.Context) error {
|
||||
pageIndex, _ := strconv.Atoi(c.QueryParam("pageIndex"))
|
||||
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
|
||||
name := c.QueryParam("name")
|
||||
@ -45,20 +52,20 @@ func CommandPagingEndpoint(c echo.Context) error {
|
||||
order := c.QueryParam("order")
|
||||
field := c.QueryParam("field")
|
||||
|
||||
items, total, err := commandRepository.Find(pageIndex, pageSize, name, content, order, field, account)
|
||||
items, total, err := repository.CommandRepository.Find(context.TODO(), pageIndex, pageSize, name, content, order, field, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return Success(c, H{
|
||||
return Success(c, Map{
|
||||
"total": total,
|
||||
"items": items,
|
||||
})
|
||||
}
|
||||
|
||||
func CommandUpdateEndpoint(c echo.Context) error {
|
||||
func (api CommandApi) CommandUpdateEndpoint(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
if err := PreCheckCommandPermission(c, id); err != nil {
|
||||
if err := api.PreCheckCommandPermission(c, id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -67,61 +74,57 @@ func CommandUpdateEndpoint(c echo.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := commandRepository.UpdateById(&item, id); err != nil {
|
||||
if err := repository.CommandRepository.UpdateById(context.TODO(), &item, id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
func CommandDeleteEndpoint(c echo.Context) error {
|
||||
func (api CommandApi) CommandDeleteEndpoint(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
split := strings.Split(id, ",")
|
||||
for i := range split {
|
||||
if err := PreCheckCommandPermission(c, split[i]); err != nil {
|
||||
if err := api.PreCheckCommandPermission(c, split[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := commandRepository.DeleteById(split[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
// 删除资产与用户的关系
|
||||
if err := resourceSharerRepository.DeleteResourceSharerByResourceId(split[i]); err != nil {
|
||||
if err := repository.CommandRepository.DeleteById(context.TODO(), split[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
func CommandGetEndpoint(c echo.Context) (err error) {
|
||||
func (api CommandApi) CommandGetEndpoint(c echo.Context) (err error) {
|
||||
id := c.Param("id")
|
||||
|
||||
if err := PreCheckCommandPermission(c, id); err != nil {
|
||||
if err := api.PreCheckCommandPermission(c, id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var item model.Command
|
||||
if item, err = commandRepository.FindById(id); err != nil {
|
||||
if item, err = repository.CommandRepository.FindById(context.TODO(), id); err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, item)
|
||||
}
|
||||
|
||||
func CommandChangeOwnerEndpoint(c echo.Context) (err error) {
|
||||
func (api CommandApi) CommandChangeOwnerEndpoint(c echo.Context) (err error) {
|
||||
id := c.Param("id")
|
||||
|
||||
if err := PreCheckCommandPermission(c, id); err != nil {
|
||||
if err := api.PreCheckCommandPermission(c, id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
owner := c.QueryParam("owner")
|
||||
if err := commandRepository.UpdateById(&model.Command{Owner: owner}, id); err != nil {
|
||||
if err := repository.CommandRepository.UpdateById(context.TODO(), &model.Command{Owner: owner}, id); err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, "")
|
||||
}
|
||||
|
||||
func PreCheckCommandPermission(c echo.Context, id string) error {
|
||||
item, err := commandRepository.FindById(id)
|
||||
func (api CommandApi) PreCheckCommandPermission(c echo.Context, id string) error {
|
||||
item, err := repository.CommandRepository.FindById(context.TODO(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user