实现category service基础接口
This commit is contained in:
138
api/gateway.api
138
api/gateway.api
@ -1,5 +1,12 @@
|
||||
syntax = "v1"
|
||||
|
||||
// ================== 通用类型定义 ==================
|
||||
type BaseResp {
|
||||
Code int `json:"code"` // 状态码 (0=成功)
|
||||
Message string `json:"message"` // 消息
|
||||
}
|
||||
|
||||
// ================== 用户服务类型 ==================
|
||||
type RegisterReq {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@ -40,22 +47,139 @@ type GetUserInfoResp {
|
||||
Roles []string `json:"roles"`
|
||||
}
|
||||
|
||||
service user-api {
|
||||
// ================== 分类服务类型 ==================
|
||||
type BaseCategory {
|
||||
ID string `json:"id"` // 分类ID (UUID)
|
||||
SystemID string `json:"systemId"` // 所属系统ID
|
||||
Name string `json:"name"` // 分类名称
|
||||
Alias string `json:"alias"` // URL别名
|
||||
ParentID string `json:"parentId"` // 父分类ID (可为空)
|
||||
Description string `json:"description"` // 分类描述
|
||||
CreatedAt string `json:"createdAt"` // 创建时间 (ISO8601)
|
||||
UpdatedAt string `json:"updatedAt"` // 更新时间 (ISO8601)
|
||||
}
|
||||
|
||||
type CategoryDetail {
|
||||
BaseCategory
|
||||
Parent *BaseCategory `json:"parent"` // 父分类信息
|
||||
}
|
||||
|
||||
type TreeNode {
|
||||
BaseCategory
|
||||
Children []*TreeNode `json:"children"` // 子分类列表
|
||||
}
|
||||
|
||||
type CreateCategoryReq {
|
||||
SystemID string `json:"systemId" validate:"required"` // 所属系统ID
|
||||
Name string `json:"name" validate:"required"` // 分类名称
|
||||
Alias string `json:"alias,optional"` // URL别名
|
||||
ParentID string `json:"parentId,optional"` // 父分类ID
|
||||
Description string `json:"description,optional"` // 分类描述
|
||||
}
|
||||
|
||||
type CreateCategoryResp {
|
||||
ID string `json:"id"` // 新创建的分类ID
|
||||
}
|
||||
|
||||
type ListCategoriesReq {
|
||||
SystemID string `form:"systemId,optional"` // 按系统ID过滤
|
||||
ParentID string `form:"parentId,optional"` // 按父分类ID过滤
|
||||
Name string `form:"name,optional"` // 按名称模糊搜索
|
||||
Page int `form:"page,default=1"` // 页码
|
||||
PageSize int `form:"pageSize,default=20"` // 每页数量
|
||||
}
|
||||
|
||||
type ListCategoriesResp {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []BaseCategory `json:"list"` // 分类列表
|
||||
}
|
||||
|
||||
type GetCategoryReq {
|
||||
ID string `path:"id"` // 分类ID
|
||||
}
|
||||
|
||||
type CategoryDetailResp {
|
||||
CategoryDetail
|
||||
}
|
||||
|
||||
type UpdateCategoryReq {
|
||||
ID string `path:"id"` // 分类ID
|
||||
Name string `json:"name,optional"` // 新名称
|
||||
Alias string `json:"alias,optional"` // 新别名
|
||||
ParentID string `json:"parentId,optional"` // 新父分类ID
|
||||
Description string `json:"description,optional"` // 新描述
|
||||
}
|
||||
|
||||
type GetCategoryTreeReq {
|
||||
ID string `path:"id"` // 起始分类ID
|
||||
}
|
||||
|
||||
type CategoryTreeResp {
|
||||
Root TreeNode `json:"root"` // 分类树根节点
|
||||
}
|
||||
|
||||
type GetSystemCategoriesReq {
|
||||
SystemID string `path:"system_id"` // 系统ID
|
||||
ParentID string `form:"parentId,optional"` // 父分类ID (可选)
|
||||
IncludeDescendants bool `form:"includeDescendants,default=true"` // 是否包含子分类
|
||||
}
|
||||
|
||||
type DeleteCategoryReq {
|
||||
ID string `path:"id"` // 分类ID
|
||||
}
|
||||
|
||||
// ================== 网关服务定义 ==================
|
||||
@server (
|
||||
prefix: /api
|
||||
)
|
||||
service gateway-api {
|
||||
// ===== 用户服务 =====
|
||||
// 公共接口(无需认证)
|
||||
@handler registerHandler
|
||||
post /api/user/register (RegisterReq) returns (RegisterResp)
|
||||
post /user/register (RegisterReq) returns (RegisterResp)
|
||||
|
||||
@handler loginHandler
|
||||
post /api/user/login (LoginReq) returns (LoginResp)
|
||||
post /user/login (LoginReq) returns (LoginResp)
|
||||
}
|
||||
|
||||
@server (
|
||||
jwt: JwtAuth
|
||||
prefix: /api
|
||||
jwt: JwtAuth
|
||||
)
|
||||
service user-api {
|
||||
service gateway-api {
|
||||
@handler logoutHandler
|
||||
post /api/user/logout (LogoutReq) returns (LogoutResp)
|
||||
post /user/logout (LogoutReq) returns (LogoutResp)
|
||||
|
||||
@handler getUserInfoHandler
|
||||
get /api/user/:user_id (GetUserInfoReq) returns (GetUserInfoResp)
|
||||
get /user/:user_id (GetUserInfoReq) returns (GetUserInfoResp)
|
||||
|
||||
// ===== 分类服务 =====
|
||||
// 创建分类
|
||||
@handler createCategoryHandler
|
||||
post /category/v1 (CreateCategoryReq) returns (CreateCategoryResp)
|
||||
|
||||
// 批量获取分类(带分页和过滤)
|
||||
@handler listCategoriesHandler
|
||||
get /category/v1 (ListCategoriesReq) returns (ListCategoriesResp)
|
||||
|
||||
// 获取单个分类详情
|
||||
@handler getCategoryHandler
|
||||
get /category/v1/:id (GetCategoryReq) returns (CategoryDetailResp)
|
||||
|
||||
// 更新分类
|
||||
@handler updateCategoryHandler
|
||||
put /category/v1/:id (UpdateCategoryReq) returns (BaseResp)
|
||||
|
||||
// 删除分类
|
||||
@handler deleteCategoryHandler
|
||||
delete /category/v1/:id (DeleteCategoryReq) returns (BaseResp)
|
||||
|
||||
// 获取子分类树
|
||||
@handler getCategoryTreeHandler
|
||||
get /category/v1/:id/tree (GetCategoryTreeReq) returns (CategoryTreeResp)
|
||||
|
||||
// 根据系统ID获取分类
|
||||
@handler getSystemCategoriesHandler
|
||||
get /category/v1/system/:system_id (GetSystemCategoriesReq) returns (ListCategoriesResp)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user