作者 tangxvhui

调整接口

... ... @@ -70,7 +70,7 @@ type (
type (
MiniArticleGetRequest {
Id int64 `path:"id"` //id
CompanyId int64 `path:"-"`
CompanyId int64 `path:",optional"`
}
MiniArticleGetResponse {
Id int64 `json:"id"` //id
... ... @@ -99,8 +99,8 @@ type (
// 获取我的发文章记录
type (
MiniArticleSearchMeRequest {
AuthorId int64 `json:"-"`
CompanyId int64 `json:"-"`
AuthorId int64 `json:",optional"`
CompanyId int64 `json:",optional"`
Page int `json:"page"`
Size int `json:"size"`
}
... ... @@ -125,7 +125,7 @@ type (
type (
MiniUserLikeArticleRequest {
ArticleId int64 `json:"articleId"` // 文章id
CompanyId int64 `json:"-"` //公司id
CompanyId int64 `json:",optional"` //公司id
Page int `json:"page"` //分页,第几页
Size int `json:"size"` //分页,每页几条
}
... ... @@ -147,7 +147,7 @@ type (
MiniSetUserLikeRequset {
ArticleId int64 `json:"articleId"` //文章id
CommentId int64 `json:"commentId"` //评论id
UserId int64 `json:"-"` //操作人
UserId int64 `json:",optional"` //操作人
Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞
}
MiniSetUserLikeResponse {
... ...
... ... @@ -3,7 +3,7 @@ Host: 0.0.0.0
Port: 8081
Verbose: true
Migrate: false
Timeout: 30000
Log:
#Mode: file
Encoding: plain
... ... @@ -24,4 +24,4 @@ Redis:
Type: node
Pass:
DB:
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=sumifcc-discuss-dev port=31543 sslmode=disable TimeZone=Asia/Shanghai
\ No newline at end of file
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=sumifcc-discuss-dev port=31543 sslmode=disable TimeZone=Asia/Shanghai
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -23,10 +24,6 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
req.AuthorId = token.UserId
req.CompanyId = token.CompanyId
resp, err := l.MiniArticleSearchMe(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -22,10 +23,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx)
req.AuthorId = token.UserId
resp, err := l.MiniCreateArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -22,10 +23,6 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.MiniGetArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -22,10 +23,6 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
token := contextdata.GetUserTokenFromCtx(r.Context())
req.UserId = token.UserId
resp, err := l.MiniSetUserLike(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -22,10 +23,6 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.MiniUserLikeArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -183,11 +183,6 @@ 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),
... ... @@ -202,6 +197,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article/user_like/set",
Handler: article.MiniSetUserLikeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.MiniArticleSearchMeHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
... ...
... ... @@ -35,7 +35,10 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
//TODO 获取人员信息
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, author.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
articleAuthor := domain.UserSimple{
Id: author.Id,
Name: author.Name,
... ... @@ -43,9 +46,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
GroupId: 0,
Group: "",
Position: author.Position,
Company: "",
Company: companyInfo.Name,
CompanyId: author.CompanyId,
}
if author.DepartmentId > 0 {
department, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, author.DepartmentId)
if err == nil {
articleAuthor.GroupId = department.Id
articleAuthor.Group = department.Name
}
}
if len(req.Images) > 9 {
return nil, xerr.NewErrMsg("图片数量最多9张")
}
... ... @@ -76,10 +86,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
}
//检查文章可被哪些人评论
whoReview := []int64{}
if len(req.WhoReview) > 0 {
whoReview = lo.Uniq(req.WhoReview)
}
//有指定可查看人的情况
if len(whoRead) > 0 {
if len(whoReview) > 0 {
whoReview = lo.Uniq(req.WhoReview)
// 检查 whoRead 是否 完全包含 whoReview
ok := lo.Every(whoRead, whoReview)
if !ok {
... ...
... ... @@ -247,7 +247,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ
return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
}
articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err == nil {
if err != nil {
return nil, xerr.NewErrMsgErr("获取点赞数量失败", err)
}
resp = &types.MiniSetUserLikeResponse{
... ...
... ... @@ -301,7 +301,7 @@ type MiniArticleCreateResponse struct {
type MiniArticleGetRequest struct {
Id int64 `path:"id"` //id
CompanyId int64 `path:"-"`
CompanyId int64 `path:",optional"`
}
type MiniArticleGetResponse struct {
... ... @@ -329,8 +329,8 @@ type ArticleSection struct {
}
type MiniArticleSearchMeRequest struct {
AuthorId int64 `json:"-"`
CompanyId int64 `json:"-"`
AuthorId int64 `json:",optional"`
CompanyId int64 `json:",optional"`
Page int `json:"page"`
Size int `json:"size"`
}
... ... @@ -352,7 +352,7 @@ type ArticleSearchMe struct {
type MiniUserLikeArticleRequest struct {
ArticleId int64 `json:"articleId"` // 文章id
CompanyId int64 `json:"-"` //公司id
CompanyId int64 `json:",optional"` //公司id
Page int `json:"page"` //分页,第几页
Size int `json:"size"` //分页,每页几条
}
... ... @@ -373,7 +373,7 @@ type WhichUserLikeArticle struct {
type MiniSetUserLikeRequset struct {
ArticleId int64 `json:"articleId"` //文章id
CommentId int64 `json:"commentId"` //评论id
UserId int64 `json:"-"` //操作人
UserId int64 `json:",optional"` //操作人
Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞
}
... ...