fix_api
This commit is contained in:
@@ -26,7 +26,7 @@ var (
|
||||
r.Middleware.Next()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
r.Response.CORS(ghttp.CORSOptions{
|
||||
AllowOrigin: "http://localhost:3000,http://localhost:8080",
|
||||
AllowMethods: "GET,POST,PUT,DELETE,OPTIONS",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package forum
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "TrangleAgent/api/forum/v1"
|
||||
"TrangleAgent/internal/service"
|
||||
"context"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
@@ -31,7 +31,8 @@ func (c *RoleControllerV1) RoleList(ctx context.Context, req *v1.RoleListReq) (r
|
||||
|
||||
func (c *RoleControllerV1) RoleDelete(ctx context.Context, req *v1.RoleDeleteReq) (res *v1.RoleDeleteRes, err error) {
|
||||
return service.User().RoleDelete(ctx, req)
|
||||
} // RolePermissionCheck 权限查询
|
||||
}
|
||||
// RolePermissionCheck 权限查询
|
||||
func (c *RoleControllerV1) RolePermissionCheck(ctx context.Context, req *v1.RolePermissionCheckReq) (res *v1.RolePermissionCheckRes, err error) {
|
||||
return service.User().RolePermissionCheck(ctx, req)
|
||||
}
|
||||
|
||||
@@ -26,48 +26,6 @@ func (c *ControllerV1) UserDelete(ctx context.Context, req *v1.UserDeleteReq) (r
|
||||
return service.User().UserDelete(ctx, req)
|
||||
}
|
||||
|
||||
// Fans 相关方法
|
||||
func (c *ControllerV1) FansList(ctx context.Context, req *v1.FansListReq) (res *v1.FansListRes, err error) {
|
||||
return service.Fans().FansList(ctx, req)
|
||||
}
|
||||
|
||||
func (c *ControllerV1) FansView(ctx context.Context, req *v1.FansViewReq) (res *v1.FansViewRes, err error) {
|
||||
return service.Fans().FansView(ctx, req)
|
||||
}
|
||||
|
||||
func (c *ControllerV1) FansUpdate(ctx context.Context, req *v1.FansUpdateReq) (res *v1.FansUpdateRes, err error) {
|
||||
return service.Fans().FansUpdate(ctx, req)
|
||||
}
|
||||
|
||||
func (c *ControllerV1) FansDelete(ctx context.Context, req *v1.FansDeleteReq) (res *v1.FansDeleteRes, err error) {
|
||||
return service.Fans().FansDelete(ctx, req)
|
||||
}
|
||||
|
||||
func (c *ControllerV1) FansCreate(ctx context.Context, req *v1.FansCreateReq) (res *v1.FansCreateRes, err error) {
|
||||
return service.Fans().FansCreate(ctx, req)
|
||||
}
|
||||
|
||||
// Subscribe 相关方法
|
||||
func (c *ControllerV1) SubscribeList(ctx context.Context, req *v1.SubscribeListReq) (res *v1.SubscribeListRes, err error) {
|
||||
return service.Subscribe().SubscribeList(ctx, req)
|
||||
}
|
||||
|
||||
func (c *ControllerV1) SubscribeView(ctx context.Context, req *v1.SubscribeViewReq) (res *v1.SubscribeViewRes, err error) {
|
||||
return service.Subscribe().SubscribeView(ctx, req)
|
||||
}
|
||||
|
||||
func (c *ControllerV1) SubscribeUpdate(ctx context.Context, req *v1.SubscribeUpdateReq) (res *v1.SubscribeUpdateRes, err error) {
|
||||
return service.Subscribe().SubscribeUpdate(ctx, req)
|
||||
}
|
||||
|
||||
func (c *ControllerV1) SubscribeDelete(ctx context.Context, req *v1.SubscribeDeleteReq) (res *v1.SubscribeDeleteRes, err error) {
|
||||
return service.Subscribe().SubscribeDelete(ctx, req)
|
||||
}
|
||||
|
||||
func (c *ControllerV1) SubscribeCreate(ctx context.Context, req *v1.SubscribeCreateReq) (res *v1.SubscribeCreateRes, err error) {
|
||||
return service.Subscribe().SubscribeCreate(ctx, req)
|
||||
}
|
||||
|
||||
// Trace 相关方法
|
||||
func (c *ControllerV1) TraceList(ctx context.Context, req *v1.TraceListReq) (res *v1.TraceListRes, err error) {
|
||||
return service.Trace().TraceList(ctx, req)
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package ForumComments
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"TrangleAgent/api/forum/v1"
|
||||
v1 "TrangleAgent/api/forum/v1"
|
||||
"TrangleAgent/internal/dao"
|
||||
"TrangleAgent/internal/model/entity"
|
||||
"TrangleAgent/internal/service"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
// ForumComments 评论相关方法
|
||||
@@ -21,13 +25,12 @@ func init() {
|
||||
// ForumCommentsCreate 创建评论
|
||||
func (s *sForumComments) Create(ctx context.Context, req *v1.ForumCommentsCreateReq) (res *v1.ForumCommentsCreateRes, err error) {
|
||||
data := &entity.ForumComments{
|
||||
UserId: req.UserId,
|
||||
PostId: req.PostId,
|
||||
ParentId: req.ParentId,
|
||||
Content: req.Content,
|
||||
Status: req.Status,
|
||||
LikeCount: 0,
|
||||
ReplyCount: 0,
|
||||
UserId: req.UserId,
|
||||
PostId: req.PostId,
|
||||
ParentId: req.ParentId,
|
||||
Content: req.Content,
|
||||
Status: req.Status,
|
||||
LikeCount: 0,
|
||||
}
|
||||
|
||||
result, err := dao.ForumComments.Ctx(ctx).Data(data).OmitEmpty().Insert()
|
||||
@@ -42,20 +45,15 @@ func (s *sForumComments) Create(ctx context.Context, req *v1.ForumCommentsCreate
|
||||
|
||||
// 更新帖子的评论数
|
||||
if req.PostId > 0 {
|
||||
_, err = dao.ForumPosts.Ctx(ctx).WherePri(req.PostId).OnDuplicate("comment_count", 1).Update()
|
||||
updateData := map[string]interface{}{
|
||||
dao.ForumPosts.Columns().CommentCount: gdb.Raw(fmt.Sprintf("%s + 1", dao.ForumPosts.Columns().CommentCount)),
|
||||
}
|
||||
_, err = dao.ForumPosts.Ctx(ctx).WherePri(req.PostId).Data(updateData).Update()
|
||||
if err != nil {
|
||||
g.Log().Warning(ctx, "更新帖子评论数失败:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是回复评论,则更新父评论的回复数
|
||||
if req.ParentId > 0 {
|
||||
_, err = dao.ForumComments.Ctx(ctx).WherePri(req.ParentId).OnDuplicate("reply_count", 1).Update()
|
||||
if err != nil {
|
||||
g.Log().Warning(ctx, "更新父评论回复数失败:", err)
|
||||
}
|
||||
}
|
||||
|
||||
return &v1.ForumCommentsCreateRes{
|
||||
Id: uint64(id),
|
||||
}, nil
|
||||
@@ -63,8 +61,11 @@ func (s *sForumComments) Create(ctx context.Context, req *v1.ForumCommentsCreate
|
||||
|
||||
// ForumCommentsUpdate 更新评论
|
||||
func (s *sForumComments) Update(ctx context.Context, req *v1.ForumCommentsUpdateReq) (res *v1.ForumCommentsUpdateRes, err error) {
|
||||
// 检查评论是否存在
|
||||
one, err := dao.ForumComments.Ctx(ctx).WherePri(req.Id).One()
|
||||
// 检查评论是否存在(排除已删除的)
|
||||
one, err := dao.ForumComments.Ctx(ctx).
|
||||
WherePri(req.Id).
|
||||
WhereNull(dao.ForumComments.Columns().DeletedAt).
|
||||
One()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询评论失败")
|
||||
}
|
||||
@@ -85,7 +86,10 @@ func (s *sForumComments) Update(ctx context.Context, req *v1.ForumCommentsUpdate
|
||||
|
||||
// ForumCommentsView 查看评论
|
||||
func (s *sForumComments) View(ctx context.Context, req *v1.ForumCommentsViewReq) (res *v1.ForumCommentsViewRes, err error) {
|
||||
record, err := dao.ForumComments.Ctx(ctx).WherePri(req.Id).One()
|
||||
record, err := dao.ForumComments.Ctx(ctx).
|
||||
WherePri(req.Id).
|
||||
WhereNull(dao.ForumComments.Columns().DeletedAt).
|
||||
One()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询评论失败")
|
||||
}
|
||||
@@ -100,16 +104,15 @@ func (s *sForumComments) View(ctx context.Context, req *v1.ForumCommentsViewReq)
|
||||
}
|
||||
|
||||
res = &v1.ForumCommentsViewRes{
|
||||
Id: entity.Id,
|
||||
UserId: entity.UserId,
|
||||
PostId: entity.PostId,
|
||||
ParentId: entity.ParentId,
|
||||
Content: entity.Content,
|
||||
Status: entity.Status,
|
||||
LikeCount: entity.LikeCount,
|
||||
ReplyCount: entity.ReplyCount,
|
||||
CreatedAt: entity.CreatedAt,
|
||||
UpdatedAt: entity.UpdatedAt,
|
||||
Id: entity.Id,
|
||||
UserId: entity.UserId,
|
||||
PostId: entity.PostId,
|
||||
ParentId: entity.ParentId,
|
||||
Content: entity.Content,
|
||||
Status: entity.Status,
|
||||
LikeCount: entity.LikeCount,
|
||||
CreatedAt: entity.CreatedAt,
|
||||
UpdatedAt: entity.UpdatedAt,
|
||||
}
|
||||
|
||||
return res, nil
|
||||
@@ -117,23 +120,25 @@ func (s *sForumComments) View(ctx context.Context, req *v1.ForumCommentsViewReq)
|
||||
|
||||
// ForumCommentsList 评论列表
|
||||
func (s *sForumComments) List(ctx context.Context, req *v1.ForumCommentsListReq) (res *v1.ForumCommentsListRes, err error) {
|
||||
query := dao.ForumComments.Ctx(ctx).OmitEmpty()
|
||||
query := dao.ForumComments.Ctx(ctx).
|
||||
WhereNull(dao.ForumComments.Columns().DeletedAt).
|
||||
OmitEmpty()
|
||||
|
||||
if req.UserId > 0 {
|
||||
query = query.Where("user_id", req.UserId)
|
||||
query = query.Where(dao.ForumComments.Columns().UserId, req.UserId)
|
||||
}
|
||||
if req.PostId > 0 {
|
||||
query = query.Where("post_id", req.PostId)
|
||||
query = query.Where(dao.ForumComments.Columns().PostId, req.PostId)
|
||||
}
|
||||
if req.ParentId > 0 {
|
||||
query = query.Where("parent_id", req.ParentId)
|
||||
query = query.Where(dao.ForumComments.Columns().ParentId, req.ParentId)
|
||||
}
|
||||
if req.Status != "" {
|
||||
query = query.Where("status", req.Status)
|
||||
query = query.Where(dao.ForumComments.Columns().Status, req.Status)
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
pageResult, err := query.Page(req.Page, req.PageSize).Order("created_at DESC").All()
|
||||
pageResult, err := query.Page(req.Page, req.PageSize).OrderDesc(dao.ForumComments.Columns().CreatedAt).All()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询评论列表失败")
|
||||
}
|
||||
@@ -147,16 +152,15 @@ func (s *sForumComments) List(ctx context.Context, req *v1.ForumCommentsListReq)
|
||||
}
|
||||
|
||||
item := &v1.ForumCommentsViewRes{
|
||||
Id: entity.Id,
|
||||
UserId: entity.UserId,
|
||||
PostId: entity.PostId,
|
||||
ParentId: entity.ParentId,
|
||||
Content: entity.Content,
|
||||
Status: entity.Status,
|
||||
LikeCount: entity.LikeCount,
|
||||
ReplyCount: entity.ReplyCount,
|
||||
CreatedAt: entity.CreatedAt,
|
||||
UpdatedAt: entity.UpdatedAt,
|
||||
Id: entity.Id,
|
||||
UserId: entity.UserId,
|
||||
PostId: entity.PostId,
|
||||
ParentId: entity.ParentId,
|
||||
Content: entity.Content,
|
||||
Status: entity.Status,
|
||||
LikeCount: entity.LikeCount,
|
||||
CreatedAt: entity.CreatedAt,
|
||||
UpdatedAt: entity.UpdatedAt,
|
||||
}
|
||||
list = append(list, item)
|
||||
}
|
||||
@@ -177,8 +181,11 @@ func (s *sForumComments) List(ctx context.Context, req *v1.ForumCommentsListReq)
|
||||
|
||||
// ForumCommentsDelete 删除评论
|
||||
func (s *sForumComments) Delete(ctx context.Context, req *v1.ForumCommentsDeleteReq) (res *v1.ForumCommentsDeleteRes, err error) {
|
||||
// 检查评论是否存在
|
||||
one, err := dao.ForumComments.Ctx(ctx).WherePri(req.Id).One()
|
||||
// 检查评论是否存在(排除已删除的)
|
||||
one, err := dao.ForumComments.Ctx(ctx).
|
||||
WherePri(req.Id).
|
||||
WhereNull(dao.ForumComments.Columns().DeletedAt).
|
||||
One()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询评论失败")
|
||||
}
|
||||
@@ -192,27 +199,26 @@ func (s *sForumComments) Delete(ctx context.Context, req *v1.ForumCommentsDelete
|
||||
return nil, gerror.Wrap(err, "解析评论数据失败")
|
||||
}
|
||||
|
||||
// 软删除评论
|
||||
_, err = dao.ForumComments.Ctx(ctx).WherePri(req.Id).Delete()
|
||||
// 软删除评论:更新 deleted_at 和 status
|
||||
updateData := map[string]interface{}{
|
||||
dao.ForumComments.Columns().DeletedAt: gtime.Now(),
|
||||
dao.ForumComments.Columns().Status: "deleted",
|
||||
}
|
||||
_, err = dao.ForumComments.Ctx(ctx).WherePri(req.Id).Data(updateData).Update()
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "删除评论失败")
|
||||
}
|
||||
|
||||
// 更新帖子的评论数
|
||||
// 更新帖子的评论数(减少)
|
||||
if comment.PostId > 0 {
|
||||
_, err = dao.ForumPosts.Ctx(ctx).WherePri(comment.PostId).OnDuplicate("comment_count", 1).Update()
|
||||
updatePostData := map[string]interface{}{
|
||||
dao.ForumPosts.Columns().CommentCount: gdb.Raw(fmt.Sprintf("GREATEST(0, %s - 1)", dao.ForumPosts.Columns().CommentCount)),
|
||||
}
|
||||
_, err = dao.ForumPosts.Ctx(ctx).WherePri(comment.PostId).Data(updatePostData).Update()
|
||||
if err != nil {
|
||||
g.Log().Warning(ctx, "更新帖子评论数失败:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是回复评论,则更新父评论的回复数
|
||||
if comment.ParentId > 0 {
|
||||
_, err = dao.ForumComments.Ctx(ctx).WherePri(comment.ParentId).OnDuplicate("reply_count", 1).Update()
|
||||
if err != nil {
|
||||
g.Log().Warning(ctx, "更新父评论回复数失败:", err)
|
||||
}
|
||||
}
|
||||
|
||||
return &v1.ForumCommentsDeleteRes{}, nil
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package containment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
v1 "TrangleAgent/api/containment/v1"
|
||||
"TrangleAgent/internal/model/response"
|
||||
"TrangleAgent/internal/service"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// 收容库相关方法
|
||||
type sContainment struct{}
|
||||
|
||||
func New() *sContainment {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package department
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "TrangleAgent/api/department/v1"
|
||||
"TrangleAgent/internal/dao"
|
||||
"TrangleAgent/internal/model"
|
||||
"TrangleAgent/internal/service"
|
||||
"context"
|
||||
)
|
||||
|
||||
// 部门相关方法
|
||||
type sDepartment struct{}
|
||||
|
||||
func New() *sDepartment {
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
package fans
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
v1 "TrangleAgent/api/user/v1"
|
||||
"TrangleAgent/internal/dao"
|
||||
"TrangleAgent/internal/service"
|
||||
)
|
||||
|
||||
type sFans struct{}
|
||||
|
||||
func New() *sFans {
|
||||
return &sFans{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterFans(New())
|
||||
}
|
||||
|
||||
// FansList 获取粉丝列表
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansListReq: 粉丝列表请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansListRes: 粉丝列表响应结果
|
||||
// - err error: 错误信息
|
||||
func (s *sFans) FansList(ctx context.Context, req *v1.FansListReq) (res *v1.FansListRes, err error) {
|
||||
// 创建数据库查询模型
|
||||
m := dao.Fans.Ctx(ctx)
|
||||
|
||||
// 根据用户ID查询
|
||||
m = m.Where(dao.Fans.Columns().UserId, req.UserId)
|
||||
|
||||
// 根据状态查询
|
||||
if req.Status != 0 {
|
||||
m = m.Where(dao.Fans.Columns().Status, req.Status)
|
||||
}
|
||||
|
||||
// 查询总数
|
||||
total, err := m.Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 分页处理
|
||||
m = m.Page(req.Page, req.PageSize)
|
||||
|
||||
// 查询列表数据
|
||||
var fansList []*v1.FansListItem
|
||||
err = m.Scan(&fansList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &v1.FansListRes{
|
||||
List: fansList,
|
||||
}
|
||||
|
||||
// 设置分页信息
|
||||
req.PageResult.Total = int(total)
|
||||
req.PageResult.Page = req.Page
|
||||
req.PageResult.PageSize = req.PageSize
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FansView 获取粉丝详情
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansViewReq: 粉丝详情请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansViewRes: 粉丝详情响应结果
|
||||
// - err error: 错误信息
|
||||
func (s *sFans) FansView(ctx context.Context, req *v1.FansViewReq) (res *v1.FansViewRes, err error) {
|
||||
// 创建数据库查询模型
|
||||
m := dao.Fans.Ctx(ctx)
|
||||
|
||||
// 根据ID查询
|
||||
m = m.Where(dao.Fans.Columns().Id, req.Id)
|
||||
|
||||
res = &v1.FansViewRes{}
|
||||
err = m.Scan(&res.FansListItem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FansUpdate 更新粉丝信息
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansUpdateReq: 粉丝更新请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansUpdateRes: 粉丝更新响应结果
|
||||
// - err error: 错误信息
|
||||
func (s *sFans) FansUpdate(ctx context.Context, req *v1.FansUpdateReq) (res *v1.FansUpdateRes, err error) {
|
||||
// 创建数据库查询模型
|
||||
m := dao.Fans.Ctx(ctx)
|
||||
|
||||
// 更新粉丝信息
|
||||
_, err = m.Data(req).Where(dao.Fans.Columns().Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &v1.FansUpdateRes{
|
||||
Id: req.Id,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FansDelete 删除粉丝关系
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansDeleteReq: 粉丝删除请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansDeleteRes: 粉丝删除响应结果
|
||||
// - err error: 错误信息
|
||||
func (s *sFans) FansDelete(ctx context.Context, req *v1.FansDeleteReq) (res *v1.FansDeleteRes, err error) {
|
||||
// 根据ID删除粉丝关系
|
||||
_, err = dao.Fans.Ctx(ctx).Where(dao.Fans.Columns().Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &v1.FansDeleteRes{}
|
||||
return
|
||||
}
|
||||
|
||||
// FansCreate 创建粉丝关系
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansCreateReq: 粉丝创建请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansCreateRes: 粉丝创建响应结果
|
||||
// - err error: 错误信息
|
||||
func (s *sFans) FansCreate(ctx context.Context, req *v1.FansCreateReq) (res *v1.FansCreateRes, err error) {
|
||||
// 创建数据库查询模型
|
||||
m := dao.Fans.Ctx(ctx)
|
||||
|
||||
// 准备数据
|
||||
data := map[string]interface{}{
|
||||
"user_id": req.UserId,
|
||||
"fan_id": req.FanId,
|
||||
"status": 1, // 默认状态为关注中
|
||||
"remark": req.Remark,
|
||||
"created_at": gtime.Now(),
|
||||
"updated_at": gtime.Now(),
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
result, err := m.Data(data).Insert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 获取插入的ID
|
||||
lastInsertId, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &v1.FansCreateRes{
|
||||
Id: uint64(lastInsertId),
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -8,10 +8,8 @@ import (
|
||||
_ "TrangleAgent/internal/logic/ForumComments"
|
||||
_ "TrangleAgent/internal/logic/containment"
|
||||
_ "TrangleAgent/internal/logic/department"
|
||||
_ "TrangleAgent/internal/logic/fans"
|
||||
_ "TrangleAgent/internal/logic/login"
|
||||
_ "TrangleAgent/internal/logic/room"
|
||||
_ "TrangleAgent/internal/logic/subscribe"
|
||||
_ "TrangleAgent/internal/logic/trace"
|
||||
_ "TrangleAgent/internal/logic/user"
|
||||
)
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "TrangleAgent/api/room/v1"
|
||||
"TrangleAgent/internal/dao"
|
||||
"TrangleAgent/internal/model"
|
||||
"TrangleAgent/internal/model/entity"
|
||||
"TrangleAgent/internal/service"
|
||||
"context"
|
||||
)
|
||||
|
||||
// 房间相关方法
|
||||
type sRoom struct{}
|
||||
|
||||
func New() *sRoom {
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "TrangleAgent/api/user/v1"
|
||||
"TrangleAgent/internal/dao"
|
||||
"TrangleAgent/internal/service"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
type sSubscribe struct{}
|
||||
|
||||
func New() *sSubscribe {
|
||||
return &sSubscribe{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterSubscribe(New())
|
||||
}
|
||||
|
||||
// SubscribeList 获取关注列表
|
||||
func (s *sSubscribe) SubscribeList(ctx context.Context, req *v1.SubscribeListReq) (res *v1.SubscribeListRes, err error) {
|
||||
// 创建数据库查询模型
|
||||
m := dao.Subscribe.Ctx(ctx)
|
||||
|
||||
// 根据用户ID查询
|
||||
m = m.Where(dao.Subscribe.Columns().UserId, req.UserId)
|
||||
|
||||
// 根据状态查询
|
||||
if req.Status != 0 {
|
||||
m = m.Where(dao.Subscribe.Columns().Status, req.Status)
|
||||
}
|
||||
|
||||
// 根据被关注用户ID查询
|
||||
if req.FollowId != 0 {
|
||||
m = m.Where(dao.Subscribe.Columns().FollowId, req.FollowId)
|
||||
}
|
||||
|
||||
// 查询总数
|
||||
total, err := m.Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 分页处理
|
||||
m = m.Page(req.Page, req.PageSize)
|
||||
|
||||
// 查询列表数据
|
||||
var subscribeList []*v1.SubscribeListItem
|
||||
err = m.Scan(&subscribeList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &v1.SubscribeListRes{
|
||||
List: subscribeList,
|
||||
}
|
||||
|
||||
// 设置分页信息
|
||||
req.PageResult.Total = int(total)
|
||||
req.PageResult.Page = req.Page
|
||||
req.PageResult.PageSize = req.PageSize
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// SubscribeView 获取关注详情
|
||||
func (s *sSubscribe) SubscribeView(ctx context.Context, req *v1.SubscribeViewReq) (res *v1.SubscribeViewRes, err error) {
|
||||
// 创建数据库查询模型
|
||||
m := dao.Subscribe.Ctx(ctx)
|
||||
|
||||
// 根据ID查询
|
||||
m = m.Where(dao.Subscribe.Columns().Id, req.Id)
|
||||
|
||||
res = &v1.SubscribeViewRes{}
|
||||
err = m.Scan(&res.SubscribeListItem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// SubscribeUpdate 更新关注信息
|
||||
func (s *sSubscribe) SubscribeUpdate(ctx context.Context, req *v1.SubscribeUpdateReq) (res *v1.SubscribeUpdateRes, err error) {
|
||||
// 创建数据库查询模型
|
||||
m := dao.Subscribe.Ctx(ctx)
|
||||
|
||||
// 更新关注信息
|
||||
_, err = m.Data(req).Where(dao.Subscribe.Columns().Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &v1.SubscribeUpdateRes{
|
||||
Id: req.Id,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// SubscribeDelete 删除关注关系
|
||||
func (s *sSubscribe) SubscribeDelete(ctx context.Context, req *v1.SubscribeDeleteReq) (res *v1.SubscribeDeleteRes, err error) {
|
||||
// 根据ID删除关注关系
|
||||
_, err = dao.Subscribe.Ctx(ctx).Where(dao.Subscribe.Columns().Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &v1.SubscribeDeleteRes{}
|
||||
return
|
||||
}
|
||||
|
||||
// SubscribeCreate 创建关注关系
|
||||
func (s *sSubscribe) SubscribeCreate(ctx context.Context, req *v1.SubscribeCreateReq) (res *v1.SubscribeCreateRes, err error) {
|
||||
// 创建数据库查询模型
|
||||
m := dao.Subscribe.Ctx(ctx)
|
||||
|
||||
// 准备数据
|
||||
data := map[string]interface{}{
|
||||
"user_id": req.UserId,
|
||||
"follow_id": req.FollowId,
|
||||
"status": 1, // 默认状态为关注中
|
||||
"remark": req.Remark,
|
||||
"created_at": gtime.Now(),
|
||||
"updated_at": gtime.Now(),
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
result, err := m.Data(data).Insert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 获取插入的ID
|
||||
lastInsertId, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &v1.SubscribeCreateRes{
|
||||
Id: uint64(lastInsertId),
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
// ================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// You can delete these comments if you wish manually maintain this interface file.
|
||||
// ================================================================================
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
v1 "TrangleAgent/api/user/v1"
|
||||
"context"
|
||||
)
|
||||
|
||||
type (
|
||||
IFans interface {
|
||||
// FansList 获取粉丝列表
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansListReq: 粉丝列表请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansListRes: 粉丝列表响应结果
|
||||
// - err error: 错误信息
|
||||
FansList(ctx context.Context, req *v1.FansListReq) (res *v1.FansListRes, err error)
|
||||
// FansView 获取粉丝详情
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansViewReq: 粉丝详情请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansViewRes: 粉丝详情响应结果
|
||||
// - err error: 错误信息
|
||||
FansView(ctx context.Context, req *v1.FansViewReq) (res *v1.FansViewRes, err error)
|
||||
// FansUpdate 更新粉丝信息
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansUpdateReq: 粉丝更新请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansUpdateRes: 粉丝更新响应结果
|
||||
// - err error: 错误信息
|
||||
FansUpdate(ctx context.Context, req *v1.FansUpdateReq) (res *v1.FansUpdateRes, err error)
|
||||
// FansDelete 删除粉丝关系
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansDeleteReq: 粉丝删除请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansDeleteRes: 粉丝删除响应结果
|
||||
// - err error: 错误信息
|
||||
FansDelete(ctx context.Context, req *v1.FansDeleteReq) (res *v1.FansDeleteRes, err error)
|
||||
// FansCreate 创建粉丝关系
|
||||
//
|
||||
// 参数:
|
||||
// - ctx context.Context: 上下文信息
|
||||
// - req *v1.FansCreateReq: 粉丝创建请求参数
|
||||
//
|
||||
// 返回:
|
||||
// - res *v1.FansCreateRes: 粉丝创建响应结果
|
||||
// - err error: 错误信息
|
||||
FansCreate(ctx context.Context, req *v1.FansCreateReq) (res *v1.FansCreateRes, err error)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localFans IFans
|
||||
)
|
||||
|
||||
func Fans() IFans {
|
||||
if localFans == nil {
|
||||
panic("implement not found for interface IFans, forgot register?")
|
||||
}
|
||||
return localFans
|
||||
}
|
||||
|
||||
func RegisterFans(i IFans) {
|
||||
localFans = i
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// ================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// You can delete these comments if you wish manually maintain this interface file.
|
||||
// ================================================================================
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
v1 "TrangleAgent/api/user/v1"
|
||||
"context"
|
||||
)
|
||||
|
||||
type (
|
||||
ISubscribe interface {
|
||||
// SubscribeList 获取关注列表
|
||||
SubscribeList(ctx context.Context, req *v1.SubscribeListReq) (res *v1.SubscribeListRes, err error)
|
||||
// SubscribeView 获取关注详情
|
||||
SubscribeView(ctx context.Context, req *v1.SubscribeViewReq) (res *v1.SubscribeViewRes, err error)
|
||||
// SubscribeUpdate 更新关注信息
|
||||
SubscribeUpdate(ctx context.Context, req *v1.SubscribeUpdateReq) (res *v1.SubscribeUpdateRes, err error)
|
||||
// SubscribeDelete 删除关注关系
|
||||
SubscribeDelete(ctx context.Context, req *v1.SubscribeDeleteReq) (res *v1.SubscribeDeleteRes, err error)
|
||||
// SubscribeCreate 创建关注关系
|
||||
SubscribeCreate(ctx context.Context, req *v1.SubscribeCreateReq) (res *v1.SubscribeCreateRes, err error)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localSubscribe ISubscribe
|
||||
)
|
||||
|
||||
func Subscribe() ISubscribe {
|
||||
if localSubscribe == nil {
|
||||
panic("implement not found for interface ISubscribe, forgot register?")
|
||||
}
|
||||
return localSubscribe
|
||||
}
|
||||
|
||||
func RegisterSubscribe(i ISubscribe) {
|
||||
localSubscribe = i
|
||||
}
|
||||
Reference in New Issue
Block a user