feat:完善项目

This commit is contained in:
henry
2021-11-08 15:52:46 +08:00
parent 1502076841
commit 1cc95fb5ca
16 changed files with 154 additions and 64 deletions

View File

@ -105,6 +105,8 @@ func (a *Role) Delete(c *gin.Context) {
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} role_id 角色ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Array} data 具体信息
@ -144,13 +146,15 @@ func (a *Role) Delete(c *gin.Context) {
*/
func (a *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)
return
}
data, err := role.NewMenu()(getSession()(c).(*service.Session)).List(form.RoleID)
obj := new(IDStringForm)
obj.ID = form.RoleID
data, err := role.NewMenu()(getSession()(c).(*service.Session)).List(obj.Convert())
APIResponse(err, data)(c)
}
@ -178,21 +182,22 @@ func (a *Role) Menu(c *gin.Context) {
*/
func (a *Role) MenuBind(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"`
MenuIDs []string `json:"menu_ids" form:"menu_ids" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
menuIDs := make([]uint64, 0)
handle := new(IDStringForm)
handle.ID = form.RoleID
roleID := handle.Convert()
menuIDs := make([]uint64, 0)
for _, v := range form.MenuIDs {
handle.ID = v
menuIDs = append(menuIDs, handle.Convert())
}
err := role.NewMenu()(getSession()(c).(*service.Session)).Bind(form.RoleID, menuIDs)
err := role.NewMenu()(getSession()(c).(*service.Session)).Bind(roleID, menuIDs)
APIResponse(err)(c)
}