This commit is contained in:
2023-06-30 14:54:43 +08:00
parent a7ca868a5f
commit c0c69eb602
14 changed files with 840 additions and 13 deletions
+67
View File
@@ -0,0 +1,67 @@
package apiResponse
import (
"hospital-admin-api/api/model"
"strconv"
)
// getApiPage 获取接口列表-分页
type getApiPage struct {
APIID string `json:"api_id"` // 主键id
APIName string `json:"api_name"` // api名称
APIPath string `json:"api_path"` // 接口路径(全路径 id为:id
APIMethod string `json:"api_method"` // 请求类型
IsAuth int `json:"is_auth"` // 是否验证权限(0:否 1:是)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// 接口详情
type getApi struct {
APIID string `json:"api_id"` // 主键id
APIName string `json:"api_name"` // api名称
APIPath string `json:"api_path"` // 接口路径(全路径 id为:id
APIMethod string `json:"api_method"` // 请求类型
IsAuth int `json:"is_auth"` // 是否验证权限(0:否 1:是)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetApiPageResponse 获取接口列表-分页
func GetApiPageResponse(adminApi []*model.AdminAPI) []getApiPage {
// 处理返回值
getApiPageResponses := make([]getApiPage, len(adminApi))
if len(adminApi) > 0 {
for i, v := range adminApi {
// 将原始结构体转换为新结构体
getApiPageResponse := getApiPage{
APIID: strconv.Itoa(int(v.APIID)),
APIName: v.APIName,
APIPath: v.APIPath,
APIMethod: v.APIMethod,
IsAuth: v.IsAuth,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
getApiPageResponses[i] = getApiPageResponse
}
}
return getApiPageResponses
}
// GetApiResponse 接口详情
func GetApiResponse(adminApi *model.AdminAPI) *getApi {
return &getApi{
APIID: strconv.Itoa(int(adminApi.APIID)),
APIName: adminApi.APIName,
APIPath: adminApi.APIPath,
APIMethod: adminApi.APIMethod,
IsAuth: adminApi.IsAuth,
CreatedAt: adminApi.CreatedAt,
UpdatedAt: adminApi.UpdatedAt,
}
}