新增
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/responses/apiResponse"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type AdminApi struct{}
|
||||
|
||||
// GetApiPage 获取api列表-分页
|
||||
func (r *AdminApi) GetApiPage(c *gin.Context) {
|
||||
apiRequest := requests.ApiRequest{}
|
||||
if err := c.ShouldBind(&apiRequest.GetApiPage); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(apiRequest.GetApiPage); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if apiRequest.GetApiPage.Page == 0 {
|
||||
apiRequest.GetApiPage.Page = 1
|
||||
}
|
||||
|
||||
if apiRequest.GetApiPage.PageSize == 0 {
|
||||
apiRequest.GetApiPage.PageSize = 20
|
||||
}
|
||||
|
||||
adminApiDao := dao.AdminApiDao{}
|
||||
adminApi, total, err := adminApiDao.GetAdminApiPageSearch(apiRequest.GetApiPage, apiRequest.GetApiPage.Page, apiRequest.GetApiPage.PageSize)
|
||||
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
getApiPageResponses := apiResponse.GetApiPageResponse(adminApi)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = apiRequest.GetApiPage.Page
|
||||
result["page_size"] = apiRequest.GetApiPage.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = getApiPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// AddApi 新增接口
|
||||
func (r *AdminApi) AddApi(c *gin.Context) {
|
||||
apiRequest := requests.ApiRequest{}
|
||||
if err := c.ShouldBind(&apiRequest.AddApi); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(apiRequest.AddApi); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
ApiService := service.ApiService{}
|
||||
_, err := ApiService.AddApi(c, apiRequest.AddApi)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// GetApi 接口详情
|
||||
func (r *AdminApi) GetApi(c *gin.Context) {
|
||||
id := c.Param("api_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
apiId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取接口详情
|
||||
adminApiDao := dao.AdminApiDao{}
|
||||
adminApi, err := adminApiDao.GetAdminApiById(apiId)
|
||||
if err != nil || adminApi == nil {
|
||||
responses.FailWithMessage("接口数据错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
getApiResponses := apiResponse.GetApiResponse(adminApi)
|
||||
|
||||
responses.OkWithData(getApiResponses, c)
|
||||
}
|
||||
|
||||
// DeleteApi 删除接口-批量
|
||||
func (r *AdminApi) DeleteApi(c *gin.Context) {
|
||||
apiRequest := requests.ApiRequest{}
|
||||
if err := c.ShouldBindJSON(&apiRequest.DeleteApi); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(apiRequest.DeleteApi); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
apiService := service.ApiService{}
|
||||
_, err := apiService.DeleteApi(c, apiRequest.DeleteApi)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutApi 修改接口
|
||||
func (r *AdminApi) PutApi(c *gin.Context) {
|
||||
apiRequest := requests.ApiRequest{}
|
||||
if err := c.ShouldBind(&apiRequest.PutApi); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(apiRequest.PutApi); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("api_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
ApiId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
apiService := service.ApiService{}
|
||||
_, err = apiService.PutApi(c, ApiId, apiRequest.PutApi)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
responses.Ok(c)
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package controller
|
||||
|
||||
// Api api接口
|
||||
type Api struct {
|
||||
Basic // 基础数据
|
||||
Role // 角色数据
|
||||
Menu // 菜单数据
|
||||
User // 用户数据
|
||||
Basic // 基础数据
|
||||
Role // 角色数据
|
||||
Menu // 菜单数据
|
||||
User // 用户数据
|
||||
AdminApi // 接口数据
|
||||
Dept // 部门数据
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
)
|
||||
|
||||
type Dept struct{}
|
||||
|
||||
// GetDeptList 获取部门列表
|
||||
func (r *Dept) GetDeptList(c *gin.Context) {
|
||||
deptRequest := service.DeptService{}
|
||||
deptList, err := deptRequest.GetDeptList()
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if deptList == nil {
|
||||
responses.Ok(c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(deptList, c)
|
||||
return
|
||||
}
|
||||
|
||||
//
|
||||
// // AddDept 新增部门
|
||||
// func (r *Dept) AddDept(c *gin.Context) {
|
||||
// deptRequest := requests.DeptRequest{}
|
||||
// if err := c.ShouldBind(&deptRequest.AddDept); err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 参数验证
|
||||
// if err := global.Validate.Struct(deptRequest.AddDept); err != nil {
|
||||
// responses.FailWithMessage(utils.Translate(err), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 业务处理
|
||||
// deptService := service.DeptService{}
|
||||
// _, err := deptService.AddDept(c, deptRequest.AddDept)
|
||||
// if err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
// responses.Ok(c)
|
||||
// }
|
||||
//
|
||||
// // GetDept 部门详情
|
||||
// func (r *Dept) GetDept(c *gin.Context) {
|
||||
// id := c.Param("dept_id")
|
||||
// if id == "" {
|
||||
// responses.FailWithMessage("缺少参数", c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 将 id 转换为 int64 类型
|
||||
// deptId, err := strconv.ParseInt(id, 10, 64)
|
||||
// if err != nil {
|
||||
// responses.Fail(c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 获取部门详情
|
||||
// adminDeptDao := dao.AdminDeptDao{}
|
||||
// adminDept, err := adminDeptDao.GetAdminDeptById(deptId)
|
||||
// if err != nil || adminDept == nil {
|
||||
// responses.FailWithMessage("部门数据错误", c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 处理返回值
|
||||
// getDeptResponses := apiResponse.GetDeptResponse(adminDept)
|
||||
//
|
||||
// responses.OkWithData(getDeptResponses, c)
|
||||
// }
|
||||
//
|
||||
// // DeleteDept 删除部门-批量
|
||||
// func (r *Dept) DeleteDept(c *gin.Context) {
|
||||
// deptRequest := requests.DeptRequest{}
|
||||
// if err := c.ShouldBindJSON(&deptRequest.DeleteDept); err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 参数验证
|
||||
// if err := global.Validate.Struct(deptRequest.DeleteDept); err != nil {
|
||||
// responses.FailWithMessage(utils.Translate(err), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 业务处理
|
||||
// apiService := service.DeptService{}
|
||||
// _, err := apiService.DeleteDept(c, deptRequest.DeleteDept)
|
||||
// if err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
// responses.Ok(c)
|
||||
// }
|
||||
//
|
||||
// // PutDept 修改部门
|
||||
// func (r *Dept) PutDept(c *gin.Context) {
|
||||
// deptRequest := requests.DeptRequest{}
|
||||
// if err := c.ShouldBind(&deptRequest.PutDept); err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 参数验证
|
||||
// if err := global.Validate.Struct(deptRequest.PutDept); err != nil {
|
||||
// responses.FailWithMessage(utils.Translate(err), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// id := c.Param("dept_id")
|
||||
// if id == "" {
|
||||
// responses.FailWithMessage("缺少参数", c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 将 id 转换为 int64 类型
|
||||
// deptId, err := strconv.ParseInt(id, 10, 64)
|
||||
// if err != nil {
|
||||
// responses.Fail(c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 业务处理
|
||||
// apiService := service.DeptService{}
|
||||
// _, err = apiService.PutDept(c, deptId, deptRequest.PutDept)
|
||||
// if err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
// responses.Ok(c)
|
||||
// }
|
||||
Reference in New Issue
Block a user