🏗️ update
This commit is contained in:
2937
.idea/GOHCache.xml
generated
2937
.idea/GOHCache.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -171,6 +171,9 @@ service auth {
|
||||
|
||||
@handler messageWebsocket
|
||||
get /message
|
||||
|
||||
@handler fileWebsocket
|
||||
get /file
|
||||
}
|
||||
|
||||
@server (
|
||||
@@ -249,3 +252,168 @@ service auth {
|
||||
get /slide/generate returns (SlideCaptchaResponse)
|
||||
}
|
||||
|
||||
type (
|
||||
// 评论提交请求参数
|
||||
CommentRequest {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
// 回复评论提交请求参数
|
||||
ReplyCommentRequest {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id" `
|
||||
ReplyId int64 `json:"reply_id" `
|
||||
ReplyUser string `json:"reply_user" `
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
// 回复回复请求参数
|
||||
ReplyReplyRequest {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id"`
|
||||
ReplyTo int64 `json:"reply_to"`
|
||||
ReplyId int64 `json:"reply_id"`
|
||||
ReplyUser string `json:"reply_user" `
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
// 评论列表请求参数
|
||||
CommentListRequest {
|
||||
TopicId string `json:"topic_id"`
|
||||
Page int `json:"page,default=1,optional"`
|
||||
Size int `json:"size,default=5,optional"`
|
||||
IsHot bool `json:"is_hot,default=true,optional"`
|
||||
}
|
||||
// 回复列表请求参数
|
||||
ReplyListRequest {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
Page int `json:"page,default=1,optional"`
|
||||
Size int `json:"size,default=5,optional"`
|
||||
}
|
||||
// 点赞评论的请求参数
|
||||
CommentLikeRequest {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
}
|
||||
CommentDisLikeRequest {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
}
|
||||
)
|
||||
|
||||
// 响应参数
|
||||
type (
|
||||
// CommentContent 评论内容
|
||||
CommentContent {
|
||||
NickName string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Level int64 `json:"level,omitempty" default:"0"`
|
||||
Id int64 `json:"id"`
|
||||
UserId string `json:"user_id"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Content string `json:"content"`
|
||||
ReplyTo int64 `json:"reply_to,omitempty"`
|
||||
ReplyId int64 `json:"reply_id,omitempty"`
|
||||
ReplyUser string `json:"reply_user,omitempty"`
|
||||
ReplyNickname string `json:"reply_nickname,omitempty"`
|
||||
IsAuthor int64 `json:"is_author"`
|
||||
Likes int64 `json:"likes"`
|
||||
ReplyCount int64 `json:"reply_count"`
|
||||
CreatedTime string `json:"created_time"`
|
||||
Location string `json:"location"`
|
||||
Browser string `json:"browser"`
|
||||
OperatingSystem string `json:"operating_system"`
|
||||
IsLiked bool `json:"is_liked" default:"false"`
|
||||
Images []string `json:"images,omitempty"`
|
||||
}
|
||||
// CommentListPageResponse 评论返回值
|
||||
CommentListPageResponse {
|
||||
Size int `json:"size"`
|
||||
Total int64 `json:"total"`
|
||||
Current int `json:"current"`
|
||||
Comments []CommentContent `json:"comments"`
|
||||
}
|
||||
// CommentResponse 提交评论响应
|
||||
CommentResponse {
|
||||
Id int64 `json:"id"`
|
||||
Content string `json:"content"`
|
||||
UserId string `json:"user_id"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Author int64 `json:"author"`
|
||||
Location string `json:"location"`
|
||||
Browser string `json:"browser"`
|
||||
OperatingSystem string `json:"operating_system"`
|
||||
CreatedTime string `json:"created_time"`
|
||||
ReplyId int64 `json:"reply_id,omitempty"`
|
||||
ReplyUser string `json:"reply_user,omitempty"`
|
||||
ReplyTo int64 `json:"reply_to,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
group: comment // 微服务分组
|
||||
prefix: /api/auth/comment // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 1048576 // 最大请求大小
|
||||
signature: false // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware,CasbinVerifyMiddleware,AuthorizationMiddleware,NonceMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
jwt: Auth // 是否开启jwt验证
|
||||
)
|
||||
service auth {
|
||||
@handler getCommentList
|
||||
post /list (CommentListRequest) returns (CommentListPageResponse)
|
||||
|
||||
@handler getReplyList
|
||||
post /reply/list (ReplyListRequest) returns (CommentListPageResponse)
|
||||
|
||||
@handler submitComment
|
||||
post /submit (CommentRequest) returns (CommentResponse)
|
||||
|
||||
@handler submitReplyComment
|
||||
post /reply/submit (ReplyCommentRequest) returns (CommentResponse)
|
||||
|
||||
@handler submitReplyReply
|
||||
post /reply/reply/submit (ReplyReplyRequest) returns (CommentResponse)
|
||||
|
||||
@handler likeComment
|
||||
post /like (CommentLikeRequest)
|
||||
|
||||
@handler dislikeComment
|
||||
post /dislike (CommentDisLikeRequest)
|
||||
}
|
||||
|
||||
// 上传图片请求参数
|
||||
type (
|
||||
UploadRequest {
|
||||
Image string `json:"image"`
|
||||
AccessToken string `json:"access_token"`
|
||||
userId string `json:"user_id"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
group: upscale // 微服务分组
|
||||
prefix: /api/auth/upscale // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 10485760 // 最大请求大小
|
||||
signature: false // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware,NonceMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
)
|
||||
service auth {
|
||||
@handler uploadImage
|
||||
post /upload (UploadRequest)
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/auth.yaml", "the config file")
|
||||
var configFile = flag.String("f", "api/etc/auth.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
@@ -3,7 +3,7 @@ Name: schisandra-auth-service
|
||||
# 监听地址
|
||||
Host: 0.0.0.0
|
||||
# 监听端口
|
||||
Port: 8080
|
||||
Port: 80
|
||||
# 服务的环境,目前我们预定义了 dev。在dev 环境我们会开启反射 dev,test,rt,pre, pro
|
||||
Mode: pro
|
||||
# 打点上报,将一些 metrics 上报到对应的地址,如果为空,则不上报
|
||||
@@ -64,6 +64,18 @@ Mysql:
|
||||
MaxOpenConn: 10
|
||||
# 最大空闲连接数
|
||||
MaxIdleConn: 5
|
||||
# Mongo 配置
|
||||
Mongo:
|
||||
# MongoDB 地址
|
||||
Uri: mongodb://1.95.0.111:27017
|
||||
# MongoDB 用户名
|
||||
Username: landaiqing
|
||||
# MongoDB 密码
|
||||
Password: LDQ20020618xxx
|
||||
# MongoDB 数据库
|
||||
Database: schisandra-cloud-album
|
||||
# MongoDB 认证源
|
||||
AuthSource: admin
|
||||
# Auth 配置
|
||||
Auth:
|
||||
# 访问密钥
|
||||
@@ -77,7 +89,7 @@ Signature:
|
||||
# 签名私钥文件
|
||||
PrivateKeys:
|
||||
- Fingerprint: idm0jdoau38lwourb4pbjk4dxkat0kcx
|
||||
KeyFile: etc/rsa_private_key.pem
|
||||
KeyFile: api/etc/rsa_private_key.pem
|
||||
# 加密配置
|
||||
Encrypt:
|
||||
# 密钥(32)
|
||||
|
@@ -19,6 +19,13 @@ type Config struct {
|
||||
MaxOpenConn int
|
||||
MaxIdleConn int
|
||||
}
|
||||
Mongo struct {
|
||||
Uri string
|
||||
Username string
|
||||
Password string
|
||||
AuthSource string
|
||||
Database string
|
||||
}
|
||||
Redis struct {
|
||||
Host string
|
||||
Pass string
|
||||
|
@@ -3,9 +3,10 @@ package comment
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
@@ -3,9 +3,9 @@ package comment
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
@@ -3,9 +3,10 @@ package comment
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
@@ -3,9 +3,10 @@ package comment
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
@@ -3,9 +3,10 @@ package comment
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
@@ -3,9 +3,10 @@ package comment
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
@@ -3,9 +3,10 @@ package comment
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
@@ -9,9 +9,11 @@ import (
|
||||
|
||||
captcha "schisandra-album-cloud-microservices/app/auth/api/internal/handler/captcha"
|
||||
client "schisandra-album-cloud-microservices/app/auth/api/internal/handler/client"
|
||||
comment "schisandra-album-cloud-microservices/app/auth/api/internal/handler/comment"
|
||||
oauth "schisandra-album-cloud-microservices/app/auth/api/internal/handler/oauth"
|
||||
sms "schisandra-album-cloud-microservices/app/auth/api/internal/handler/sms"
|
||||
token "schisandra-album-cloud-microservices/app/auth/api/internal/handler/token"
|
||||
upscale "schisandra-album-cloud-microservices/app/auth/api/internal/handler/upscale"
|
||||
user "schisandra-album-cloud-microservices/app/auth/api/internal/handler/user"
|
||||
websocket "schisandra-album-cloud-microservices/app/auth/api/internal/handler/websocket"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
@@ -57,6 +59,53 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.CasbinVerifyMiddleware, serverCtx.AuthorizationMiddleware, serverCtx.NonceMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/dislike",
|
||||
Handler: comment.DislikeCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/like",
|
||||
Handler: comment.LikeCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/list",
|
||||
Handler: comment.GetCommentListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/list",
|
||||
Handler: comment.GetReplyListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/reply/submit",
|
||||
Handler: comment.SubmitReplyReplyHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/submit",
|
||||
Handler: comment.SubmitReplyCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/submit",
|
||||
Handler: comment.SubmitCommentHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/auth/comment"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
|
||||
@@ -151,6 +200,22 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/upload",
|
||||
Handler: upscale.UploadImageHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/auth/upscale"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(10485760),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
|
||||
@@ -190,6 +255,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/file",
|
||||
Handler: websocket.FileWebsocketHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/message",
|
||||
|
@@ -3,9 +3,9 @@ package upscale
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/logic/upscale"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/upscale"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
@@ -2,8 +2,8 @@ package websocket
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
func FileWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
@@ -5,8 +5,8 @@ import (
|
||||
"errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
)
|
@@ -5,10 +5,10 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
types2 "schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mongodb"
|
||||
constant2 "schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"sync"
|
||||
|
||||
@@ -32,13 +32,13 @@ func NewGetCommentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetCommentListLogic) GetCommentList(req *types2.CommentListRequest) (resp *types2.CommentListPageResponse, err error) {
|
||||
func (l *GetCommentListLogic) GetCommentList(req *types.CommentListRequest) (resp *types.CommentListPageResponse, err error) {
|
||||
// 获取用户ID
|
||||
uid, ok := l.ctx.Value("user_id").(string)
|
||||
if !ok {
|
||||
return nil, errors.New("user_id not found")
|
||||
}
|
||||
var commentQueryList []types2.CommentListQueryResult
|
||||
var commentQueryList []types.CommentListQueryResult
|
||||
comment := l.svcCtx.DB.ScaCommentReply
|
||||
user := l.svcCtx.DB.ScaAuthUser
|
||||
var orderConditions []field.Expr
|
||||
@@ -63,18 +63,18 @@ func (l *GetCommentListLogic) GetCommentList(req *types2.CommentListRequest) (re
|
||||
user.Avatar,
|
||||
user.Nickname,
|
||||
).LeftJoin(user, comment.UserID.EqCol(user.UID)).
|
||||
Where(comment.TopicID.Eq(req.TopicId), comment.CommentType.Eq(constant2.COMMENT)).
|
||||
Where(comment.TopicID.Eq(req.TopicId), comment.CommentType.Eq(constant.COMMENT)).
|
||||
Order(orderConditions...).
|
||||
ScanByPage(&commentQueryList, (req.Page-1)*req.Size, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count == 0 || len(commentQueryList) == 0 {
|
||||
return &types2.CommentListPageResponse{
|
||||
return &types.CommentListPageResponse{
|
||||
Total: count,
|
||||
Size: req.Size,
|
||||
Current: req.Page,
|
||||
Comments: []types2.CommentContent{},
|
||||
Comments: []types.CommentContent{},
|
||||
}, nil
|
||||
}
|
||||
// **************** 获取评论Id和用户Id ************
|
||||
@@ -106,7 +106,7 @@ func (l *GetCommentListLogic) GetCommentList(req *types2.CommentListRequest) (re
|
||||
commentImageMap := make(map[int64][]string)
|
||||
go func() {
|
||||
defer l.wg.Done()
|
||||
newCollection := mongodb.MustNewCollection[types2.CommentImages](l.svcCtx.MongoClient, constant2.COMMENT_IMAGES)
|
||||
newCollection := mongodb.MustNewCollection[types.CommentImages](l.svcCtx.MongoClient, constant.COMMENT_IMAGES)
|
||||
commentImages, err := newCollection.Finder().
|
||||
Filter(query.Eq("topic_id", req.TopicId)).
|
||||
Filter(query.In("comment_id", commentIds...)).
|
||||
@@ -130,13 +130,13 @@ func (l *GetCommentListLogic) GetCommentList(req *types2.CommentListRequest) (re
|
||||
l.wg.Wait()
|
||||
|
||||
// *************** 组装数据 **********
|
||||
result := make([]types2.CommentContent, 0, len(commentQueryList))
|
||||
result := make([]types.CommentContent, 0, len(commentQueryList))
|
||||
for _, commentData := range commentQueryList {
|
||||
commentContent := types2.CommentContent{
|
||||
commentContent := types.CommentContent{
|
||||
Avatar: commentData.Avatar,
|
||||
NickName: commentData.Nickname,
|
||||
Content: commentData.Content,
|
||||
CreatedTime: commentData.CreatedAt.Format(constant2.TimeFormat),
|
||||
CreatedTime: commentData.CreatedAt.Format(constant.TimeFormat),
|
||||
Level: 0,
|
||||
Id: commentData.ID,
|
||||
UserId: commentData.UserID,
|
||||
@@ -152,7 +152,7 @@ func (l *GetCommentListLogic) GetCommentList(req *types2.CommentListRequest) (re
|
||||
}
|
||||
result = append(result, commentContent)
|
||||
}
|
||||
commentListPageResponse := &types2.CommentListPageResponse{
|
||||
commentListPageResponse := &types.CommentListPageResponse{
|
||||
Total: count,
|
||||
Size: req.Size,
|
||||
Current: req.Page,
|
@@ -5,10 +5,10 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
types2 "schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mongodb"
|
||||
constant2 "schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"sync"
|
||||
|
||||
@@ -32,13 +32,13 @@ func NewGetReplyListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetR
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetReplyListLogic) GetReplyList(req *types2.ReplyListRequest) (resp *types2.CommentListPageResponse, err error) {
|
||||
func (l *GetReplyListLogic) GetReplyList(req *types.ReplyListRequest) (resp *types.CommentListPageResponse, err error) {
|
||||
// 获取用户ID
|
||||
uid, ok := l.ctx.Value("user_id").(string)
|
||||
if !ok {
|
||||
return nil, errors.New("user_id not found")
|
||||
}
|
||||
var replyQueryList []types2.ReplyListQueryResult
|
||||
var replyQueryList []types.ReplyListQueryResult
|
||||
reply := l.svcCtx.DB.ScaCommentReply
|
||||
user := l.svcCtx.DB.ScaAuthUser
|
||||
commentUser := user.As("comment_user")
|
||||
@@ -64,14 +64,14 @@ func (l *GetReplyListLogic) GetReplyList(req *types2.ReplyListRequest) (resp *ty
|
||||
replyUser.Nickname.As("reply_nickname"),
|
||||
).LeftJoin(commentUser, reply.UserID.EqCol(commentUser.UID)).
|
||||
LeftJoin(replyUser, reply.ReplyUser.EqCol(replyUser.UID)).
|
||||
Where(reply.TopicID.Eq(req.TopicId), reply.ReplyID.Eq(req.CommentId), reply.CommentType.Eq(constant2.REPLY)).
|
||||
Where(reply.TopicID.Eq(req.TopicId), reply.ReplyID.Eq(req.CommentId), reply.CommentType.Eq(constant.REPLY)).
|
||||
Order(reply.Likes.Desc(), reply.CreatedAt.Desc()).
|
||||
ScanByPage(&replyQueryList, (req.Page-1)*req.Size, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count == 0 || len(replyQueryList) == 0 {
|
||||
return &types2.CommentListPageResponse{
|
||||
return &types.CommentListPageResponse{
|
||||
Total: count,
|
||||
Size: req.Size,
|
||||
Current: req.Page,
|
||||
@@ -106,7 +106,7 @@ func (l *GetReplyListLogic) GetReplyList(req *types2.ReplyListRequest) (resp *ty
|
||||
commentImageMap := make(map[int64][]string)
|
||||
go func() {
|
||||
defer l.wg.Done()
|
||||
newCollection := mongodb.MustNewCollection[types2.CommentImages](l.svcCtx.MongoClient, constant2.COMMENT_IMAGES)
|
||||
newCollection := mongodb.MustNewCollection[types.CommentImages](l.svcCtx.MongoClient, constant.COMMENT_IMAGES)
|
||||
commentImages, err := newCollection.Finder().
|
||||
Filter(query.Eq("topic_id", req.TopicId)).
|
||||
Filter(query.In("comment_id", commentIds...)).
|
||||
@@ -130,13 +130,13 @@ func (l *GetReplyListLogic) GetReplyList(req *types2.ReplyListRequest) (resp *ty
|
||||
l.wg.Wait()
|
||||
|
||||
// *************** 组装数据 **********
|
||||
result := make([]types2.CommentContent, 0, len(replyQueryList))
|
||||
result := make([]types.CommentContent, 0, len(replyQueryList))
|
||||
for _, replyData := range replyQueryList {
|
||||
commentContent := types2.CommentContent{
|
||||
commentContent := types.CommentContent{
|
||||
Avatar: replyData.Avatar,
|
||||
NickName: replyData.Nickname,
|
||||
Content: replyData.Content,
|
||||
CreatedTime: replyData.CreatedAt.Format(constant2.TimeFormat),
|
||||
CreatedTime: replyData.CreatedAt.Format(constant.TimeFormat),
|
||||
Level: 0,
|
||||
Id: replyData.ID,
|
||||
UserId: replyData.UserID,
|
||||
@@ -156,7 +156,7 @@ func (l *GetReplyListLogic) GetReplyList(req *types2.ReplyListRequest) (resp *ty
|
||||
}
|
||||
result = append(result, commentContent)
|
||||
}
|
||||
commentListPageResponse := &types2.CommentListPageResponse{
|
||||
commentListPageResponse := &types.CommentListPageResponse{
|
||||
Total: count,
|
||||
Size: req.Size,
|
||||
Current: req.Page,
|
@@ -3,9 +3,9 @@ package comment
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
"time"
|
||||
|
@@ -4,10 +4,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/captcha/verify"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/captcha/verify"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/captcha/verify"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
model2 "schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
"strconv"
|
||||
@@ -119,7 +119,7 @@ func (l *GiteeCallbackLogic) GiteeCallback(r *http.Request, req *types.OAuthCall
|
||||
// 创建用户
|
||||
uid := idgen.NextId()
|
||||
uidStr := strconv.FormatInt(uid, 10)
|
||||
addUser := &model.ScaAuthUser{
|
||||
addUser := &model2.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Avatar: giteeUser.AvatarURL,
|
||||
Username: giteeUser.Login,
|
||||
@@ -134,7 +134,7 @@ func (l *GiteeCallbackLogic) GiteeCallback(r *http.Request, req *types.OAuthCall
|
||||
return "", err
|
||||
}
|
||||
gitee := constant.OAuthSourceGitee
|
||||
newSocialUser := &model.ScaAuthUserSocial{
|
||||
newSocialUser := &model2.ScaAuthUserSocial{
|
||||
UserID: uidStr,
|
||||
OpenID: Id,
|
||||
Source: gitee,
|
||||
@@ -180,7 +180,7 @@ func (l *GiteeCallbackLogic) GiteeCallback(r *http.Request, req *types.OAuthCall
|
||||
}
|
||||
|
||||
// HandleOauthLoginResponse 处理登录响应
|
||||
func HandleOauthLoginResponse(scaAuthUser *model.ScaAuthUser, svcCtx *svc.ServiceContext, r *http.Request, ctx context.Context) (string, error) {
|
||||
func HandleOauthLoginResponse(scaAuthUser *model2.ScaAuthUser, svcCtx *svc.ServiceContext, r *http.Request, ctx context.Context) (string, error) {
|
||||
data, err := user.HandleLoginJWT(scaAuthUser, svcCtx, true, r, ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
model2 "schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"strconv"
|
||||
|
||||
@@ -117,7 +117,7 @@ func (l *GithubCallbackLogic) GithubCallback(r *http.Request, req *types.OAuthCa
|
||||
uidStr := strconv.FormatInt(uid, 10)
|
||||
|
||||
male := constant.Male
|
||||
addUser := &model.ScaAuthUser{
|
||||
addUser := &model2.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Avatar: gitHubUser.AvatarURL,
|
||||
Username: gitHubUser.Login,
|
||||
@@ -133,7 +133,7 @@ func (l *GithubCallbackLogic) GithubCallback(r *http.Request, req *types.OAuthCa
|
||||
return "", err
|
||||
}
|
||||
githubUser := constant.OAuthSourceGithub
|
||||
newSocialUser := &model.ScaAuthUserSocial{
|
||||
newSocialUser := &model2.ScaAuthUserSocial{
|
||||
UserID: uidStr,
|
||||
OpenID: Id,
|
||||
Source: githubUser,
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
model2 "schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -119,7 +119,7 @@ func (l *QqCallbackLogic) QqCallback(r *http.Request, req *types.OAuthCallbackRe
|
||||
|
||||
male := constant.Male
|
||||
avatarUrl := strings.Replace(qqUserInfo.FigureurlQq1, "http://", "https://", 1)
|
||||
addUser := &model.ScaAuthUser{
|
||||
addUser := &model2.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Avatar: avatarUrl,
|
||||
Username: authQQme.OpenID,
|
||||
@@ -133,7 +133,7 @@ func (l *QqCallbackLogic) QqCallback(r *http.Request, req *types.OAuthCallbackRe
|
||||
}
|
||||
|
||||
githubUser := constant.OAuthSourceQQ
|
||||
newSocialUser := &model.ScaAuthUserSocial{
|
||||
newSocialUser := &model2.ScaAuthUserSocial{
|
||||
UserID: uidStr,
|
||||
OpenID: authQQme.OpenID,
|
||||
Source: githubUser,
|
||||
|
@@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
"github.com/mssola/useragent"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/query"
|
||||
model2 "schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
query2 "schisandra-album-cloud-microservices/app/auth/model/mysql/query"
|
||||
"schisandra-album-cloud-microservices/common/captcha/verify"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
@@ -44,7 +44,7 @@ func (l *AccountLoginLogic) AccountLogin(r *http.Request, req *types.AccountLogi
|
||||
}
|
||||
|
||||
user := l.svcCtx.DB.ScaAuthUser
|
||||
var selectedUser query.IScaAuthUserDo
|
||||
var selectedUser query2.IScaAuthUserDo
|
||||
|
||||
switch {
|
||||
case utils.IsPhone(req.Account):
|
||||
@@ -75,7 +75,7 @@ func (l *AccountLoginLogic) AccountLogin(r *http.Request, req *types.AccountLogi
|
||||
}
|
||||
|
||||
// HandleLoginJWT 处理用户登录
|
||||
func HandleLoginJWT(user *model.ScaAuthUser, svcCtx *svc.ServiceContext, autoLogin bool, r *http.Request, ctx context.Context) (*types.LoginResponse, error) {
|
||||
func HandleLoginJWT(user *model2.ScaAuthUser, svcCtx *svc.ServiceContext, autoLogin bool, r *http.Request, ctx context.Context) (*types.LoginResponse, error) {
|
||||
// 获取用户登录设备
|
||||
err := GetUserLoginDevice(user.UID, r, svcCtx.Ip2Region, svcCtx.DB)
|
||||
if err != nil {
|
||||
@@ -124,7 +124,7 @@ func HandleLoginJWT(user *model.ScaAuthUser, svcCtx *svc.ServiceContext, autoLog
|
||||
}
|
||||
|
||||
// GetUserLoginDevice 获取用户登录设备
|
||||
func GetUserLoginDevice(userId string, r *http.Request, ip2location *xdb.Searcher, DB *query.Query) error {
|
||||
func GetUserLoginDevice(userId string, r *http.Request, ip2location *xdb.Searcher, DB *query2.Query) error {
|
||||
userAgent := r.UserAgent()
|
||||
if userAgent == "" {
|
||||
return errors2.New("user agent not found")
|
||||
@@ -157,7 +157,7 @@ func GetUserLoginDevice(userId string, r *http.Request, ip2location *xdb.Searche
|
||||
if err != nil && !errors2.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
newDevice := &model.ScaAuthUserDevice{
|
||||
newDevice := &model2.ScaAuthUserDevice{
|
||||
UserID: userId,
|
||||
Bot: newIsBot,
|
||||
Agent: userAgent,
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
constant2 "schisandra-album-cloud-microservices/common/constant"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/yitter/idgenerator-go/idgen"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
model2 "schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/encrypt"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
||||
@@ -61,7 +61,7 @@ func (l *WechatOffiaccountLoginLogic) WechatOffiaccountLogin(r *http.Request, re
|
||||
avatar := utils.GenerateAvatar(uidStr)
|
||||
name := randomname.GenerateName()
|
||||
|
||||
addUser := &model.ScaAuthUser{
|
||||
addUser := &model2.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Avatar: avatar,
|
||||
Username: Openid,
|
||||
@@ -74,7 +74,7 @@ func (l *WechatOffiaccountLoginLogic) WechatOffiaccountLogin(r *http.Request, re
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newSocialUser := &model.ScaAuthUserSocial{
|
||||
newSocialUser := &model2.ScaAuthUserSocial{
|
||||
UserID: uidStr,
|
||||
OpenID: Openid,
|
||||
Source: constant.OAuthSourceWechat,
|
||||
|
@@ -5,7 +5,8 @@ import (
|
||||
"fmt"
|
||||
"github.com/lxzan/gws"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/file/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/jwt"
|
||||
"time"
|
||||
|
||||
@@ -26,11 +27,6 @@ func NewFileWebsocketLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Fil
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
PingInterval = 5 * time.Second // 客户端心跳间隔
|
||||
HeartbeatWaitTimeout = 10 * time.Second // 心跳等待超时时间
|
||||
)
|
||||
|
||||
type FileWebSocket struct {
|
||||
ctx context.Context
|
||||
gws.BuiltinEventHandler
|
||||
@@ -128,11 +124,3 @@ func (c *FileWebSocket) SendMessageToClient(clientId string, message []byte) err
|
||||
}
|
||||
return fmt.Errorf("client %s not found", clientId)
|
||||
}
|
||||
|
||||
// MustLoad 从session中加载数据
|
||||
func MustLoad[T any](session gws.SessionStorage, key string) (v T) {
|
||||
if value, exist := session.Load(key); exist {
|
||||
v = value.(T)
|
||||
}
|
||||
return
|
||||
}
|
@@ -8,14 +8,18 @@ import (
|
||||
"github.com/wenlng/go-captcha/v2/rotate"
|
||||
"github.com/wenlng/go-captcha/v2/slide"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
sensitive "github.com/zmexing/go-sensitive-word"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/config"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/middleware"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/query"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/query"
|
||||
"schisandra-album-cloud-microservices/common/captcha/initialize"
|
||||
"schisandra-album-cloud-microservices/common/casbinx"
|
||||
"schisandra-album-cloud-microservices/common/ip2region"
|
||||
"schisandra-album-cloud-microservices/common/redisx"
|
||||
"schisandra-album-cloud-microservices/common/sensitivex"
|
||||
"schisandra-album-cloud-microservices/common/wechat_official"
|
||||
)
|
||||
|
||||
@@ -30,9 +34,10 @@ type ServiceContext struct {
|
||||
Ip2Region *xdb.Searcher
|
||||
CasbinEnforcer *casbin.SyncedCachedEnforcer
|
||||
WechatOfficial *officialAccount.OfficialAccount
|
||||
|
||||
RotateCaptcha rotate.Captcha
|
||||
SlideCaptcha slide.Captcha
|
||||
MongoClient *mongo.Database
|
||||
RotateCaptcha rotate.Captcha
|
||||
SlideCaptcha slide.Captcha
|
||||
Sensitive *sensitive.Manager
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
@@ -52,5 +57,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
WechatOfficial: wechat_official.NewWechatPublic(c.Wechat.AppID, c.Wechat.AppSecret, c.Wechat.Token, c.Wechat.AESKey, c.Redis.Host, c.Redis.Pass, c.Redis.DB),
|
||||
RotateCaptcha: initialize.NewRotateCaptcha(),
|
||||
SlideCaptcha: initialize.NewSlideCaptcha(),
|
||||
MongoClient: mongodb.NewMongoDB(c.Mongo.Uri, c.Mongo.Username, c.Mongo.Password, c.Mongo.AuthSource, c.Mongo.Database),
|
||||
Sensitive: sensitivex.NewSensitive(),
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,77 @@ type AccountLoginRequest struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type CommentContent struct {
|
||||
NickName string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Level int64 `json:"level,omitempty" default:"0"`
|
||||
Id int64 `json:"id"`
|
||||
UserId string `json:"user_id"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Content string `json:"content"`
|
||||
ReplyTo int64 `json:"reply_to,omitempty"`
|
||||
ReplyId int64 `json:"reply_id,omitempty"`
|
||||
ReplyUser string `json:"reply_user,omitempty"`
|
||||
ReplyNickname string `json:"reply_nickname,omitempty"`
|
||||
IsAuthor int64 `json:"is_author"`
|
||||
Likes int64 `json:"likes"`
|
||||
ReplyCount int64 `json:"reply_count"`
|
||||
CreatedTime string `json:"created_time"`
|
||||
Location string `json:"location"`
|
||||
Browser string `json:"browser"`
|
||||
OperatingSystem string `json:"operating_system"`
|
||||
IsLiked bool `json:"is_liked" default:"false"`
|
||||
Images []string `json:"images,omitempty"`
|
||||
}
|
||||
|
||||
type CommentDisLikeRequest struct {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
}
|
||||
|
||||
type CommentLikeRequest struct {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
}
|
||||
|
||||
type CommentListPageResponse struct {
|
||||
Size int `json:"size"`
|
||||
Total int64 `json:"total"`
|
||||
Current int `json:"current"`
|
||||
Comments []CommentContent `json:"comments"`
|
||||
}
|
||||
|
||||
type CommentListRequest struct {
|
||||
TopicId string `json:"topic_id"`
|
||||
Page int `json:"page,default=1,optional"`
|
||||
Size int `json:"size,default=5,optional"`
|
||||
IsHot bool `json:"is_hot,default=true,optional"`
|
||||
}
|
||||
|
||||
type CommentRequest struct {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
|
||||
type CommentResponse struct {
|
||||
Id int64 `json:"id"`
|
||||
Content string `json:"content"`
|
||||
UserId string `json:"user_id"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Author int64 `json:"author"`
|
||||
Location string `json:"location"`
|
||||
Browser string `json:"browser"`
|
||||
OperatingSystem string `json:"operating_system"`
|
||||
CreatedTime string `json:"created_time"`
|
||||
ReplyId int64 `json:"reply_id,omitempty"`
|
||||
ReplyUser string `json:"reply_user,omitempty"`
|
||||
ReplyTo int64 `json:"reply_to,omitempty"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpireAt int64 `json:"expire_at"`
|
||||
@@ -44,6 +115,36 @@ type RefreshTokenResponse struct {
|
||||
ExpireAt int64 `json:"expire_at"`
|
||||
}
|
||||
|
||||
type ReplyCommentRequest struct {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id" `
|
||||
ReplyId int64 `json:"reply_id" `
|
||||
ReplyUser string `json:"reply_user" `
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
|
||||
type ReplyListRequest struct {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
Page int `json:"page,default=1,optional"`
|
||||
Size int `json:"size,default=5,optional"`
|
||||
}
|
||||
|
||||
type ReplyReplyRequest struct {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id"`
|
||||
ReplyTo int64 `json:"reply_to"`
|
||||
ReplyId int64 `json:"reply_id"`
|
||||
ReplyUser string `json:"reply_user" `
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
|
||||
type ResetPasswordRequest struct {
|
||||
Phone string `json:"phone"`
|
||||
Captcha string `json:"captcha"`
|
||||
@@ -73,6 +174,12 @@ type SmsSendRequest struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type UploadRequest struct {
|
||||
Image string `json:"image"`
|
||||
AccessToken string `json:"access_token"`
|
||||
UserId string `json:"user_id"`
|
||||
}
|
||||
|
||||
type WechatOffiaccountLoginRequest struct {
|
||||
Openid string `json:"openid"`
|
||||
ClientId string `json:"client_id"`
|
||||
|
@@ -1,107 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const MySQLDSN = "root:1611@(localhost:3306)/schisandra-cloud-album?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
|
||||
func main() {
|
||||
|
||||
// 连接数据库
|
||||
db, err := gorm.Open(mysql.Open(MySQLDSN))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
path := filepath.Join(dir, "app/auth/api/model/mysql/", "query")
|
||||
// 生成实例
|
||||
g := gen.NewGenerator(gen.Config{
|
||||
// 相对执行`go run`时的路径, 会自动创建目录
|
||||
OutPath: path,
|
||||
// 生成的文件名,默认gen.go
|
||||
OutFile: "gen.go",
|
||||
// 生成DAO代码的包名,默认是:model
|
||||
ModelPkgPath: "model",
|
||||
// 是否为DAO包生成单元测试代码,默认:false
|
||||
WithUnitTest: false,
|
||||
|
||||
// WithDefaultQuery 生成默认查询结构体(作为全局变量使用), 即`Q`结构体和其字段(各表模型)
|
||||
// WithoutContext 生成没有context调用限制的代码供查询
|
||||
// WithQueryInterface 生成interface形式的查询代码(可导出), 如`Where()`方法返回的就是一个可导出的接口类型
|
||||
Mode: gen.WithDefaultQuery | gen.WithQueryInterface | gen.WithoutContext,
|
||||
|
||||
// 表字段可为 null 值时, 对应结体字段使用指针类型
|
||||
FieldNullable: false, // generate pointer when field is nullable
|
||||
|
||||
// 表字段默认值与模型结构体字段零值不一致的字段, 在插入数据时需要赋值该字段值为零值的, 结构体字段须是指针类型才能成功, 即`FieldCoverable:true`配置下生成的结构体字段.
|
||||
// 因为在插入时遇到字段为零值的会被GORM赋予默认值. 如字段`age`表默认值为10, 即使你显式设置为0最后也会被GORM设为10提交.
|
||||
// 如果该字段没有上面提到的插入时赋零值的特殊需要, 则字段为非指针类型使用起来会比较方便.
|
||||
FieldCoverable: true,
|
||||
|
||||
// 模型结构体字段的数字类型的符号表示是否与表字段的一致, `false`指示都用有符号类型
|
||||
FieldSignable: false,
|
||||
// 生成 gorm 标签的字段索引属性
|
||||
FieldWithIndexTag: true,
|
||||
// 生成 gorm 标签的字段类型属性
|
||||
FieldWithTypeTag: true,
|
||||
})
|
||||
// 设置目标 db
|
||||
g.UseDB(db)
|
||||
|
||||
// 自定义字段的数据类型
|
||||
// 统一数字类型为int64,兼容protobuf
|
||||
dataMap := map[string]func(columnType gorm.ColumnType) (dataType string){
|
||||
"tinyint": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
"smallint": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
"mediumint": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
"bigint": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
"int": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
}
|
||||
// 要先于`ApplyBasic`执行
|
||||
g.WithDataTypeMap(dataMap)
|
||||
|
||||
// 自定义模型结体字段的标签
|
||||
// 将特定字段名的 json 标签加上`string`属性,即 MarshalJSON 时该字段由数字类型转成字符串类型
|
||||
jsonField := gen.FieldJSONTagWithNS(func(columnName string) (tagContent string) {
|
||||
toStringField := `id, `
|
||||
if strings.Contains(toStringField, columnName) {
|
||||
return columnName + ",string"
|
||||
}
|
||||
return columnName
|
||||
})
|
||||
// 将非默认字段名的字段定义为自动时间戳和软删除字段;
|
||||
// 自动时间戳默认字段名为:`updated_at`、`created_at, 表字段数据类型为: INT 或 DATETIME
|
||||
// 软删除默认字段名为:`deleted_at`, 表字段数据类型为: DATETIME
|
||||
idField := gen.FieldGORMTag("id", func(tag field.GormTag) field.GormTag {
|
||||
return tag.Append("primary_key")
|
||||
})
|
||||
autoUpdateTimeField := gen.FieldGORMTag("updated_at", func(tag field.GormTag) field.GormTag {
|
||||
return tag.Append("autoUpdateTime")
|
||||
})
|
||||
autoCreateTimeField := gen.FieldGORMTag("created_at", func(tag field.GormTag) field.GormTag {
|
||||
return tag.Append("autoCreateTime")
|
||||
})
|
||||
softDeleteField := gen.FieldType("delete_at", "gorm.DeletedAt")
|
||||
versionField := gen.FieldType("version", "optimisticlock.Version")
|
||||
// 模型自定义选项组
|
||||
fieldOpts := []gen.ModelOpt{jsonField, idField, autoUpdateTimeField, autoCreateTimeField, softDeleteField, versionField}
|
||||
|
||||
// 创建全部模型文件, 并覆盖前面创建的同名模型
|
||||
allModel := g.GenerateAllTable(fieldOpts...)
|
||||
|
||||
g.ApplyBasic(allModel...)
|
||||
|
||||
g.Execute()
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
package mysql
|
||||
|
||||
import (
|
||||
"github.com/asjdf/gorm-cache/cache"
|
||||
"github.com/asjdf/gorm-cache/config"
|
||||
"github.com/asjdf/gorm-cache/storage"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"log"
|
||||
"os"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/query"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewMySQL(url string, maxOpenConn int, maxIdleConn int, client *redis.Client) (*gorm.DB, *query.Query) {
|
||||
db, err := gorm.Open(mysql.Open(url), &gorm.Config{
|
||||
SkipDefaultTransaction: true,
|
||||
PrepareStmt: true,
|
||||
Logger: logger.New(
|
||||
log.New(os.Stdout, "\r\n", log.LstdFlags),
|
||||
logger.Config{
|
||||
SlowThreshold: time.Second, // 慢sql日志
|
||||
LogLevel: logger.Error, // 级别
|
||||
Colorful: true, // 颜色
|
||||
IgnoreRecordNotFoundError: true, // 忽略RecordNotFoundError
|
||||
ParameterizedQueries: true, // 格式化SQL语句
|
||||
}),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
sqlDB, err := db.DB()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
sqlDB.SetMaxOpenConns(maxOpenConn)
|
||||
sqlDB.SetMaxIdleConns(maxIdleConn)
|
||||
useDB := query.Use(db)
|
||||
// cache
|
||||
gormCache, err := cache.NewGorm2Cache(&config.CacheConfig{
|
||||
CacheLevel: config.CacheLevelAll,
|
||||
CacheStorage: storage.NewRedis(&storage.RedisStoreConfig{
|
||||
KeyPrefix: "cache",
|
||||
Client: client,
|
||||
}),
|
||||
InvalidateWhenUpdate: true, // when you create/update/delete objects, invalidate cache
|
||||
CacheTTL: 10000, // 5000 ms
|
||||
CacheMaxItemCnt: 0, // if length of objects retrieved one single time
|
||||
AsyncWrite: true, // async write to cache
|
||||
DebugMode: false,
|
||||
DisableCachePenetrationProtect: true, // disable cache penetration protect
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = db.Use(gormCache)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return db, useDB
|
||||
}
|
@@ -1,159 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"gorm.io/gen"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
ScaAuthMenu *scaAuthMenu
|
||||
ScaAuthPermissionRule *scaAuthPermissionRule
|
||||
ScaAuthRole *scaAuthRole
|
||||
ScaAuthUser *scaAuthUser
|
||||
ScaAuthUserDevice *scaAuthUserDevice
|
||||
ScaAuthUserSocial *scaAuthUserSocial
|
||||
ScaUserLevel *scaUserLevel
|
||||
ScaUserMessage *scaUserMessage
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
ScaAuthMenu = &Q.ScaAuthMenu
|
||||
ScaAuthPermissionRule = &Q.ScaAuthPermissionRule
|
||||
ScaAuthRole = &Q.ScaAuthRole
|
||||
ScaAuthUser = &Q.ScaAuthUser
|
||||
ScaAuthUserDevice = &Q.ScaAuthUserDevice
|
||||
ScaAuthUserSocial = &Q.ScaAuthUserSocial
|
||||
ScaUserLevel = &Q.ScaUserLevel
|
||||
ScaUserMessage = &Q.ScaUserMessage
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ScaAuthMenu: newScaAuthMenu(db, opts...),
|
||||
ScaAuthPermissionRule: newScaAuthPermissionRule(db, opts...),
|
||||
ScaAuthRole: newScaAuthRole(db, opts...),
|
||||
ScaAuthUser: newScaAuthUser(db, opts...),
|
||||
ScaAuthUserDevice: newScaAuthUserDevice(db, opts...),
|
||||
ScaAuthUserSocial: newScaAuthUserSocial(db, opts...),
|
||||
ScaUserLevel: newScaUserLevel(db, opts...),
|
||||
ScaUserMessage: newScaUserMessage(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
ScaAuthMenu scaAuthMenu
|
||||
ScaAuthPermissionRule scaAuthPermissionRule
|
||||
ScaAuthRole scaAuthRole
|
||||
ScaAuthUser scaAuthUser
|
||||
ScaAuthUserDevice scaAuthUserDevice
|
||||
ScaAuthUserSocial scaAuthUserSocial
|
||||
ScaUserLevel scaUserLevel
|
||||
ScaUserMessage scaUserMessage
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ScaAuthMenu: q.ScaAuthMenu.clone(db),
|
||||
ScaAuthPermissionRule: q.ScaAuthPermissionRule.clone(db),
|
||||
ScaAuthRole: q.ScaAuthRole.clone(db),
|
||||
ScaAuthUser: q.ScaAuthUser.clone(db),
|
||||
ScaAuthUserDevice: q.ScaAuthUserDevice.clone(db),
|
||||
ScaAuthUserSocial: q.ScaAuthUserSocial.clone(db),
|
||||
ScaUserLevel: q.ScaUserLevel.clone(db),
|
||||
ScaUserMessage: q.ScaUserMessage.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) ReadDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
|
||||
}
|
||||
|
||||
func (q *Query) WriteDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
|
||||
}
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ScaAuthMenu: q.ScaAuthMenu.replaceDB(db),
|
||||
ScaAuthPermissionRule: q.ScaAuthPermissionRule.replaceDB(db),
|
||||
ScaAuthRole: q.ScaAuthRole.replaceDB(db),
|
||||
ScaAuthUser: q.ScaAuthUser.replaceDB(db),
|
||||
ScaAuthUserDevice: q.ScaAuthUserDevice.replaceDB(db),
|
||||
ScaAuthUserSocial: q.ScaAuthUserSocial.replaceDB(db),
|
||||
ScaUserLevel: q.ScaUserLevel.replaceDB(db),
|
||||
ScaUserMessage: q.ScaUserMessage.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
ScaAuthMenu IScaAuthMenuDo
|
||||
ScaAuthPermissionRule IScaAuthPermissionRuleDo
|
||||
ScaAuthRole IScaAuthRoleDo
|
||||
ScaAuthUser IScaAuthUserDo
|
||||
ScaAuthUserDevice IScaAuthUserDeviceDo
|
||||
ScaAuthUserSocial IScaAuthUserSocialDo
|
||||
ScaUserLevel IScaUserLevelDo
|
||||
ScaUserMessage IScaUserMessageDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
ScaAuthMenu: q.ScaAuthMenu.WithContext(ctx),
|
||||
ScaAuthPermissionRule: q.ScaAuthPermissionRule.WithContext(ctx),
|
||||
ScaAuthRole: q.ScaAuthRole.WithContext(ctx),
|
||||
ScaAuthUser: q.ScaAuthUser.WithContext(ctx),
|
||||
ScaAuthUserDevice: q.ScaAuthUserDevice.WithContext(ctx),
|
||||
ScaAuthUserSocial: q.ScaAuthUserSocial.WithContext(ctx),
|
||||
ScaUserLevel: q.ScaUserLevel.WithContext(ctx),
|
||||
ScaUserMessage: q.ScaUserMessage.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
|
||||
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
|
||||
}
|
||||
|
||||
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
|
||||
tx := q.db.Begin(opts...)
|
||||
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
|
||||
}
|
||||
|
||||
type QueryTx struct {
|
||||
*Query
|
||||
Error error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Commit() error {
|
||||
return q.db.Commit().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Rollback() error {
|
||||
return q.db.Rollback().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) SavePoint(name string) error {
|
||||
return q.db.SavePoint(name).Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) RollbackTo(name string) error {
|
||||
return q.db.RollbackTo(name).Error
|
||||
}
|
@@ -3,7 +3,7 @@ package mysql
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"schisandra-album-cloud-microservices/app/file/api/model/mysql/query"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/query"
|
||||
"time"
|
||||
|
||||
"github.com/asjdf/gorm-cache/cache"
|
@@ -6,11 +6,10 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -6,11 +6,10 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -6,11 +6,10 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -6,11 +6,10 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -6,11 +6,10 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -6,11 +6,10 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -6,11 +6,10 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -6,11 +6,10 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
@@ -1,5 +1,6 @@
|
||||
[captcha]
|
||||
verificationFailure = "verification failure!"
|
||||
|
||||
[login]
|
||||
invalidAccount = "invalid account!"
|
||||
notFoundAccount = "account not found!"
|
||||
@@ -18,4 +19,10 @@ loginSuccess = "login success!"
|
||||
[sms]
|
||||
smsSendTooFrequently = "sms send too frequently!"
|
||||
smsSendFailed = "sms send failed!"
|
||||
smsSendSuccess = "sms send success!"
|
||||
smsSendSuccess = "sms send success!"
|
||||
|
||||
[comment]
|
||||
tooManyImages = "too many images!"
|
||||
commentError = "comment error!"
|
||||
LikeError = "like error!"
|
||||
CancelLikeError = "cancel like error!"
|
@@ -1,5 +1,6 @@
|
||||
[captcha]
|
||||
verificationFailure = "验证失败!"
|
||||
|
||||
[login]
|
||||
invalidAccount = "无效的账号!"
|
||||
notFoundAccount = "未找到账号!"
|
||||
@@ -19,3 +20,9 @@ loginSuccess = "登录成功!"
|
||||
smsSendTooFrequently = "验证码发送过于频繁,请稍后再试!"
|
||||
smsSendFailed = "短信发送失败!"
|
||||
smsSendSuccess = "短信发送成功!"
|
||||
|
||||
[comment]
|
||||
tooManyImages = "图片数量过多,请上传不超过3张!"
|
||||
commentError = "评论失败!"
|
||||
LikeError = "点赞失败!"
|
||||
CancelLikeError = "取消点赞失败!"
|
@@ -1,152 +0,0 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "社区服务"
|
||||
desc: "社区服务"
|
||||
author: "landaiqing"
|
||||
email: "landaiqing@126.com"
|
||||
version: "v1.0.0"
|
||||
)
|
||||
|
||||
// 评论请求参数
|
||||
type (
|
||||
// 评论提交请求参数
|
||||
CommentRequest {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
// 回复评论提交请求参数
|
||||
ReplyCommentRequest {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id" `
|
||||
ReplyId int64 `json:"reply_id" `
|
||||
ReplyUser string `json:"reply_user" `
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
// 回复回复请求参数
|
||||
ReplyReplyRequest {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id"`
|
||||
ReplyTo int64 `json:"reply_to"`
|
||||
ReplyId int64 `json:"reply_id"`
|
||||
ReplyUser string `json:"reply_user" `
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
// 评论列表请求参数
|
||||
CommentListRequest {
|
||||
TopicId string `json:"topic_id"`
|
||||
Page int `json:"page,default=1,optional"`
|
||||
Size int `json:"size,default=5,optional"`
|
||||
IsHot bool `json:"is_hot,default=true,optional"`
|
||||
}
|
||||
// 回复列表请求参数
|
||||
ReplyListRequest {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
Page int `json:"page,default=1,optional"`
|
||||
Size int `json:"size,default=5,optional"`
|
||||
}
|
||||
// 点赞评论的请求参数
|
||||
CommentLikeRequest {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
}
|
||||
CommentDisLikeRequest {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
}
|
||||
)
|
||||
|
||||
// 响应参数
|
||||
type (
|
||||
// CommentContent 评论内容
|
||||
CommentContent {
|
||||
NickName string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Level int64 `json:"level,omitempty" default:"0"`
|
||||
Id int64 `json:"id"`
|
||||
UserId string `json:"user_id"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Content string `json:"content"`
|
||||
ReplyTo int64 `json:"reply_to,omitempty"`
|
||||
ReplyId int64 `json:"reply_id,omitempty"`
|
||||
ReplyUser string `json:"reply_user,omitempty"`
|
||||
ReplyNickname string `json:"reply_nickname,omitempty"`
|
||||
IsAuthor int64 `json:"is_author"`
|
||||
Likes int64 `json:"likes"`
|
||||
ReplyCount int64 `json:"reply_count"`
|
||||
CreatedTime string `json:"created_time"`
|
||||
Location string `json:"location"`
|
||||
Browser string `json:"browser"`
|
||||
OperatingSystem string `json:"operating_system"`
|
||||
IsLiked bool `json:"is_liked" default:"false"`
|
||||
Images []string `json:"images,omitempty"`
|
||||
}
|
||||
// CommentListPageResponse 评论返回值
|
||||
CommentListPageResponse {
|
||||
Size int `json:"size"`
|
||||
Total int64 `json:"total"`
|
||||
Current int `json:"current"`
|
||||
Comments []CommentContent `json:"comments"`
|
||||
}
|
||||
// CommentResponse 提交评论响应
|
||||
CommentResponse {
|
||||
Id int64 `json:"id"`
|
||||
Content string `json:"content"`
|
||||
UserId string `json:"user_id"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Author int64 `json:"author"`
|
||||
Location string `json:"location"`
|
||||
Browser string `json:"browser"`
|
||||
OperatingSystem string `json:"operating_system"`
|
||||
CreatedTime string `json:"created_time"`
|
||||
ReplyId int64 `json:"reply_id,omitempty"`
|
||||
ReplyUser string `json:"reply_user,omitempty"`
|
||||
ReplyTo int64 `json:"reply_to,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
group: comment // 微服务分组
|
||||
prefix: /api/auth/comment // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 1048576 // 最大请求大小
|
||||
signature: false // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware,CasbinVerifyMiddleware,AuthorizationMiddleware,NonceMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
jwt: Auth // 是否开启jwt验证
|
||||
)
|
||||
service community {
|
||||
@handler getCommentList
|
||||
post /list (CommentListRequest) returns (CommentListPageResponse)
|
||||
|
||||
@handler getReplyList
|
||||
post /reply/list (ReplyListRequest) returns (CommentListPageResponse)
|
||||
|
||||
@handler submitComment
|
||||
post /submit (CommentRequest) returns (CommentResponse)
|
||||
|
||||
@handler submitReplyComment
|
||||
post /reply/submit (ReplyCommentRequest) returns (CommentResponse)
|
||||
|
||||
@handler submitReplyReply
|
||||
post /reply/reply/submit (ReplyReplyRequest) returns (CommentResponse)
|
||||
|
||||
@handler likeComment
|
||||
post /like (CommentLikeRequest)
|
||||
|
||||
@handler dislikeComment
|
||||
post /dislike (CommentDisLikeRequest)
|
||||
}
|
||||
|
@@ -1,36 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/config"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/handler"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/common/idgenerator"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/community.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf,
|
||||
rest.WithCustomCors(middleware.CORSMiddleware(), nil),
|
||||
rest.WithUnauthorizedCallback(middleware.UnauthorizedCallbackMiddleware()),
|
||||
rest.WithUnsignedCallback(middleware.UnsignedCallbackMiddleware()))
|
||||
defer server.Stop()
|
||||
|
||||
server.Use(middleware.I18nMiddleware)
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
idgenerator.NewIDGenerator(1)
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
@@ -1,84 +0,0 @@
|
||||
# 定义服务的名称,会出现在 log 和 tracer 中
|
||||
Name: schisandra-community-service
|
||||
# 监听地址
|
||||
Host: 0.0.0.0
|
||||
# 监听端口
|
||||
Port: 8081
|
||||
# 服务的环境,目前我们预定义了 dev。在dev 环境我们会开启反射 dev,test,rt,pre, pro
|
||||
Mode: pro
|
||||
# 打点上报,将一些 metrics 上报到对应的地址,如果为空,则不上报
|
||||
MetricsUrl:
|
||||
# 并发请求数
|
||||
MaxConns: 100
|
||||
# 超时时间(ms)
|
||||
Timeout: 5000
|
||||
# 降载阈值,默认900(90%),可允许设置范围0到1000
|
||||
CpuThreshold: 900
|
||||
# 最大ContentLength
|
||||
MaxBytes: 10485760
|
||||
# 是否打印详细日志
|
||||
Verbose: false
|
||||
# 日志配置
|
||||
Log:
|
||||
# 服务名称
|
||||
ServiceName: schisandra-community-service
|
||||
# 日志打印模式,console 控制台 file, console
|
||||
Mode: console
|
||||
# 日志格式, json 格式 或者 plain 纯文本
|
||||
Encoding: plain
|
||||
# 日期格式化
|
||||
TimeFormat:
|
||||
# 日志在文件输出模式下,日志输出路径
|
||||
Path: logs/system
|
||||
# 日志输出级别 debug,info,error,severe
|
||||
Level: debug
|
||||
# 日志长度限制,打印单个日志的时候会对日志进行裁剪,只有对 content 进行裁剪
|
||||
MaxContentLength: 0
|
||||
# 是否压缩日志
|
||||
Compress: true
|
||||
# 是否开启 stat 日志,go-zero 版本大于等于1.5.0才支持
|
||||
Stat: false
|
||||
# 日志保留天数,只有在文件模式才会生效
|
||||
KeepDays: 7
|
||||
# 堆栈打印冷却时间
|
||||
StackCooldownMillis: 100
|
||||
# 文件输出模式,按照大小分割时,最多文件保留个数
|
||||
MaxBackups: 5
|
||||
# 文件输出模式,按照大小分割时,单个文件大小
|
||||
MaxSize: 0
|
||||
# 文件分割模式, daily 按日期 daily,size
|
||||
Rotation: daily
|
||||
# 文件名日期格式
|
||||
FileTimeFormat:
|
||||
# Auth 配置
|
||||
Auth:
|
||||
# 访问密钥
|
||||
AccessSecret: uOvKLmVfztaXGpNYd4Z0I1SiT7MweJhl
|
||||
# MySQL 配置
|
||||
Mysql:
|
||||
# 数据源dsn
|
||||
DataSource: root:LDQ20020618xxx@tcp(1.95.0.111:3306)/schisandra-cloud-album?charset=utf8mb4&parseTime=True&loc=Local
|
||||
# 最大连接数
|
||||
MaxOpenConn: 10
|
||||
# 最大空闲连接数
|
||||
MaxIdleConn: 5
|
||||
# Redis 配置
|
||||
Redis:
|
||||
# Redis 地址
|
||||
Host: 1.95.0.111:6379
|
||||
# Redis 密码
|
||||
Pass: LDQ20020618xxx
|
||||
# Redis 数据库
|
||||
DB: 0
|
||||
# Mongo 配置
|
||||
Mongo:
|
||||
# MongoDB 地址
|
||||
Uri: mongodb://1.95.0.111:27017
|
||||
# MongoDB 用户名
|
||||
Username: landaiqing
|
||||
# MongoDB 密码
|
||||
Password: LDQ20020618xxx
|
||||
# MongoDB 数据库
|
||||
Database: schisandra-cloud-album
|
||||
# MongoDB 认证源
|
||||
AuthSource: admin
|
@@ -1,3 +0,0 @@
|
||||
package main
|
||||
|
||||
//go:generate goctl api go -api community.api -dir . --style=go_zero
|
@@ -1,27 +0,0 @@
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
Auth struct {
|
||||
AccessSecret string
|
||||
}
|
||||
Mysql struct {
|
||||
DataSource string
|
||||
MaxOpenConn int
|
||||
MaxIdleConn int
|
||||
}
|
||||
Redis struct {
|
||||
Host string
|
||||
Pass string
|
||||
DB int
|
||||
}
|
||||
Mongo struct {
|
||||
Uri string
|
||||
Username string
|
||||
Password string
|
||||
AuthSource string
|
||||
Database string
|
||||
}
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.3
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
comment "schisandra-album-cloud-microservices/app/community/api/internal/handler/comment"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.CasbinVerifyMiddleware, serverCtx.AuthorizationMiddleware, serverCtx.NonceMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/dislike",
|
||||
Handler: comment.DislikeCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/like",
|
||||
Handler: comment.LikeCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/list",
|
||||
Handler: comment.GetCommentListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/list",
|
||||
Handler: comment.GetReplyListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/reply/submit",
|
||||
Handler: comment.SubmitReplyReplyHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/submit",
|
||||
Handler: comment.SubmitReplyCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/submit",
|
||||
Handler: comment.SubmitCommentHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/auth/comment"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
)
|
||||
|
||||
type AuthorizationMiddleware struct {
|
||||
}
|
||||
|
||||
func NewAuthorizationMiddleware() *AuthorizationMiddleware {
|
||||
return &AuthorizationMiddleware{}
|
||||
}
|
||||
|
||||
func (m *AuthorizationMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.AuthorizationMiddleware(w, r)
|
||||
next(w, r)
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/casbin/casbin/v2"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
)
|
||||
|
||||
type CasbinVerifyMiddleware struct {
|
||||
casbin *casbin.SyncedCachedEnforcer
|
||||
}
|
||||
|
||||
func NewCasbinVerifyMiddleware(casbin *casbin.SyncedCachedEnforcer) *CasbinVerifyMiddleware {
|
||||
return &CasbinVerifyMiddleware{
|
||||
casbin: casbin,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CasbinVerifyMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.CasbinMiddleware(w, r, m.casbin)
|
||||
next(w, r)
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/redis/go-redis/v9"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
)
|
||||
|
||||
type NonceMiddleware struct {
|
||||
RedisClient *redis.Client
|
||||
}
|
||||
|
||||
func NewNonceMiddleware(redisClient *redis.Client) *NonceMiddleware {
|
||||
return &NonceMiddleware{
|
||||
RedisClient: redisClient,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *NonceMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.NonceMiddleware(w, r, m.RedisClient)
|
||||
next(w, r)
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
)
|
||||
|
||||
type SecurityHeadersMiddleware struct {
|
||||
}
|
||||
|
||||
func NewSecurityHeadersMiddleware() *SecurityHeadersMiddleware {
|
||||
return &SecurityHeadersMiddleware{}
|
||||
}
|
||||
|
||||
func (m *SecurityHeadersMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.SecurityHeadersMiddleware(r)
|
||||
next(w, r)
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"github.com/casbin/casbin/v2"
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
sensitive "github.com/zmexing/go-sensitive-word"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/config"
|
||||
"schisandra-album-cloud-microservices/app/community/api/internal/middleware"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mongodb"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql"
|
||||
"schisandra-album-cloud-microservices/app/community/api/model/mysql/query"
|
||||
"schisandra-album-cloud-microservices/common/casbinx"
|
||||
"schisandra-album-cloud-microservices/common/ip2region"
|
||||
"schisandra-album-cloud-microservices/common/redisx"
|
||||
"schisandra-album-cloud-microservices/common/sensitivex"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
SecurityHeadersMiddleware rest.Middleware
|
||||
CasbinVerifyMiddleware rest.Middleware
|
||||
AuthorizationMiddleware rest.Middleware
|
||||
NonceMiddleware rest.Middleware
|
||||
MongoClient *mongo.Database
|
||||
DB *query.Query
|
||||
CasbinEnforcer *casbin.SyncedCachedEnforcer
|
||||
RedisClient *redis.Client
|
||||
Sensitive *sensitive.Manager
|
||||
Ip2Region *xdb.Searcher
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
redisClient := redisx.NewRedis(c.Redis.Host, c.Redis.Pass, c.Redis.DB)
|
||||
db, queryDB := mysql.NewMySQL(c.Mysql.DataSource, c.Mysql.MaxOpenConn, c.Mysql.MaxIdleConn, redisClient)
|
||||
casbinEnforcer := casbinx.NewCasbin(db)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
SecurityHeadersMiddleware: middleware.NewSecurityHeadersMiddleware().Handle,
|
||||
CasbinVerifyMiddleware: middleware.NewCasbinVerifyMiddleware(casbinEnforcer).Handle,
|
||||
AuthorizationMiddleware: middleware.NewAuthorizationMiddleware().Handle,
|
||||
NonceMiddleware: middleware.NewNonceMiddleware(redisClient).Handle,
|
||||
MongoClient: mongodb.NewMongoDB(c.Mongo.Uri, c.Mongo.Username, c.Mongo.Password, c.Mongo.AuthSource, c.Mongo.Database),
|
||||
DB: queryDB,
|
||||
CasbinEnforcer: casbinEnforcer,
|
||||
RedisClient: redisClient,
|
||||
Sensitive: sensitivex.NewSensitive(),
|
||||
Ip2Region: ip2region.NewIP2Region(),
|
||||
}
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.3
|
||||
|
||||
package types
|
||||
|
||||
type CommentContent struct {
|
||||
NickName string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Level int64 `json:"level,omitempty" default:"0"`
|
||||
Id int64 `json:"id"`
|
||||
UserId string `json:"user_id"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Content string `json:"content"`
|
||||
ReplyTo int64 `json:"reply_to,omitempty"`
|
||||
ReplyId int64 `json:"reply_id,omitempty"`
|
||||
ReplyUser string `json:"reply_user,omitempty"`
|
||||
ReplyNickname string `json:"reply_nickname,omitempty"`
|
||||
IsAuthor int64 `json:"is_author"`
|
||||
Likes int64 `json:"likes"`
|
||||
ReplyCount int64 `json:"reply_count"`
|
||||
CreatedTime string `json:"created_time"`
|
||||
Location string `json:"location"`
|
||||
Browser string `json:"browser"`
|
||||
OperatingSystem string `json:"operating_system"`
|
||||
IsLiked bool `json:"is_liked" default:"false"`
|
||||
Images []string `json:"images,omitempty"`
|
||||
}
|
||||
|
||||
type CommentDisLikeRequest struct {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
}
|
||||
|
||||
type CommentLikeRequest struct {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
}
|
||||
|
||||
type CommentListPageResponse struct {
|
||||
Size int `json:"size"`
|
||||
Total int64 `json:"total"`
|
||||
Current int `json:"current"`
|
||||
Comments []CommentContent `json:"comments"`
|
||||
}
|
||||
|
||||
type CommentListRequest struct {
|
||||
TopicId string `json:"topic_id"`
|
||||
Page int `json:"page,default=1,optional"`
|
||||
Size int `json:"size,default=5,optional"`
|
||||
IsHot bool `json:"is_hot,default=true,optional"`
|
||||
}
|
||||
|
||||
type CommentRequest struct {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
|
||||
type CommentResponse struct {
|
||||
Id int64 `json:"id"`
|
||||
Content string `json:"content"`
|
||||
UserId string `json:"user_id"`
|
||||
TopicId string `json:"topic_id"`
|
||||
Author int64 `json:"author"`
|
||||
Location string `json:"location"`
|
||||
Browser string `json:"browser"`
|
||||
OperatingSystem string `json:"operating_system"`
|
||||
CreatedTime string `json:"created_time"`
|
||||
ReplyId int64 `json:"reply_id,omitempty"`
|
||||
ReplyUser string `json:"reply_user,omitempty"`
|
||||
ReplyTo int64 `json:"reply_to,omitempty"`
|
||||
}
|
||||
|
||||
type ReplyCommentRequest struct {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id" `
|
||||
ReplyId int64 `json:"reply_id" `
|
||||
ReplyUser string `json:"reply_user" `
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
||||
|
||||
type ReplyListRequest struct {
|
||||
TopicId string `json:"topic_id"`
|
||||
CommentId int64 `json:"comment_id"`
|
||||
Page int `json:"page,default=1,optional"`
|
||||
Size int `json:"size,default=5,optional"`
|
||||
}
|
||||
|
||||
type ReplyReplyRequest struct {
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images,optional"`
|
||||
TopicId string `json:"topic_id"`
|
||||
ReplyTo int64 `json:"reply_to"`
|
||||
ReplyId int64 `json:"reply_id"`
|
||||
ReplyUser string `json:"reply_user" `
|
||||
Author string `json:"author"`
|
||||
Key string `json:"key"`
|
||||
Point []int64 `json:"point"`
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameScaAuthMenu = "sca_auth_menu"
|
||||
|
||||
// ScaAuthMenu mapped from table <sca_auth_menu>
|
||||
type ScaAuthMenu struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
MenuName string `gorm:"column:menu_name;type:varchar(64);comment:名称" json:"menu_name"` // 名称
|
||||
ParentID int64 `gorm:"column:parent_id;type:bigint;comment:父ID" json:"parent_id"` // 父ID
|
||||
Type int64 `gorm:"column:type;type:tinyint;comment:类型" json:"type"` // 类型
|
||||
Path string `gorm:"column:path;type:varchar(30);comment:路径" json:"path"` // 路径
|
||||
Status int64 `gorm:"column:status;type:tinyint;comment:状态 0 启用 1 停用" json:"status"` // 状态 0 启用 1 停用
|
||||
Icon string `gorm:"column:icon;type:varchar(128);comment:图标" json:"icon"` // 图标
|
||||
MenuKey string `gorm:"column:menu_key;type:varchar(64);comment:关键字" json:"menu_key"` // 关键字
|
||||
Order_ int64 `gorm:"column:order;type:int;comment:排序" json:"order"` // 排序
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
Remark string `gorm:"column:remark;type:varchar(255);comment:备注 描述" json:"remark"` // 备注 描述
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthMenu's table name
|
||||
func (*ScaAuthMenu) TableName() string {
|
||||
return TableNameScaAuthMenu
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
const TableNameScaAuthPermissionRule = "sca_auth_permission_rule"
|
||||
|
||||
// ScaAuthPermissionRule mapped from table <sca_auth_permission_rule>
|
||||
type ScaAuthPermissionRule struct {
|
||||
ID int64 `gorm:"column:id;type:int;primaryKey;autoIncrement:true;primary_key" json:"id,string"`
|
||||
Ptype string `gorm:"column:ptype;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:1;index:IDX_sca_auth_permission_rule_ptype,priority:1" json:"ptype"`
|
||||
V0 string `gorm:"column:v0;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:2;index:IDX_sca_auth_permission_rule_v0,priority:1" json:"v0"`
|
||||
V1 string `gorm:"column:v1;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:3;index:IDX_sca_auth_permission_rule_v1,priority:1" json:"v1"`
|
||||
V2 string `gorm:"column:v2;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:4;index:IDX_sca_auth_permission_rule_v2,priority:1" json:"v2"`
|
||||
V3 string `gorm:"column:v3;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:5;index:IDX_sca_auth_permission_rule_v3,priority:1" json:"v3"`
|
||||
V4 string `gorm:"column:v4;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:6;index:IDX_sca_auth_permission_rule_v4,priority:1" json:"v4"`
|
||||
V5 string `gorm:"column:v5;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:7;index:IDX_sca_auth_permission_rule_v5,priority:1" json:"v5"`
|
||||
}
|
||||
|
||||
// TableName ScaAuthPermissionRule's table name
|
||||
func (*ScaAuthPermissionRule) TableName() string {
|
||||
return TableNameScaAuthPermissionRule
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user