46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package platform
|
|
|
|
import (
|
|
"git.apinb.com/bsm-sdk/core/errcode"
|
|
"git.apinb.com/bsm-sdk/core/infra"
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// ListUser 查询业主客户分页列表。
|
|
func ListUser(ctx *gin.Context) { listPage[models.UserAccount](ctx) }
|
|
|
|
// GetUser 查询一个业主客户档案。
|
|
func GetUser(ctx *gin.Context) { getByIdentity[models.UserAccount](ctx) }
|
|
|
|
// CreateUser 创建业主客户档案。
|
|
func CreateUser(ctx *gin.Context) {
|
|
var request models.UserAccount
|
|
if err := ctx.ShouldBindJSON(&request); err != nil || request.Name == "" {
|
|
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
|
return
|
|
}
|
|
request.Entity = newEntity("enabled")
|
|
if err := impl.DBService.Create(&request).Error; err != nil {
|
|
infra.Response.Error(ctx, err)
|
|
return
|
|
}
|
|
infra.Response.Success(ctx, request)
|
|
}
|
|
|
|
// UpdateUser 更新业主客户档案。
|
|
func UpdateUser(ctx *gin.Context) {
|
|
var request struct {
|
|
Name string `json:"name" binding:"required,max=64"`
|
|
Phone string `json:"phone" binding:"max=32"`
|
|
Avatar string `json:"avatar" binding:"max=512"`
|
|
RealName string `json:"real_name" binding:"max=64"`
|
|
}
|
|
if err := ctx.ShouldBindJSON(&request); err != nil {
|
|
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
|
return
|
|
}
|
|
updateByIdentity(ctx, &models.UserAccount{}, gin.H{"name": request.Name, "phone": request.Phone, "avatar": request.Avatar, "real_name": request.RealName})
|
|
}
|