Cron_Admin/app/http/controllers/backend/cmd_controller.go

49 lines
1.3 KiB
Go

package backend
import (
"cron_admin/app/constants/errorcode"
"cron_admin/app/http/controllers"
"cron_admin/app/http/entities/backend"
"cron_admin/app/models/croncmdmodel"
cmd_services "cron_admin/app/services/cmd_service"
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
)
func CmdList(c *gin.Context) {
request := controllers.GetRequest(c).(*backend.CmdListRequest)
count, list, err := cmd_services.GetListByWhere(request, request.Page, request.Limit)
if err != nil {
controllers.HandRes(c, nil, errorcode.NotFound)
} else {
var (
cmdList = make([]backend.CmdListResponse, 0)
//userIdList []int
)
linq.From(list).SelectT(func(in croncmdmodel.CronCmd) (d backend.CmdListResponse) {
d.ResponseFromDb(in)
return d
}).ToSlice(&cmdList)
controllers.HandRes(c, gin.H{"data": cmdList, "count": count}, err)
}
}
func CmdAdd(c *gin.Context) {
request := controllers.GetRequest(c).(*backend.CmdAddRequest)
err := cmd_services.UserAdd(request)
controllers.HandRes(c, nil, err)
}
func CmdEdit(c *gin.Context) {
request := controllers.GetRequest(c).(*backend.CmdEditRequest)
err := cmd_services.UserEdit(request)
controllers.HandRes(c, nil, err)
}
func CmdDel(c *gin.Context) {
request := controllers.GetRequest(c).(*backend.CmdDeleteRequest)
err := cmd_services.UserDel(request)
controllers.HandRes(c, nil, err)
}