作者 tangxvhui

新建接口

... ... @@ -93,6 +93,9 @@ service Core {
@doc "小程序创建发布内容"
@handler MiniCreateArticle
post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
@doc "小程序获取我发布的文章"
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序获取文章内容详情"
@handler MiniGetArticle
get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
... ...
package article
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniArticleSearchMeLogic(r.Context(), svcCtx)
resp, err := l.MiniArticleSearchMe(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -183,6 +183,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: article.MiniCreateArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.MiniArticleSearchMeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article/:id",
Handler: article.MiniGetArticleHandler(serverCtx),
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniArticleSearchMeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleSearchMeLogic {
return &MiniArticleSearchMeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -31,7 +31,7 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext)
func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(req.AuthorId))
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
... ...
... ... @@ -256,7 +256,7 @@ type Author struct {
type MiniArticleCreateRequest struct {
Title string `json:"title"` //标题
Section []string `json:"section"` //文章的文本内容
AuthorId int `json:"authorId,optional"` //发布人id
AuthorId int64 `json:"authorId,optional"` //发布人id
Images []string `json:"images,optional"` //图片
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
... ... @@ -285,3 +285,22 @@ type MiniArticleGetResponse struct {
CountComment int `json:"countComment"` // 评论数量
Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
}
type MiniArticleSearchMeRequest struct {
AuthorId int64 `json:"-"`
}
type MiniArticleSearchMeResponse struct {
Total int `json:"total"`
List []ArticleSearchMe `json:"list"`
}
type ArticleSearchMe struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
}
... ...