package role

import (
	"github.com/veypi/vbase/cfg"
	"github.com/veypi/vbase/models"
	"github.com/veypi/vigo"
)

type getIDReq struct {
	ID string `src:"path@role_id" desc:"角色ID"`
}

var _ = Router.Get("/{role_id}", "获取角色详情", getRole)

func getRole(x *vigo.X, req *getIDReq) (*models.Role, error) {
	// 查询数据库
	role := &models.Role{}
	err := cfg.DB().Where("id = ?", req.ID).First(role).Error
	if err != nil {
		return nil, vigo.NewError("role not found").WithCode(404)
	}

	return role, nil
}
