syntax = "v1" import "common.api" type ( PathId { Id int64 `path:"id"` } Post { Id int64 `json:"id,string"` Title string `json:"title"` Content string `json:"content"` Images []string `json:"images"` Tags []string `json:"tags"` LinkedOrderId int64 `json:"linkedOrderId,string,optional"` Pinned bool `json:"pinned"` LikeCount int64 `json:"likeCount"` CommentCount int64 `json:"commentCount"` Liked bool `json:"liked"` Author UserProfile `json:"author"` CreatedAt string `json:"createdAt"` } CreatePostReq { Title string `json:"title"` Content string `json:"content"` Images []string `json:"images"` Tags []string `json:"tags"` LinkedOrderId string `json:"linkedOrderId,optional"` } PostListReq { PageReq Tags string `form:"tags,optional"` SortBy string `form:"sortBy,optional"` } PostListResp { Items []Post `json:"items"` Meta PageMeta `json:"meta"` } Comment { Id int64 `json:"id,string"` Content string `json:"content"` Author UserProfile `json:"author"` LikeCount int64 `json:"likeCount"` Liked bool `json:"liked"` CreatedAt string `json:"createdAt"` } CommentListResp { Items []Comment `json:"items"` Meta PageMeta `json:"meta"` } CreateCommentReq { PostId int64 `json:"-"` Content string `json:"content"` } ListCommentsReq { PathId PageReq } ) @server ( prefix: api/v1 group: community ) service community-api { @doc "获取帖子列表" @handler ListPosts get /posts (PostListReq) returns (PostListResp) @doc "获取帖子详情" @handler GetPost get /posts/:id (PathId) returns (Post) @doc "获取帖子评论" @handler ListComments get /posts/:id/comments (ListCommentsReq) returns (CommentListResp) @doc "获取用户帖子" @handler ListUserPosts get /users/:id/posts (ListCommentsReq) returns (PostListResp) } @server ( prefix: api/v1 group: community ) service community-api { @doc "发布帖子" @handler CreatePost post /posts (CreatePostReq) returns (Post) @doc "点赞帖子" @handler LikePost post /posts/:id/like (PathId) returns (EmptyResp) @doc "取消点赞帖子" @handler UnlikePost delete /posts/:id/like (PathId) returns (EmptyResp) @doc "置顶帖子" @handler PinPost post /posts/:id/pin (PathId) returns (EmptyResp) @doc "取消置顶" @handler UnpinPost delete /posts/:id/pin (PathId) returns (EmptyResp) @doc "发表评论" @handler CreateComment post /posts/:id/comments (CreateCommentReq) returns (Comment) @doc "点赞评论" @handler LikeComment post /comments/:id/like (PathId) returns (EmptyResp) @doc "取消点赞评论" @handler UnlikeComment delete /comments/:id/like (PathId) returns (EmptyResp) }