修复 「1.2.2 用户管理-用户列表勾选单一用户会全选 」 close #216

This commit is contained in:
dushixiang
2022-01-23 17:53:22 +08:00
parent 29c066ca3a
commit d35b348a33
130 changed files with 5467 additions and 4554 deletions

View File

@ -1,47 +1,29 @@
package api
import (
"errors"
"fmt"
"context"
"next-terminal/server/model"
"next-terminal/server/repository"
"next-terminal/server/service"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
)
func PropertyGetEndpoint(c echo.Context) error {
properties := propertyRepository.FindAllMap()
type PropertyApi struct{}
func (api PropertyApi) PropertyGetEndpoint(c echo.Context) error {
properties := repository.PropertyRepository.FindAllMap(context.TODO())
return Success(c, properties)
}
func PropertyUpdateEndpoint(c echo.Context) error {
func (api PropertyApi) PropertyUpdateEndpoint(c echo.Context) error {
var item map[string]interface{}
if err := c.Bind(&item); err != nil {
return err
}
for key := range item {
value := fmt.Sprintf("%v", item[key])
if value == "" {
value = "-"
}
property := model.Property{
Name: key,
Value: value,
}
_, err := propertyRepository.FindByName(key)
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
if err := propertyRepository.Create(&property); err != nil {
return err
}
} else {
if err := propertyRepository.UpdateByName(&property, key); err != nil {
return err
}
}
if err := service.PropertyService.Update(item); err != nil {
return err
}
return Success(c, nil)
}