加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
user.go 4.85 KB
一键复制 编辑 原始数据 按行查看 历史
zbjlala 提交于 2020-01-15 17:00 . [add]rbac 权限管理
package main
//package v1
//
//import (
// "gin_management_system/pkg/app"
// "gin_management_system/pkg/e"
// "gin_management_system/pkg/setting"
// "gin_management_system/pkg/util"
// "gin_management_system/service/user_service"
// "github.com/astaxie/beego/validation"
// "github.com/gin-gonic/gin"
// "github.com/Unknwon/com"
// "net/http"
//)
//
//// @Summary Get multiple user
//// @Produce json
//// @Param name query string false "Name"
//// @Param state query int false "State"
//// @Param email query int false "Email"
//// @Success 200 {object} app.Response
//// @Failure 500 {object} app.Response
//// @Router /api/v1/users [get]
//func GetUsers(c *gin.Context) {
// appG := app.Gin{C: c}
// name := c.Query("name")
// state := -1
// if arg := c.Query("state"); arg != ""{
// state = com.StrTo(arg).MustInt()
// }
//
// userService := user_service.User{
// Name: name,
// State: state,
// PageNum: util.GetPage(c),
// PageSize: setting.AppSetting.PageSize,
// }
// users, err := userService.GetAll()
// if err != nil {
// appG.Response(http.StatusInternalServerError, e.ERROR_GET_USERS_FAIL, nil)
// return
// }
//
// count, err := userService.Count()
// if err != nil{
// appG.Response(http.StatusInternalServerError, e.ERROR_COUNT_USER_FAIL, nil)
// return
// }
//
// appG.Response(http.StatusOK, e.SUCCESS, map[string]interface{}{
// "lists": users,
// "total": count,
// })
//}
//
//type AddUserForm struct {
// Name string `form:"name" valid:"Required;MaxSize(100)"`
// Email string `form:"email" valid:"Required;MaxSize(100)"`
// State int `form:"state" valid:"Range(0,1)"`
//}
//
//// @Summary Add user
//// @Produce json
//// @Param name body string true "Name"
//// @Param state body int false "State"
//// @Param email body string false "Email"
//// @Success 200 {object} app.Response
//// @Failure 500 {object} app.Response
//// @Router /api/v1/users [post]
//func AddUser(c *gin.Context){
// var(
// appG = app.Gin{C: c}
// form AddUserForm
// )
//
// httpCode, errCode := app.BindAndValid(c, &form)
// if errCode != e.SUCCESS{
// appG.Response(httpCode, errCode, nil)
// return
// }
//
// userService := user_service.User{
// Name: form.Name,
// Email: form.Email,
// State: form.State,
// }
//
// err := userService.Add()
// if err != nil {
// appG.Response(http.StatusInternalServerError, e.ERROR_ADD_USER_FAIL, nil)
// return
// }
//
// appG.Response(http.StatusOK, e.SUCCESS, nil)
//}
//
//type EditUserForm struct {
// ID int `form:"id" valid:"Required;Min(1)"`
// Name string `form:"name" valid:"Required;MaxSize(100)"`
// Email string `form:"email" valid:"Required;MaxSize(100)"`
// State int `form:"state" valid:"Range(0,1)"`
//}
//// @Summary Update user
//// @Produce json
//// @Param id path int true "ID"
//// @Param name body string true "Name"
//// @Param state body int false "State"
//// @Param email body string false "Email"
//// @Success 200 {object} app.Response
//// @Failure 500 {object} app.Response
//// @Router /api/v1/users/{id} [put]
//func EditUser(c *gin.Context){
// var (
// appG = app.Gin{C:c}
// form = EditUserForm{ID: com.StrTo(c.Param("id")).MustInt()}
// )
//
// httpCode, errCode := app.BindAndValid(c, &form)
// if errCode != e.SUCCESS{
// appG.Response(httpCode, errCode, nil)
// return
// }
//
// userService := user_service.User{
// ID: form.ID,
// Name: form.Name,
// Email: form.Email,
// State: form.State,
// }
//
// exists, err := userService.ExistByID()
// if err != nil {
// appG.Response(http.StatusInternalServerError, e.ERROR_EXIST_USER_FAIL, nil)
// return
// }
//
// if !exists{
// appG.Response(http.StatusOK, e.ERROR_NOT_EXIST_USER, nil)
// return
// }
//
// err = userService.Edit()
// if err != nil {
// appG.Response(http.StatusInternalServerError, e.ERROR_EDIT_USER_FAIL, nil)
// return
// }
//
// appG.Response(http.StatusOK, e.SUCCESS, nil)
//}
//
//// @Summary Delete user
//// @Produce json
//// @Param id path int true "ID"
//// @Success 200 {object} app.Response
//// @Failure 500 {object} app.Response
//// @Router /api/v1/users/{id} [delete]
//func DeleteUser(c *gin.Context) {
// appG := app.Gin{C: c}
// valid := validation.Validation{}
// id := com.StrTo(c.Param("id")).MustInt()
// valid.Min(id, 1, "id").Message("ID必须大于0")
//
// if valid.HasErrors() {
// app.MarkErrors(valid.Errors)
// appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
// }
//
// userService := user_service.User{ID:id}
// exists, err := userService.ExistByID()
// if err != nil{
// appG.Response(http.StatusInternalServerError, e.ERROR_EXIST_TAG_FAIL, nil)
// return
// }
//
// if !exists {
// appG.Response(http.StatusOK, e.ERROR_NOT_EXIST_USER, nil)
// return
// }
//
// if err := userService.Delete(); err != nil{
// appG.Response(http.StatusInternalServerError, e.ERROR_DELETE_USER_FAIL, nil)
// return
// }
//
// appG.Response(http.StatusOK, e.SUCCESS, nil)
//}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化