作者 tangxvhui

新建接口

@@ -93,6 +93,9 @@ service Core { @@ -93,6 +93,9 @@ service Core {
93 @doc "小程序创建发布内容" 93 @doc "小程序创建发布内容"
94 @handler MiniCreateArticle 94 @handler MiniCreateArticle
95 post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse) 95 post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
  96 + @doc "小程序获取我发布的文章"
  97 + @handler MiniArticleSearchMe
  98 + post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
96 @doc "小程序获取文章内容详情" 99 @doc "小程序获取文章内容详情"
97 @handler MiniGetArticle 100 @handler MiniGetArticle
98 get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse) 101 get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
  1 +package article
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 +)
  11 +
  12 +func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.MiniArticleSearchMeRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := article.NewMiniArticleSearchMeLogic(r.Context(), svcCtx)
  21 + resp, err := l.MiniArticleSearchMe(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
@@ -19,7 +19,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -19,7 +19,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
19 server.AddRoutes( 19 server.AddRoutes(
20 []rest.Route{ 20 []rest.Route{
21 { 21 {
22 - Method: http.MethodGet, 22 + Method: http.MethodGet,
23 Path: "/mini/comment", 23 Path: "/mini/comment",
24 Handler: comment.MiniCommentHandler(serverCtx), 24 Handler: comment.MiniCommentHandler(serverCtx),
25 }, 25 },
@@ -183,6 +183,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -183,6 +183,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
183 Handler: article.MiniCreateArticleHandler(serverCtx), 183 Handler: article.MiniCreateArticleHandler(serverCtx),
184 }, 184 },
185 { 185 {
  186 + Method: http.MethodPost,
  187 + Path: "/article/search/me",
  188 + Handler: article.MiniArticleSearchMeHandler(serverCtx),
  189 + },
  190 + {
186 Method: http.MethodGet, 191 Method: http.MethodGet,
187 Path: "/article/:id", 192 Path: "/article/:id",
188 Handler: article.MiniGetArticleHandler(serverCtx), 193 Handler: article.MiniGetArticleHandler(serverCtx),
  1 +package article
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type MiniArticleSearchMeLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewMiniArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleSearchMeLogic {
  19 + return &MiniArticleSearchMeLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
@@ -31,7 +31,7 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) @@ -31,7 +31,7 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext)
31 func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) { 31 func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
32 var conn = l.svcCtx.DefaultDBConn() 32 var conn = l.svcCtx.DefaultDBConn()
33 // 检查发布人 33 // 检查发布人
34 - author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(req.AuthorId)) 34 + author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId)
35 if err != nil { 35 if err != nil {
36 return nil, xerr.NewErrMsgErr("创建文章内容失败", err) 36 return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
37 } 37 }
@@ -256,10 +256,10 @@ type Author struct { @@ -256,10 +256,10 @@ type Author struct {
256 type MiniArticleCreateRequest struct { 256 type MiniArticleCreateRequest struct {
257 Title string `json:"title"` //标题 257 Title string `json:"title"` //标题
258 Section []string `json:"section"` //文章的文本内容 258 Section []string `json:"section"` //文章的文本内容
259 - AuthorId int `json:"authorId,optional"` //发布人id 259 + AuthorId int64 `json:"authorId,optional"` //发布人id
260 Images []string `json:"images,optional"` //图片 260 Images []string `json:"images,optional"` //图片
261 - WhoRead []int64 `json:"whoRead,optional"` //谁可查看  
262 - WhoReview []int64 `json:"whoReview,optional"` //谁可评论 261 + WhoRead []int64 `json:"whoRead,optional"` //谁可查看
  262 + WhoReview []int64 `json:"whoReview,optional"` //谁可评论
263 Location Location `json:"location,optional"` //定位坐标 263 Location Location `json:"location,optional"` //定位坐标
264 } 264 }
265 265
@@ -278,10 +278,29 @@ type MiniArticleGetResponse struct { @@ -278,10 +278,29 @@ type MiniArticleGetResponse struct {
278 CreatedAt int64 `json:"createdAt"` //文章的发布时间 278 CreatedAt int64 `json:"createdAt"` //文章的发布时间
279 Section []string `json:"section"` //文章的文本内容 279 Section []string `json:"section"` //文章的文本内容
280 Images []string `json:"images"` //图片 280 Images []string `json:"images"` //图片
281 - WhoRead []int64 `json:"whoRead"` //谁可查看  
282 - WhoReview []int64 `json:"whoReview"` //谁可评论 281 + WhoRead []int64 `json:"whoRead"` //谁可查看
  282 + WhoReview []int64 `json:"whoReview"` //谁可评论
283 Location Location `json:"location"` //定位坐标 283 Location Location `json:"location"` //定位坐标
284 CountLove int `json:"countLove"` // 点赞数量 284 CountLove int `json:"countLove"` // 点赞数量
285 CountComment int `json:"countComment"` // 评论数量 285 CountComment int `json:"countComment"` // 评论数量
286 Show int `json:"showState"` // 评论的展示状态(0显示、1不显示) 286 Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
287 } 287 }
  288 +
  289 +type MiniArticleSearchMeRequest struct {
  290 + AuthorId int64 `json:"-"`
  291 +}
  292 +
  293 +type MiniArticleSearchMeResponse struct {
  294 + Total int `json:"total"`
  295 + List []ArticleSearchMe `json:"list"`
  296 +}
  297 +
  298 +type ArticleSearchMe struct {
  299 + Id int64 `json:"id"` //id
  300 + Title string `json:"title"` //标题
  301 + Images []string `json:"images"` //图片
  302 + CreatedAt int64 `json:"createdAt"` //文章的创建日期
  303 + CountLove int `json:"countLove"` //点赞数量
  304 + CountComment int `json:"CountComment"` //评论数量
  305 + Show int `json:"show"` //是否隐藏 [0显示、1不显示]
  306 +}