package base
|
|
|
|
import (
|
|
"github.com/kataras/iris/v12"
|
|
"github.com/kataras/iris/v12/core/router"
|
|
model "leit.com/LAPP_GAAS_GFrame/models/base"
|
|
"leit.com/LAPP_GAAS_GFrame/web/middleware/jwts"
|
|
"leit.com/LAPP_GAAS_GFrame/web/models"
|
|
"leit.com/LAPP_GAAS_GFrame/web/supports"
|
|
)
|
|
|
|
func RegisterSelectCostCenter(party router.Party, path string, method func(map[string]string, *models.Usertab) (interface{}, error)) {
|
|
|
|
party.Get(path, func(ctx iris.Context) {
|
|
user, ok := jwts.ParseToken(ctx)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
result, err := method(ctx.URLParams(), user)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
supports.Ok(ctx, supports.OptionSuccess, result)
|
|
})
|
|
}
|
|
|
|
func RegisterInsertOneCostCenter(party router.Party, path string, method func(*models.Usertab, *model.CostCenter) error) {
|
|
|
|
party.Put(path, func(ctx iris.Context) {
|
|
user, ok := jwts.ParseToken(ctx)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
|
|
var err error = nil
|
|
|
|
entity := new(model.CostCenter)
|
|
if ctx.GetContentLength() > 0 {
|
|
err := ctx.ReadJSON(entity)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
} else {
|
|
entity = nil
|
|
}
|
|
|
|
err = method(user, entity)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
supports.Ok(ctx, supports.OptionSuccess, nil)
|
|
})
|
|
}
|
|
|
|
func RegisterDeleteOneCostCenter(party router.Party, path string, method func(*models.Usertab, string) error) {
|
|
|
|
party.Delete(path, func(ctx iris.Context) {
|
|
user, ok := jwts.ParseToken(ctx)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
|
|
var err error = nil
|
|
costCenterId := ctx.Params().GetString("costCenterId")
|
|
|
|
err = method(user, costCenterId)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
supports.Ok(ctx, supports.OptionSuccess, nil)
|
|
})
|
|
}
|
|
|
|
func RegisterSelectOneCostCenter(party router.Party, path string, method func(*models.Usertab, string) (*model.CostCenter, error)) {
|
|
|
|
party.Get(path+"/{costCenterId:string}", func(ctx iris.Context) {
|
|
user, ok := jwts.ParseToken(ctx)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
|
|
costCenterId := ctx.Params().GetString("costCenterId")
|
|
result, err := method(user, costCenterId)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
if result == nil {
|
|
supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil)
|
|
return
|
|
}
|
|
supports.Ok(ctx, supports.OptionSuccess, result)
|
|
})
|
|
}
|
|
|
|
func RegisterUpdateOneCostCenter(party router.Party, path string, method func(*models.Usertab, *model.CostCenter) error) {
|
|
|
|
party.Post(path, func(ctx iris.Context) {
|
|
user, ok := jwts.ParseToken(ctx)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
|
|
var err error = nil
|
|
|
|
entity := new(model.CostCenter)
|
|
if ctx.GetContentLength() > 0 {
|
|
err := ctx.ReadJSON(entity)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
} else {
|
|
entity = nil
|
|
}
|
|
|
|
err = method(user, entity)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
supports.Ok(ctx, supports.OptionSuccess, nil)
|
|
})
|
|
}
|