作者 tangxvhui
... ... @@ -257,7 +257,7 @@
},
"v1/mini/company/search": {
"post": {
"summary": "公司搜索",
"summary": "公司搜索(公开的)",
"operationId": "miniCompanySearch",
"responses": {
"200": {
... ... @@ -283,6 +283,34 @@
]
}
},
"v1/mini/company/search-joined": {
"post": {
"summary": "搜索已加入的公司",
"operationId": "miniCompanySearchJoined",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/CompanySearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/CompanySearchRequest"
}
}
],
"requestBody": {},
"tags": [
"company"
]
}
},
"v1/mini/message/business": {
"post": {
"summary": "业务消息",
... ... @@ -1022,6 +1050,34 @@
]
}
},
"v1/system/user/info": {
"post": {
"summary": "系统用户信息",
"operationId": "systemUserInfo",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserInfoResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemUserInfoRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/user/mylike": {
"post": {
"summary": "我点赞的文章或评论",
... ... @@ -1300,21 +1356,22 @@
"type": "integer",
"format": "int32"
},
"flag": {
"type": "integer",
"format": "int32",
"description": " 1:用户已加入的 2:用户未加入的公司"
},
"userId": {
"type": "integer",
"format": "int64",
"description": " 按用户搜索"
"description": " 按用户搜索(用户所加入的企业)"
},
"code": {
"type": "string",
"description": " 按编码搜索"
}
},
"title": "CompanySearchRequest",
"required": [
"page",
"size"
]
"title": "CompanySearchRequest"
},
"CompanySearchResponse": {
"type": "object",
... ... @@ -2998,6 +3055,40 @@
"list"
]
},
"SystemUserInfoRequest": {
"type": "object",
"title": "SystemUserInfoRequest"
},
"SystemUserInfoResponse": {
"type": "object",
"properties": {
"userId": {
"type": "integer",
"format": "int64"
},
"userName": {
"type": "string"
},
"avatar": {
"type": "string"
},
"companyId": {
"type": "integer",
"format": "int64"
},
"companyName": {
"type": "string"
}
},
"title": "SystemUserInfoResponse",
"required": [
"userId",
"userName",
"avatar",
"companyId",
"companyName"
]
},
"TagCreateRequest": {
"type": "object",
"properties": {
... ...
... ... @@ -32,6 +32,10 @@ service Core {
@handler MiniArticleMarkUserRead
post /article/mark/user_read (MiniArticleMarkUserReadRequest) returns (MiniArticleMarkUserReadResponse)
@doc "小程序获取文章浏览记录"
@handler MiniArticleMarkList
post /article/mark/list (MiniArticleMarkListRequest) returns (MiniArticleMarkListResponse)
@doc "小程序获取我发布的文章"
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
... ...
... ... @@ -255,6 +255,29 @@ type (
}
)
type (
MiniArticleMarkListRequest {
Page int `json:"page"`
Size int `json:"size"`
}
MiniArticleMarkListResponse {
Total int64 `json:"total"`
List []MiniArticleMarkItem `json:"list"`
}
MiniArticleMarkItem {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
UserId int64 `json:"userId"`
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Author SimpleUser `json:"author"` // 发布人
UpdatedAt int64 `json:"updatedAt"`
}
)
//管理后台获取文章详情
type (
SystemArticleGetRequest {
... ...
... ... @@ -14,7 +14,7 @@ info(
group: company
)
service Core {
@doc "公司搜索"
@doc "公司搜索(公开的)"
@handler miniCompanySearch
post /mini/company/search(CompanySearchRequest) returns (CompanySearchResponse)
}
... ... @@ -23,6 +23,18 @@ service Core {
@server(
prefix: v1
group: company
jwt : MiniAuth
)
service Core {
@doc "搜索已加入的公司"
@handler miniCompanySearchJoined
post /mini/company/search-joined(CompanySearchRequest) returns (CompanySearchResponse)
}
// 小程序接口
@server(
prefix: v1
group: company
jwt : SystemAuth
)
service Core {
... ... @@ -33,9 +45,10 @@ service Core {
type (
CompanySearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
UserId int64 `json:"userId,optional"` // 按用户搜索
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
Code string `json:"code,optional"` // 按编码搜索
}
CompanySearchResponse{
... ...
... ... @@ -206,13 +206,26 @@ type (
// 后台接口
//@server(
// prefix: v1
// group: user
// jwt: SystemAuth
//)
//service Core {
// @doc "系统评论"
// @handler systemUser
// get /system/user () returns ()
//}
\ No newline at end of file
@server(
prefix: v1
group: user
jwt: SystemAuth
)
service Core {
@doc "系统用户信息"
@handler systemUserInfo
post /system/user/info(SystemUserInfoRequest) returns (SystemUserInfoResponse)
}
type(
SystemUserInfoRequest{
}
SystemUserInfoResponse{
UserId int64 `json:"userId"`
UserName string `json:"userName"`
Avatar string `json:"avatar"`
CompanyId int64 `json:"companyId"`
CompanyName string `json:"companyName"`
}
)
\ No newline at end of file
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"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 MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleMarkListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniArticleMarkListLogic(r.Context(), svcCtx)
resp, err := l.MiniArticleMarkList(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package company
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/company"
"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 MiniCompanySearchJoinedHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CompanySearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := company.NewMiniCompanySearchJoinedLogic(r.Context(), svcCtx)
resp, err := l.MiniCompanySearchJoined(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -167,6 +167,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/system/user/info",
Handler: user.SystemUserInfoHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/company/search",
Handler: company.MiniCompanySearchHandler(serverCtx),
},
... ... @@ -178,6 +190,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/company/search-joined",
Handler: company.MiniCompanySearchJoinedHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/system/company/search",
Handler: company.SystemCompanySearchHandler(serverCtx),
},
... ... @@ -215,6 +239,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/article/mark/list",
Handler: article.MiniArticleMarkListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.MiniArticleSearchMeHandler(serverCtx),
},
... ...
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"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 SystemUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserInfoRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserInfoLogic(r.Context(), svcCtx)
resp, err := l.SystemUserInfo(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"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 MiniArticleMarkListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleMarkListLogic {
return &MiniArticleMarkListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMarkListRequest) (resp *types.MiniArticleMarkListResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
total, list, err := l.svcCtx.UserReadArticleRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("userId", userToken.UserId))
if err != nil {
return nil, err
}
resp = &types.MiniArticleMarkListResponse{}
resp.Total = total
resp.List = make([]types.MiniArticleMarkItem, 0)
for _, item := range list {
to := types.MiniArticleMarkItem{
Id: item.Id,
CompanyId: item.CompanyId,
ArticleId: item.ArticleId,
Title: item.Title,
Author: types.SimpleUser{
Id: item.Author.Id,
CompanyId: item.Author.CompanyId,
CompanyName: item.Author.Company,
Name: item.Author.Name,
Avatar: item.Author.Avatar,
Position: item.Author.Position,
},
UpdatedAt: item.UpdatedAt,
}
resp.List = append(resp.List, to)
}
return resp, nil
}
... ...
package company
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"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 MiniCompanySearchJoinedLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniCompanySearchJoinedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCompanySearchJoinedLogic {
return &MiniCompanySearchJoinedLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.CompanySearchRequest) (resp *types.CompanySearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
companyList []*domain.Company
total int64
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
user *domain.User
companyIds []int64
)
queryOptions := domain.NewQueryOptions()
if req.Page != 0 {
queryOptions.WithOffsetLimit(req.Page, req.Size)
}
user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId)
if err != nil {
return nil, xerr.NewErrMsgErr("账号有误", err)
}
resp = &types.CompanySearchResponse{
List: make([]types.Company, 0),
}
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
MustWithKV("phone", user.Phone).
MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}).
WithFindOnly())
lo.ForEach(users, func(item *domain.User, index int) {
companyIds = append(companyIds, item.CompanyId)
})
if req.Flag == 1 {
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("ids", companyIds))
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
}
} else {
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyIds))
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
}
}
lo.ForEach(companyList, func(item *domain.Company, index int) {
resp.List = append(resp.List, NewCompany(item))
})
resp.Total = total
return
}
... ...
... ... @@ -2,9 +2,11 @@ package company
import (
"context"
"github.com/samber/lo"
"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/zeromicro/go-zero/core/logx"
)
... ... @@ -24,7 +26,37 @@ func NewMiniCompanySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *MiniCompanySearchLogic) MiniCompanySearch(req *types.CompanySearchRequest) (resp *types.CompanySearchResponse, err error) {
// todo: add your logic here and delete this line
var (
conn = l.svcCtx.DefaultDBConn()
companyList []*domain.Company
total int64
)
queryOptions := domain.NewQueryOptions()
if req.Page != 0 {
queryOptions.WithOffsetLimit(req.Page, req.Size)
}
if req.Code != "" {
queryOptions.WithKV("code", req.Code)
}
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
}
resp = &types.CompanySearchResponse{
Total: total,
List: make([]types.Company, 0),
}
lo.ForEach(companyList, func(item *domain.Company, index int) {
resp.List = append(resp.List, NewCompany(item))
})
return
}
func NewCompany(item *domain.Company) types.Company {
return types.Company{
Id: item.Id,
Name: item.Name,
Code: item.Code,
Logo: item.Logo,
}
}
... ...
package user
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 SystemUserInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserInfoLogic {
return &SystemUserInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (resp *types.SystemUserInfoResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -227,6 +227,26 @@ type MiniArticleDraftDeleteMeResponse struct {
Id int64 `json:"id"` //
}
type MiniArticleMarkListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type MiniArticleMarkListResponse struct {
Total int64 `json:"total"`
List []MiniArticleMarkItem `json:"list"`
}
type MiniArticleMarkItem struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
UserId int64 `json:"userId"`
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Author SimpleUser `json:"author"` // 发布人
UpdatedAt int64 `json:"updatedAt"`
}
type SystemArticleGetRequest struct {
Id int64 `path:"id"` //id
CompanyId int64 `path:",optional"`
... ... @@ -575,10 +595,22 @@ type SimpleComment struct {
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
}
type SystemUserInfoRequest struct {
}
type SystemUserInfoResponse struct {
UserId int64 `json:"userId"`
UserName string `json:"userName"`
Avatar string `json:"avatar"`
CompanyId int64 `json:"companyId"`
CompanyName string `json:"companyName"`
}
type CompanySearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
UserId int64 `json:"userId,optional"` // 按用户搜索
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
Code string `json:"code,optional"` // 按编码搜索
}
... ...
... ... @@ -142,6 +142,9 @@ func (repository *CompanyRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["ids"]; ok {
tx.Where("id in (?)", v)
}
if v, ok := queryOptions["excludeIds"]; ok {
tx.Where("id not in (?)", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...