48 lines
1.8 KiB
Go
48 lines
1.8 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"
|
|
)
|
|
|
|
// ListGasBasic 查询可燃气体站分页列表。
|
|
func ListGasBasic(ctx *gin.Context) { listPage[models.GasBasic](ctx) }
|
|
|
|
// GetGasBasic 查询一个可燃气体站。
|
|
func GetGasBasic(ctx *gin.Context) { getByIdentity[models.GasBasic](ctx) }
|
|
|
|
// CreateGasBasic 创建可燃气体站档案。
|
|
func CreateGasBasic(ctx *gin.Context) {
|
|
var request models.GasBasic
|
|
if err := ctx.ShouldBindJSON(&request); err != nil || request.Code == "" || request.Name == "" {
|
|
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
|
return
|
|
}
|
|
request.Entity = newEntity("draft")
|
|
if err := impl.DBService.Create(&request).Error; err != nil {
|
|
infra.Response.Error(ctx, err)
|
|
return
|
|
}
|
|
respondCreatedResource(ctx, request)
|
|
}
|
|
|
|
// UpdateGasBasic 更新可燃气体站基础资料。
|
|
func UpdateGasBasic(ctx *gin.Context) {
|
|
var request struct {
|
|
Name string `json:"name" binding:"required,max=128"`
|
|
CreditCode string `json:"credit_code" binding:"max=64"`
|
|
Principal string `json:"principal" binding:"max=64"`
|
|
Address string `json:"address" binding:"max=255"`
|
|
Longitude string `json:"longitude" binding:"max=32"`
|
|
Latitude string `json:"latitude" binding:"max=32"`
|
|
}
|
|
if err := ctx.ShouldBindJSON(&request); err != nil {
|
|
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
|
return
|
|
}
|
|
updateAllowedByIdentity(ctx, &models.GasBasic{}, gin.H{"name": request.Name, "credit_code": request.CreditCode, "principal": request.Principal, "address": request.Address, "longitude": request.Longitude, "latitude": request.Latitude}, []string{"name", "credit_code", "principal", "address", "longitude", "latitude"})
|
|
}
|