feat:完善项目信息
This commit is contained in:
@ -12,36 +12,6 @@ import (
|
||||
|
||||
type Account struct{}
|
||||
|
||||
/**
|
||||
* @apiDefine Account 账号管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {post} /api/account/login 账号登录
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName AccountLogin
|
||||
* @apiGroup Account
|
||||
*
|
||||
* @apiHeader {string} x-equipment 设备平台(Web,H5,App)
|
||||
*
|
||||
* @apiParam {String} account 登录账号
|
||||
* @apiParam {String} password 登录密码
|
||||
* @apiParam {Json} captcha 验证码信息
|
||||
* @apiParam {String} captcha.key 验证key
|
||||
* @apiParam {String} captcha.value 验证value
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {String} data token
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNjE3NDU2OTMwIiwiaWF0IjoiMTYxNjg1MjEzMCIsInVpZCI6IjIwMTMxMTI4MTMwMTg0MTkyMDAifQ.D7oSD4OGdz8rJt0rFNVEl5Ea47_vtuC51IDrY9mUTPo"
|
||||
* }
|
||||
*/
|
||||
func (a *Account) Login(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||
@ -50,7 +20,7 @@ func (a *Account) Login(c *gin.Context) {
|
||||
Captcha string `json:"captcha" form:"captcha"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewAccount()(nil, api.GetTenantID()(c).(uint64)).Login(form.Mode, &controller.AccountLoginParams{
|
||||
@ -59,25 +29,6 @@ func (a *Account) Login(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/account/logout 账号退出
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName AccountLogout
|
||||
* @apiGroup Account
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Account) Logout(c *gin.Context) {
|
||||
// 因跳过中间键,故只能自己去获取token用户信息
|
||||
token := c.GetHeader(config.APIRequestToken)
|
||||
|
@ -2,57 +2,15 @@ package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/auth"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Auth struct{}
|
||||
|
||||
/**
|
||||
* @apiDefine Auth 权限管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {get} /api/auth/list 权限列表
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName AuthList
|
||||
* @apiGroup Auth
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id ID
|
||||
* @apiSuccess (200) {Number} data.kind_title 权限类型名称
|
||||
* @apiSuccess (200) {String} data.kind 权限类型
|
||||
* @apiSuccess (200) {String} data.name 权限名称
|
||||
* @apiSuccess (200) {String} data.auth 权限信息
|
||||
* @apiSuccess (200) {String} data.remark 备注信息
|
||||
* @apiSuccess (200) {Array} data.children 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": {
|
||||
* {
|
||||
* "id": 1,
|
||||
* "kind": 1,
|
||||
* "name": "测试",
|
||||
* "auth": "",
|
||||
* "remark": "",
|
||||
* "created_at": "2021-09-15T13:59:35+08:00",
|
||||
* "updated_at": "2021-09-15T13:59:35+08:00",
|
||||
* "kind_title": "模块",
|
||||
* "children": []
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
func (a *Auth) List(c *gin.Context) {
|
||||
data, err := auth.NewInstance()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
func (*Auth) Index(c *gin.Context) {
|
||||
data, err := auth.NewInstance()(api.GetSession()(c).(*session.Admin)).Index()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -1,108 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/logger"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
SuccessCode = 200 //成功的状态码
|
||||
FailureCode = 999 //失败的状态码
|
||||
)
|
||||
|
||||
type response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type ApiHandle func(c *gin.Context, syslog ...bool) interface{}
|
||||
|
||||
func (c ApiHandle) SysLog() {
|
||||
fmt.Println(123)
|
||||
//service.Publish(config.EventForSysLogProduce, _session.Community, _session.UID, _session.Name, mode, event, content,
|
||||
// c.Get("params"), c.ClientIP())
|
||||
}
|
||||
|
||||
func getSession() ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
value, _ := c.Get(config.TokenForSession)
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
func bind(req interface{}) ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
var err error
|
||||
|
||||
if c.Request.Method == "GET" {
|
||||
err = c.ShouldBindQuery(req)
|
||||
} else {
|
||||
err = c.ShouldBindBodyWith(req, binding.JSON)
|
||||
}
|
||||
if err != nil {
|
||||
logger.ErrorF("Request URL【%s】Params Bind Error:%v", c.Request.URL, err)
|
||||
return errors.New("参数异常/缺失")
|
||||
}
|
||||
c.Set("params", utils.AnyToJSON(req))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APISuccess(data ...interface{}) ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
resp := &response{
|
||||
Code: SuccessCode,
|
||||
Message: "ok",
|
||||
}
|
||||
if len(data) > 0 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APIFailure(err error) ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
resp := &response{
|
||||
Code: FailureCode,
|
||||
Message: "failure",
|
||||
}
|
||||
if err != nil {
|
||||
resp.Message = err.Error()
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
c.Abort()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APIResponse(err error, data ...interface{}) ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
resp := &response{
|
||||
Code: SuccessCode,
|
||||
Message: "ok",
|
||||
}
|
||||
if err != nil {
|
||||
resp.Code = FailureCode
|
||||
resp.Message = err.Error()
|
||||
c.JSON(http.StatusOK, resp)
|
||||
c.Abort()
|
||||
return nil
|
||||
}
|
||||
if len(data) > 0 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return nil
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -11,7 +11,7 @@ type Config struct{}
|
||||
func (a *Config) Index(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
pageForm
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
|
@ -2,7 +2,8 @@ package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -12,12 +13,12 @@ type Log struct{}
|
||||
func (a *Log) Login(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
pageForm
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewLog()(getSession()(c).(*service.Session)).Login(form.Name, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
data, err := controller.NewLog()(api.GetSession()(c).(*session.Admin)).Login(form.Name, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -20,8 +21,8 @@ type (
|
||||
)
|
||||
|
||||
// handle 审核处理
|
||||
func (a *manageExamineForm) handle(session *service.Session, local string) error {
|
||||
return manage.NewExamine()(session, local).Launch(a.Convert(), a.Identity, a.Status)
|
||||
func (a *manageExamineForm) handle(session *session.Admin) error {
|
||||
return manage.NewExamine()(session).Launch(a.Convert(), a.Identity, a.Status)
|
||||
}
|
||||
|
||||
func (*Manage) Company(c *gin.Context) {
|
||||
@ -36,7 +37,7 @@ func (*Manage) CompanyExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForCompany
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ func (*Manage) ExpertExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForExpert
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -79,7 +80,7 @@ func (*Manage) LaboratoryExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForLaboratory
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -95,7 +96,7 @@ func (*Manage) ResearchExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForResearch
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -111,6 +112,6 @@ func (*Manage) AgentExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForAgent
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func (a *Menu) Status(c *gin.Context) {
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Status(form.Convert(), form.Status)
|
||||
|
@ -3,7 +3,6 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/role"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -85,50 +84,60 @@ func (*Role) Delete(c *gin.Context) {
|
||||
|
||||
func (*Role) Menu(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
RoleID string `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role.NewMenu()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
data, err := role.NewMenu()(api.GetSession()(c).(*session.Admin)).Index((&api.IDStringForm{ID: form.RoleID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Role) MenuBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
RoleID string `json:"role_id" form:"role_id" binding:"required"`
|
||||
MenuIDs []string `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewMenu()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.MenuIDs)
|
||||
APIResponse(err)(c)
|
||||
menuIDs := make([]uint64, 0)
|
||||
|
||||
for _, v := range form.MenuIDs {
|
||||
menuIDs = append(menuIDs, (&api.IDStringForm{ID: v}).Convert())
|
||||
}
|
||||
err := role.NewMenu()(api.GetSession()(c).(*session.Admin)).Bind((&api.IDStringForm{ID: form.RoleID}).Convert(), menuIDs)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Role) Auth(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
RoleID string `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role.NewAuth()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
data, err := role.NewAuth()(api.GetSession()(c).(*session.Admin)).Index((&api.IDStringForm{ID: form.RoleID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Role) AuthBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"`
|
||||
RoleID string `json:"role_id" form:"role_id" binding:"required"`
|
||||
AuthIDs []string `json:"auth_ids" form:"auth_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewAuth()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.AuthIDs)
|
||||
APIResponse(err)(c)
|
||||
authIDs := make([]uint64, 0)
|
||||
|
||||
for _, v := range form.AuthIDs {
|
||||
authIDs = append(authIDs, (&api.IDStringForm{ID: v}).Convert())
|
||||
}
|
||||
err := role.NewAuth()(api.GetSession()(c).(*session.Admin)).Bind((&api.IDStringForm{ID: form.RoleID}).Convert(), authIDs)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type idForm struct {
|
||||
ID uint64 `json:"id" form:"id" binding:"required"`
|
||||
}
|
||||
|
||||
type uidForm struct {
|
||||
UID string `json:"uid" form:"uid" binding:"required"`
|
||||
}
|
||||
|
||||
func (this *uidForm) Convert() uint64 {
|
||||
return utils.StringToUnit64(this.UID)
|
||||
}
|
||||
|
||||
type imageForm struct {
|
||||
Image string `json:"image" form:"image"`
|
||||
}
|
||||
|
||||
func (this *imageForm) FilterImageURL() string {
|
||||
return strings.Replace(this.Image, config.SettingInfo.Domain, "", -1)
|
||||
}
|
||||
|
||||
type positionForm struct {
|
||||
Longitude float64 `json:"longitude" form:"longitude" binding:"required"`
|
||||
Latitude float64 `json:"latitude" form:"latitude" binding:"required"`
|
||||
}
|
||||
|
||||
type pageForm struct {
|
||||
Page int `json:"current" form:"current" binding:"required"`
|
||||
PageSize int `json:"pageSize" form:"pageSize" binding:"required"`
|
||||
}
|
@ -4,7 +4,6 @@ import (
|
||||
"SciencesServer/app/api/admin/controller/tenant"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -20,7 +19,7 @@ type (
|
||||
Contact string `json:"contact" form:"contact" binding:"required"` // 联系人
|
||||
ContactMobile string `json:"contact_mobile" form:"contact_mobile" binding:"required"` // 联系方式
|
||||
Province string `json:"province" form:"province" binding:"required"` // 省
|
||||
City string `json:"city" form:"city" binding:"city"` // 市区
|
||||
City string `json:"city" form:"city" binding:"required"` // 市区
|
||||
Remark string `json:"remark" form:"remark"` // 备注
|
||||
}
|
||||
)
|
||||
@ -87,8 +86,7 @@ func (a *Tenant) Member(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).
|
||||
Instance((&api.IDStringForm{ID: form.TenantID}).Convert())
|
||||
data, err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).Instance((&api.IDStringForm{ID: form.TenantID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -115,7 +113,7 @@ func (a *Tenant) Menu(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := tenant.NewMenu()(getSession()(c).(*service.Session)).List(form.TenantID)
|
||||
data, err := tenant.NewMenu()(api.GetSession()(c).(*session.Admin)).List(form.TenantID)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -128,7 +126,7 @@ func (a *Tenant) MenuBind(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant.NewMenu()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.MenuIDs)
|
||||
err := tenant.NewMenu()(api.GetSession()(c).(*session.Admin)).Bind(form.TenantID, form.MenuIDs)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
@ -141,6 +139,6 @@ func (a *Tenant) AuthBind(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant.NewAuth()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.AuthIDs)
|
||||
err := tenant.NewAuth()(api.GetSession()(c).(*session.Admin)).Bind(form.TenantID, form.AuthIDs)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/user"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -39,27 +38,37 @@ func (this *userForm) RoleInfo() []uint64 {
|
||||
|
||||
func (*User) Info(c *gin.Context) {
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Info()
|
||||
APIResponse(err, data)(c)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) List(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
Status int `json:"status" form:"status"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
Status int `json:"status" form:"status"`
|
||||
DepartmentIDs []string `json:"department_ids" form:"department_ids"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Index(form.Name, form.Mobile, form.Status, form.Page, form.PageSize)
|
||||
departmentIDs := make([]uint64, 0)
|
||||
|
||||
obj := new(api.IDStringForm)
|
||||
|
||||
for _, v := range form.DepartmentIDs {
|
||||
obj.ID = v
|
||||
departmentIDs = append(departmentIDs, obj.Convert())
|
||||
}
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Index(form.Name, form.Mobile, departmentIDs,
|
||||
form.Status, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) Menu(c *gin.Context) {
|
||||
data, err := user.NewMenu()(api.GetSession()(c).(*session.Admin)).Index()
|
||||
APIResponse(err, data)(c)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) Add(c *gin.Context) {
|
||||
@ -80,18 +89,18 @@ func (a *User) Add(c *gin.Context) {
|
||||
|
||||
func (a *User) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
api.IDStringForm
|
||||
userForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Edit(&user.InstanceForm{
|
||||
ID: form.ID, Account: form.Account, Name: form.Name, Mobile: form.Mobile,
|
||||
ID: form.Convert(), Account: form.Account, Name: form.Name, Mobile: form.Mobile,
|
||||
Remark: form.Remark, Gender: form.Gender, DepartmentID: form.departmentInfo(), RoleIDs: form.RoleInfo(),
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) Password(c *gin.Context) {
|
||||
@ -114,46 +123,21 @@ func (a *User) PasswordEdit(c *gin.Context) {
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewPerson()(getSession()(c).(*service.Session)).EditPassword(form.OldPwd, form.Password, form.RepeatPwd)
|
||||
APIResponse(err)(c)
|
||||
err := user.NewPerson()(api.GetSession()(c).(*session.Admin)).PasswordEdit(form.OldPwd, form.Password, form.RepeatPwd)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) Role(c *gin.Context) {
|
||||
form := &struct {
|
||||
uidForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewRole()(getSession()(c).(*service.Session)).List(form.Convert())
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) RoleBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
uidForm
|
||||
RoleIDs []uint64 `json:"role_ids" form:"role_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewRole()(getSession()(c).(*service.Session)).Bind(form.Convert(), form.RoleIDs)
|
||||
APIResponse(err)(c)
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
Reference in New Issue
Block a user