-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from nicelizhi/dev
Dev
- Loading branch information
Showing
97 changed files
with
10,704 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package apis | ||
|
||
import ( | ||
"github.com/nicelizhi/easy-admin-core/sdk/api" | ||
"github.com/nicelizhi/easy-admin-core/sdk/pkg/captcha" | ||
|
||
ginI18n "github.com/gin-contrib/i18n" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type System struct { | ||
api.Api | ||
} | ||
|
||
// GenerateCaptchaHandler 获取验证码 | ||
// @Summary 获取验证码 | ||
// @Description 获取验证码 | ||
// @Tags 登陆 | ||
// @Success 200 {object} response.Response{data=string,id=string,msg=string} "{"code": 200, "data": [...]}" | ||
// @Router /api/v1/captcha [get] | ||
func (e System) GenerateCaptchaHandler(c *gin.Context) { | ||
err := e.MakeContext(c).Errors | ||
if err != nil { | ||
//e.Error(500, err, "服务初始化失败!") | ||
e.Error(500, err, ginI18n.MustGetMessage(c, "Service initialization failed")) | ||
return | ||
} | ||
id, b64s, err := captcha.DriverDigitFunc() | ||
if err != nil { | ||
e.Logger.Errorf("DriverDigitFunc error, %s", err.Error()) | ||
//e.Error(500, err, "验证码获取失败") | ||
e.Error(500, err, ginI18n.MustGetMessage(c, "Failed to obtain verification code")) | ||
return | ||
} | ||
e.Custom(gin.H{ | ||
"code": 200, | ||
"data": b64s, | ||
"id": id, | ||
"msg": "success", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package apis | ||
|
||
import ( | ||
resource "github.com/nicelizhi/easy-admin/ui" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func GoAdmin(c *gin.Context) { | ||
c.Header("Content-Type", "text/html; charset=utf-8") | ||
c.String(200, string(resource.Html)) | ||
} | ||
|
||
func Favicon(c *gin.Context) { | ||
//c.Header("Content-Type", "text/html; charset=utf-8") | ||
c.String(200, string(resource.Favicon)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package apis | ||
|
||
import ( | ||
"github.com/nicelizhi/easy-admin-core/sdk/api" | ||
"github.com/nicelizhi/easy-admin-core/sdk/pkg/jwtauth/user" | ||
_ "github.com/nicelizhi/easy-admin-core/sdk/pkg/response" | ||
|
||
ginI18n "github.com/gin-contrib/i18n" | ||
"github.com/gin-gonic/gin" | ||
"github.com/gin-gonic/gin/binding" | ||
|
||
"github.com/nicelizhi/easy-admin/app/admin/models" | ||
"github.com/nicelizhi/easy-admin/app/admin/service" | ||
"github.com/nicelizhi/easy-admin/app/admin/service/dto" | ||
"github.com/nicelizhi/easy-admin/common/actions" | ||
) | ||
|
||
type SysApi struct { | ||
api.Api | ||
} | ||
|
||
// GetPage 获取接口管理列表 | ||
// @Summary 获取接口管理列表 | ||
// @Description 获取接口管理列表 | ||
// @Tags 接口管理 | ||
// @Param name query string false "名称" | ||
// @Param title query string false "标题" | ||
// @Param path query string false "地址" | ||
// @Param action query string false "类型" | ||
// @Param pageSize query int false "页条数" | ||
// @Param pageIndex query int false "页码" | ||
// @Success 200 {object} response.Response{data=response.Page{list=[]models.SysApi}} "{"code": 200, "data": [...]}" | ||
// @Router /api/v1/sys-api [get] | ||
// @Security Bearer | ||
func (e SysApi) GetPage(c *gin.Context) { | ||
s := service.SysApi{} | ||
req := dto.SysApiGetPageReq{} | ||
err := e.MakeContext(c). | ||
MakeOrm(). | ||
Bind(&req, binding.Form). | ||
MakeService(&s.Service). | ||
Errors | ||
if err != nil { | ||
e.Logger.Error(err) | ||
e.Error(500, err, err.Error()) | ||
return | ||
} | ||
//数据权限检查 | ||
p := actions.GetPermissionFromContext(c) | ||
list := make([]models.SysApi, 0) | ||
var count int64 | ||
err = s.GetPage(&req, p, &list, &count) | ||
if err != nil { | ||
//e.Error(500, err, ginI18n.MustGetMessage(c, "Query failed")) | ||
e.Error(500, err, ginI18n.MustGetMessage(c, "Query failed")) | ||
return | ||
} | ||
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), ginI18n.MustGetMessage(c, "Query successful")) | ||
} | ||
|
||
// Get 获取接口管理 | ||
// @Summary 获取接口管理 | ||
// @Description 获取接口管理 | ||
// @Tags 接口管理 | ||
// @Param id path string false "id" | ||
// @Success 200 {object} response.Response{data=models.SysApi} "{"code": 200, "data": [...]}" | ||
// @Router /api/v1/sys-api/{id} [get] | ||
// @Security Bearer | ||
func (e SysApi) Get(c *gin.Context) { | ||
req := dto.SysApiGetReq{} | ||
s := service.SysApi{} | ||
err := e.MakeContext(c). | ||
MakeOrm(). | ||
Bind(&req, nil). | ||
MakeService(&s.Service). | ||
Errors | ||
if err != nil { | ||
e.Logger.Error(err) | ||
e.Error(500, err, err.Error()) | ||
return | ||
} | ||
p := actions.GetPermissionFromContext(c) | ||
var object models.SysApi | ||
err = s.Get(&req, p, &object).Error | ||
if err != nil { | ||
e.Error(500, err, ginI18n.MustGetMessage(c, "Query failed")) | ||
return | ||
} | ||
e.OK(object, ginI18n.MustGetMessage(c, "Query successful")) | ||
} | ||
|
||
// Update 修改接口管理 | ||
// @Summary 修改接口管理 | ||
// @Description 修改接口管理 | ||
// @Tags 接口管理 | ||
// @Accept application/json | ||
// @Product application/json | ||
// @Param data body dto.SysApiUpdateReq true "body" | ||
// @Success 200 {object} response.Response "{"code": 200, "message": ginI18n.MustGetMessage(c, "Update completed")}" | ||
// @Router /api/v1/sys-api/{id} [put] | ||
// @Security Bearer | ||
func (e SysApi) Update(c *gin.Context) { | ||
req := dto.SysApiUpdateReq{} | ||
s := service.SysApi{} | ||
err := e.MakeContext(c). | ||
MakeOrm(). | ||
Bind(&req). | ||
MakeService(&s.Service). | ||
Errors | ||
if err != nil { | ||
e.Logger.Error(err) | ||
return | ||
} | ||
req.SetUpdateBy(user.GetUserId(c)) | ||
p := actions.GetPermissionFromContext(c) | ||
err = s.Update(&req, p) | ||
if err != nil { | ||
e.Error(500, err, ginI18n.MustGetMessage(c, "Update failed")) | ||
return | ||
} | ||
e.OK(req.GetId(), ginI18n.MustGetMessage(c, "Update completed")) | ||
} | ||
|
||
// DeleteSysApi 删除接口管理 | ||
// @Summary 删除接口管理 | ||
// @Description 删除接口管理 | ||
// @Tags 接口管理 | ||
// @Param data body dto.SysApiDeleteReq true "body" | ||
// @Success 200 {object} response.Response "{"code": 200, "message": ginI18n.MustGetMessage(c, "Successfully deleted")}" | ||
// @Router /api/v1/sys-api [delete] | ||
// @Security Bearer | ||
func (e SysApi) DeleteSysApi(c *gin.Context) { | ||
req := dto.SysApiDeleteReq{} | ||
s := service.SysApi{} | ||
err := e.MakeContext(c). | ||
MakeOrm(). | ||
Bind(&req). | ||
MakeService(&s.Service). | ||
Errors | ||
if err != nil { | ||
e.Logger.Error(err) | ||
return | ||
} | ||
p := actions.GetPermissionFromContext(c) | ||
err = s.Remove(&req, p) | ||
if err != nil { | ||
//e.Error(500, err, ginI18n.MustGetMessage(c, "Failed to delete")) | ||
e.Error(500, err, ginI18n.MustGetMessage(c, "Failed to delete")) | ||
return | ||
} | ||
e.OK(req.GetId(), ginI18n.MustGetMessage(c, "Successfully deleted")) | ||
} |
Oops, something went wrong.