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

45 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/cronusermodel"
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 {
ulist := make([]backend.UserListResponse, 0)
linq.From(list).SelectT(func(in cronusermodel.CronUser) (d backend.UserListResponse) {
d.ResponseFromDb(in)
return d
}).ToSlice(&ulist)
controllers.HandRes(c, gin.H{"data": ulist, "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)
}