1 Star 0 Fork 0

MinKo-U/keyauth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
user.go 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
MinKo-U 提交于 2022-11-20 16:16 . 修改包名
package api
import (
"github.com/emicklei/go-restful/v3"
"github.com/infraboard/mcube/http/response"
"gitee.com/MinKo-U/keyauth/apps/user"
)
func (h *handler) CreateUser(r *restful.Request, w *restful.Response) {
req := user.NewCreateUserRequest()
if err := r.ReadEntity(req); err != nil {
response.Failed(w.ResponseWriter, err)
return
}
h.log.Debug(req)
err := req.Validate()
if err != nil {
response.Failed(w.ResponseWriter, err)
return
}
set, err := h.service.CreateUser(r.Request.Context(), req)
if err != nil {
response.Failed(w.ResponseWriter, err)
return
}
response.Success(w.ResponseWriter, set)
}
func (h *handler) QueryUser(r *restful.Request, w *restful.Response) {
req := user.NewQueryUserRequestFromHTTP(r.Request)
set, err := h.service.QueryUser(r.Request.Context(), req)
if err != nil {
response.Failed(w.ResponseWriter, err)
return
}
response.Success(w.ResponseWriter, set)
}
func (h *handler) DescribeUser(r *restful.Request, w *restful.Response) {
req := user.NewDescribeUserRequest(r.PathParameter("id"))
ins, err := h.service.DescribeUser(r.Request.Context(), req)
if err != nil {
response.Failed(w.ResponseWriter, err)
return
}
response.Success(w.ResponseWriter, ins)
}
func (h *handler) UpdateUser(r *restful.Request, w *restful.Response) {
req := user.NewPutUserRequest(r.PathParameter("id"))
if err := r.ReadEntity(req.Data); err != nil {
response.Failed(w.ResponseWriter, err)
return
}
set, err := h.service.UpdateUser(r.Request.Context(), req)
if err != nil {
response.Failed(w.ResponseWriter, err)
return
}
response.Success(w.ResponseWriter, set)
}
func (h *handler) PatchUser(r *restful.Request, w *restful.Response) {
req := user.NewPatchUserRequest(r.PathParameter("id"))
h.log.Debugf("id:%s", req.Id)
if err := r.ReadEntity(req.Data); err != nil {
h.log.Debugf("data:%v", req)
response.Failed(w.ResponseWriter, err)
return
}
h.log.Debugf("data:%v", req)
set, err := h.service.UpdateUser(r.Request.Context(), req)
if err != nil {
response.Failed(w.ResponseWriter, err)
return
}
response.Success(w.ResponseWriter, set)
}
func (h *handler) DeleteUser(r *restful.Request, w *restful.Response) {
req := user.NewDeleteUserRequestWithID(r.PathParameter("id"))
set, err := h.service.DeleteUser(r.Request.Context(), req)
if err != nil {
response.Failed(w.ResponseWriter, err)
return
}
response.Success(w.ResponseWriter, set)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MinKo-U/keyauth.git
git@gitee.com:MinKo-U/keyauth.git
MinKo-U
keyauth
keyauth
v1.0.8

搜索帮助