95 lines
2.8 KiB
Go
95 lines
2.8 KiB
Go
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"` // 修改时间
|
||
}
|
||
|
||
// getApiList 获取接口列表
|
||
type getApiList struct {
|
||
APIID string `json:"api_id"` // 主键id
|
||
APIName string `json:"api_name"` // api名称
|
||
}
|
||
|
||
// 接口详情
|
||
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
|
||
}
|
||
|
||
// GetApiListResponse 获取接口列表
|
||
func GetApiListResponse(adminApi []*model.AdminAPI) []getApiList {
|
||
// 处理返回值
|
||
getApiListResponses := make([]getApiList, len(adminApi))
|
||
|
||
if len(adminApi) > 0 {
|
||
for i, v := range adminApi {
|
||
// 将原始结构体转换为新结构体
|
||
getApiListResponse := getApiList{
|
||
APIID: strconv.Itoa(int(v.APIID)),
|
||
APIName: v.APIName,
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
getApiListResponses[i] = getApiListResponse
|
||
}
|
||
}
|
||
|
||
return getApiListResponses
|
||
}
|
||
|
||
// 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,
|
||
}
|
||
}
|