作者 tangxvhui

更新

... ... @@ -2,4 +2,5 @@ import "core/comment.api"
import "core/message.api"
import "core/article_tag.api"
import "core/user.api"
import "core/company.api"
\ No newline at end of file
import "core/company.api"
import "core/article.api"
\ No newline at end of file
... ...
... ... @@ -10,9 +10,9 @@ info(
// 坐标地点描述
type Location {
Longitude float64 `json:"longitude"` //经度
Latitude float64 `json:"latitude"` //纬度
Descript string `json:"descript"` //地点描述
Longitude float64 `json:"longitude,optional"` //经度
Latitude float64 `json:"latitude,optional"` //纬度
Descript string `json:"descript,optional"` //地点描述
}
// 人员的简单展示信息
... ... @@ -24,36 +24,36 @@ type Author {
Position string `json:"position"` // 职位
}
// 创建发布文章
//小程序端创建发布文章
type (
ArticleCreateRequest {
Title string `json:"title"` //标题
Section []string `json:"section"` //文章的文本内容
AuthorId int `json:"authorId"` //发布人id
Images []string `json:"images"` //图片
WhoRead []int `json:"whoRead"` //谁可查看
WhoReview []int `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
MiniArticleCreateRequest {
Title string `json:"title"` //标题
Section []string `json:"section"` //文章的文本内容
AuthorId int64 `json:"authorId,optional"` //发布人id
Images []string `json:"images,optional"` //图片
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
Location Location `json:"location,optional"` //定位坐标
}
ArticleCreateResponse {
MiniArticleCreateResponse {
Id int64 `json:"id"`
}
)
// 查看文章的详情
//小程序端查看文章的详情
type (
ArticleGetRequest {
Id int64 `json:"id"` //id
MiniArticleGetRequest {
Id int64 `path:"id"` //id
}
ArticleGetResponse {
MiniArticleGetResponse {
Title string `json:"title"` //标题
AuthorId int `json:"authorId"` //发布人id
Author Author `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []string `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
WhoRead []int `json:"whoRead"` //谁可查看
WhoReview []int `json:"whoReview"` //谁可评论
WhoRead []int64 `json:"whoRead"` //谁可查看
WhoReview []int64 `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
... ... @@ -69,9 +69,9 @@ type (
)
service Core {
@doc "小程序创建发布内容"
@handler CreateArticle
post /article (ArticleCreateRequest) returns (ArticleCreateResponse)
@handler MiniCreateArticle
post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
@doc "小程序获取文章内容详情"
@handler GetArticle
get /article/:id (ArticleGetRequest) returns (ArticleGetResponse)
@handler MiniGetArticle
get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
}
\ No newline at end of file
... ...
... ... @@ -90,7 +90,7 @@ type (
)
@server(
prefix: v1/mini
prefix: v1/system
group: tags
jwt: MiniAuth
)
... ...
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 MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx)
resp, err := l.MiniCreateArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
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 MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniGetArticleLogic(r.Context(), svcCtx)
resp, err := l.MiniGetArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -4,6 +4,7 @@ package handler
import (
"net/http"
article "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/article"
comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment"
company "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/company"
message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message"
... ... @@ -18,7 +19,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Method: http.MethodGet,
Path: "/mini/comment",
Handler: comment.MiniCommentHandler(serverCtx),
},
... ... @@ -75,7 +76,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodDelete,
Path: "/article_tag",
Path: "/article_tag/:id",
Handler: tags.DeleteTagHandler(serverCtx),
},
{
... ... @@ -85,7 +86,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
rest.WithPrefix("/v1/system"),
)
server.AddRoutes(
... ... @@ -173,4 +174,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article",
Handler: article.MiniCreateArticleHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article/:id",
Handler: article.MiniGetArticleHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
)
}
... ...
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"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniCreateArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCreateArticleLogic {
return &MiniCreateArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
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))
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
//TODO 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
images = append(images, domain.Image{
Url: val,
Width: 0,
Height: 0,
})
}
//检查文章可被哪些人查看
whoRead := []int64{}
if len(req.WhoRead) > 0 {
whoRead = lo.Uniq(req.WhoRead)
var u *domain.User
for _, val := range whoRead {
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, val)
if err != nil {
return nil, xerr.NewErrMsgErr("文章可查看人设置错误", err)
}
if u.CompanyId != author.CompanyId {
return nil, xerr.NewErrMsg("文章可查看人设置错误")
}
}
}
//检查文章可被哪些人评论
whoReview := []int64{}
if len(req.WhoReview) > 0 && len(whoRead) > 0 {
whoReview = lo.Uniq(req.WhoReview)
// 检查 whoRead 是否 完全包含 whoReview
ok := lo.Every(whoRead, whoReview)
if !ok {
return nil, xerr.NewErrMsg("文章可评论人设置错误")
}
}
if len(whoRead) > 0 && len(whoReview) == 0 {
//有指定可查看人 ,但未指定可评论人
return nil, xerr.NewErrMsg("文章可评论人设置错误")
}
// if len(whoRead) == 0 && len(whoReview) > 0 {
// 未指定可查看人(全员可看),有指定可评论人 ,忽略判断
// }
// if len(whoRead) == 0 && len(whoReview) == 0 {
// 未指定可查看人(全员可看),未指定可评论人 ,忽略判断
// }
return
}
... ...
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 MiniGetArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleLogic {
return &MiniGetArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -67,8 +67,8 @@ type User struct {
type TagCreateRequest struct {
CompanyId int64 `json:"companyId"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
... ... @@ -80,8 +80,8 @@ type TagEditRequest struct {
Id int64 `json:"id"`
CompanyId int64 `json:"-"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
... ... @@ -90,7 +90,7 @@ type TagEditResponse struct {
}
type TagGetRequest struct {
Id int64 `path:"id"`
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
... ... @@ -103,16 +103,16 @@ type TagGetResponse struct {
}
type TagListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"-"`
TagName string `json:"tagName,optional"`
Group string `json:"group,optional"`
Remark string `json:"remark,optional"`
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"-"`
TagName string `json:"tagName,optional"`
Group string `json:"group,optional"`
Remark string `json:"remark,optional"`
}
type TagListResponse struct {
Total int64 `json:"total"`
Total int64 `json:"total"`
List []TagItem `json:"list"`
}
... ... @@ -126,7 +126,7 @@ type TagItem struct {
}
type TagDeleteRequest struct {
Id int64 `path:"id"`
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
... ... @@ -134,8 +134,6 @@ type TagDeleteResponse struct {
Id int64 `json:"id"`
}
type MiniUserLoginRequest struct {
LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login
WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码
... ... @@ -240,3 +238,50 @@ type Company struct {
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
Logo string `json:"logo,omitempty"` // 公司LOGO
}
type Location struct {
Longitude float64 `json:"longitude,optional"` //经度
Latitude float64 `json:"latitude,optional"` //纬度
Descript string `json:"descript,optional"` //地点描述
}
type Author struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar"` // 人员头像URL
Group string `json:"group"` // 人员的分组
Position string `json:"position"` // 职位
}
type MiniArticleCreateRequest struct {
Title string `json:"title"` //标题
Section []string `json:"section"` //文章的文本内容
AuthorId int `json:"authorId,optional"` //发布人id
Images []string `json:"images,optional"` //图片
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
Location Location `json:"location,optional"` //定位坐标
}
type MiniArticleCreateResponse struct {
Id int64 `json:"id"`
}
type MiniArticleGetRequest struct {
Id int64 `path:"id"` //id
}
type MiniArticleGetResponse struct {
Title string `json:"title"` //标题
AuthorId int `json:"authorId"` //发布人id
Author Author `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []string `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
WhoRead []int64 `json:"whoRead"` //谁可查看
WhoReview []int64 `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
}
... ...