fix
This commit is contained in:
31
Backend/internal/logic/Forum/boards.go
Normal file
31
Backend/internal/logic/Forum/boards.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package Forum
|
||||
|
||||
import (
|
||||
v1 "TrangleAgent/api/forum/v1"
|
||||
"context"
|
||||
)
|
||||
|
||||
type sForumBoards struct{}
|
||||
|
||||
func NewForumBoards() *sForumBoards {
|
||||
return &sForumBoards{}
|
||||
}
|
||||
|
||||
func (s *sForumBoards) Create(ctx context.Context, req *v1.ForumBoardsCreateReq) (res *v1.ForumBoardsCreateRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *sForumBoards) Update(ctx context.Context, req *v1.ForumBoardsUpdateReq) (res *v1.ForumBoardsUpdateRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *sForumBoards) Delete(ctx context.Context, req *v1.ForumBoardsDeleteReq) (res *v1.ForumBoardsDeleteRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *sForumBoards) View(ctx context.Context, req *v1.ForumBoardsViewReq) (res *v1.ForumBoardsViewRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (s *sForumBoards) List(ctx context.Context, req *v1.ForumBoardsListReq) (res *v1.ForumBoardsListRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
31
Backend/internal/logic/Forum/comments.go
Normal file
31
Backend/internal/logic/Forum/comments.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package Forum
|
||||
|
||||
import (
|
||||
v1 "TrangleAgent/api/forum/v1"
|
||||
"context"
|
||||
)
|
||||
|
||||
type sForumComments struct{}
|
||||
|
||||
func NewForumComments() *sForumComments {
|
||||
return &sForumComments{}
|
||||
}
|
||||
|
||||
func (s *sForumComments) Create(ctx context.Context, req *v1.ForumCommentsCreateReq) (res *v1.ForumCommentsCreateRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *sForumComments) Update(ctx context.Context, req *v1.ForumCommentsUpdateReq) (res *v1.ForumCommentsUpdateRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *sForumComments) Delete(ctx context.Context, req *v1.ForumCommentsDeleteReq) (res *v1.ForumCommentsDeleteRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *sForumComments) View(ctx context.Context, req *v1.ForumCommentsViewReq) (res *v1.ForumCommentsViewRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (s *sForumComments) List(ctx context.Context, req *v1.ForumCommentsListReq) (res *v1.ForumCommentsListRes, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
127
Backend/internal/logic/Forum/post.go
Normal file
127
Backend/internal/logic/Forum/post.go
Normal file
@@ -0,0 +1,127 @@
|
||||
package Forum
|
||||
|
||||
import (
|
||||
v1 "TrangleAgent/api/forum/v1"
|
||||
"TrangleAgent/internal/dao"
|
||||
"TrangleAgent/internal/model"
|
||||
"TrangleAgent/internal/service"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
// sForumPosts 帖子逻辑
|
||||
type sForumPosts struct{}
|
||||
|
||||
func NewForumPosts() *sForumPosts {
|
||||
return &sForumPosts{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterForumPosts(NewForumPosts())
|
||||
}
|
||||
|
||||
func (s *sForumPosts) Create(ctx context.Context, req *v1.ForumPostsCreateReq) (res *v1.ForumPostsCreateRes, err error) {
|
||||
|
||||
//校验参数
|
||||
if len(req.Title) < 5 || len(req.Title) > 100 {
|
||||
return nil, gerror.New("标题长度要在5-100之间")
|
||||
}
|
||||
if len(req.Content) < 5 || len(req.Content) > 10000 {
|
||||
return nil, gerror.New("内容长度要在5-10000之间")
|
||||
}
|
||||
if req.BoardId == 0 {
|
||||
return nil, gerror.New("板块ID不能为空")
|
||||
}
|
||||
|
||||
//创建帖子
|
||||
insert := model.ForumPost{
|
||||
BoardId: req.BoardId,
|
||||
UserId: req.UserId,
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
CoverImage: req.CoverImage,
|
||||
Status: req.Status,
|
||||
CreatedAt: gtime.Now(),
|
||||
UpdatedAt: gtime.Now(),
|
||||
}
|
||||
result, err := dao.ForumPosts.Ctx(ctx).Data(insert).Insert()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "创建帖子失败")
|
||||
}
|
||||
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "获取帖子ID失败")
|
||||
}
|
||||
|
||||
return &v1.ForumPostsCreateRes{Id: uint64(id)}, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *sForumPosts) Update(ctx context.Context, req *v1.ForumPostsUpdateReq) (res *v1.ForumPostsUpdateRes, err error) {
|
||||
//校验参数
|
||||
if len(req.Title) < 5 || len(req.Title) > 100 {
|
||||
return nil, gerror.New("标题长度要在5-100之间")
|
||||
}
|
||||
if len(req.Content) < 5 || len(req.Content) > 10000 {
|
||||
return nil, gerror.New("内容长度要在5-10000之间")
|
||||
}
|
||||
//只能修改 帖子标题 帖子正文 帖子封面图URL
|
||||
fields := []string{"title", "content", "cover_image"}
|
||||
//更新帖子
|
||||
_, err = dao.ForumPosts.Ctx(ctx).Data(model.ForumPost{
|
||||
Id: req.Id,
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
CoverImage: req.CoverImage,
|
||||
}).Fields(fields).OmitEmpty().Update()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "更新帖子失败")
|
||||
}
|
||||
|
||||
return &v1.ForumPostsUpdateRes{Id: req.Id}, nil
|
||||
}
|
||||
|
||||
func (s *sForumPosts) Delete(ctx context.Context, req *v1.ForumPostsDeleteReq) (res *v1.ForumPostsDeleteRes, err error) {
|
||||
//根据id删除帖子
|
||||
_, err = dao.ForumPosts.Ctx(ctx).Where(dao.ForumPosts.Columns().Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "删除帖子失败")
|
||||
}
|
||||
return &v1.ForumPostsDeleteRes{}, nil
|
||||
}
|
||||
|
||||
func (s *sForumPosts) View(ctx context.Context, req *v1.ForumPostsViewReq) (res *v1.ForumPostsViewRes, err error) {
|
||||
// 根据id查询帖子
|
||||
var post model.ForumPostViewParams
|
||||
err = dao.ForumPosts.Ctx(ctx).Where(dao.ForumPosts.Columns().Id, req.Id).Scan(&post)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询帖子失败")
|
||||
}
|
||||
return &v1.ForumPostsViewRes{
|
||||
ForumPostViewParams: post,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *sForumPosts) List(ctx context.Context, req *v1.ForumPostsListReq) (res *v1.ForumPostsListRes, err error) {
|
||||
// 查询帖子列表
|
||||
|
||||
mod := dao.ForumPosts.Ctx(ctx)
|
||||
|
||||
if req.Title != "" {
|
||||
mod = mod.WhereLike(dao.ForumPosts.Columns().Title, "%"+req.Title+"%")
|
||||
}
|
||||
if req.BoardId != 0 {
|
||||
mod = mod.Where(dao.ForumPosts.Columns().BoardId, req.BoardId)
|
||||
}
|
||||
var list []*model.ForumPostViewParams
|
||||
err = mod.Scan(&list)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询帖子列表失败")
|
||||
}
|
||||
return &v1.ForumPostsListRes{
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user