Cron_Admin/app/http/controllers/backend/user_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"
user_services "cron_admin/app/services/user_service"
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
)
func UserList(c *gin.Context) {
request := controllers.GetRequest(c).(*backend.UserListRequest)
count, list, err := user_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 UserAdd(c *gin.Context) {
request := controllers.GetRequest(c).(*backend.UserAddRequest)
err := user_services.UserAdd(request)
controllers.HandRes(c, nil, err)
}
func UserEdit(c *gin.Context) {
request := controllers.GetRequest(c).(*backend.UserEditRequest)
err := user_services.UserEdit(request)
controllers.HandRes(c, nil, err)
}
func UserDel(c *gin.Context) {
request := controllers.GetRequest(c).(*backend.UserDeleteRequest)
err := user_services.UserDel(request)
controllers.HandRes(c, nil, err)
}