Phase 2c 全部 14 个 Task 完成,包含: 后端(Go): - MinIO 文件存储服务集成(Docker + Go SDK + 通用上传 API) - Group 模块完整实现(DAO + Service + Controller + Router + Wire) - 18 个群管理 REST API + 11 个 WS 群事件推送 - 群创建/解散/邀请/踢人/退出/转让群主/设管理员/禁言/全体禁言/群公告/群昵称/免打扰/搜索 - IM Service 扩展(群消息发送/撤回 + @提醒 + 管理员无时限撤回) - 已读回执后端(单聊会话级 last_read_msg_id + 群聊消息级 im_message_reads) - 管理端群组管理(列表/详情/解散) - 数据库迁移(3 张新表 + 2 张表字段扩展) 前端(uni-app): - 群聊 Store + API 封装 + 11 个 WS 事件监听 - 已读回执 UI(单聊已读/未读标记 + 群聊 X人已读 + 已读详情页) - 7 个群聊页面(对话/创建/设置/成员/邀请/审批/搜索) - 会话列表改造(全部/单聊/群聊 Tab + @标记 + 免打扰标识) 管理端(Vue 3 + Element Plus): - 群组列表页(搜索/分页/详情弹窗/解散群聊) - 侧边栏群组管理入口 文档同步:进度/架构/设计/API/规范文档全部更新 Made-with: Cursor
113 lines
3.4 KiB
Go
113 lines
3.4 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/echochat/backend/app/constants"
|
|
"github.com/echochat/backend/app/group/model"
|
|
"github.com/echochat/backend/pkg/logs"
|
|
"go.uber.org/zap"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// JoinRequestDAO 入群申请数据访问对象
|
|
type JoinRequestDAO struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewJoinRequestDAO 创建 JoinRequestDAO 实例
|
|
func NewJoinRequestDAO(db *gorm.DB) *JoinRequestDAO {
|
|
return &JoinRequestDAO{db: db}
|
|
}
|
|
|
|
// Create 创建入群申请
|
|
func (d *JoinRequestDAO) Create(ctx context.Context, groupID, userID int64, message string) (*model.GroupJoinRequest, error) {
|
|
funcName := "dao.join_request_dao.Create"
|
|
logs.Info(ctx, funcName, "创建入群申请",
|
|
zap.Int64("group_id", groupID), zap.Int64("user_id", userID))
|
|
|
|
req := &model.GroupJoinRequest{
|
|
GroupID: groupID,
|
|
UserID: userID,
|
|
Message: message,
|
|
Status: constants.JoinRequestStatusPending,
|
|
}
|
|
err := d.db.WithContext(ctx).Create(req).Error
|
|
if err != nil {
|
|
logs.Error(ctx, funcName, "创建入群申请失败", zap.Error(err))
|
|
}
|
|
return req, err
|
|
}
|
|
|
|
// GetByID 根据 ID 获取入群申请
|
|
func (d *JoinRequestDAO) GetByID(ctx context.Context, id int64) (*model.GroupJoinRequest, error) {
|
|
var req model.GroupJoinRequest
|
|
err := d.db.WithContext(ctx).First(&req, id).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &req, nil
|
|
}
|
|
|
|
// GetPendingByGroupAndUser 查找用户对某群的待处理申请
|
|
func (d *JoinRequestDAO) GetPendingByGroupAndUser(ctx context.Context, groupID, userID int64) (*model.GroupJoinRequest, error) {
|
|
funcName := "dao.join_request_dao.GetPendingByGroupAndUser"
|
|
logs.Debug(ctx, funcName, "查找待处理申请",
|
|
zap.Int64("group_id", groupID), zap.Int64("user_id", userID))
|
|
|
|
var req model.GroupJoinRequest
|
|
err := d.db.WithContext(ctx).
|
|
Where("group_id = ? AND user_id = ? AND status = ?", groupID, userID, constants.JoinRequestStatusPending).
|
|
First(&req).Error
|
|
if err == gorm.ErrRecordNotFound {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &req, nil
|
|
}
|
|
|
|
// GetListByGroup 获取群的入群申请列表
|
|
func (d *JoinRequestDAO) GetListByGroup(ctx context.Context, groupID int64) ([]model.GroupJoinRequest, error) {
|
|
funcName := "dao.join_request_dao.GetListByGroup"
|
|
logs.Debug(ctx, funcName, "获取入群申请列表", zap.Int64("group_id", groupID))
|
|
|
|
var requests []model.GroupJoinRequest
|
|
err := d.db.WithContext(ctx).
|
|
Where("group_id = ?", groupID).
|
|
Order("created_at DESC").
|
|
Find(&requests).Error
|
|
return requests, err
|
|
}
|
|
|
|
// Approve 通过入群申请
|
|
func (d *JoinRequestDAO) Approve(ctx context.Context, id, reviewerID int64) error {
|
|
funcName := "dao.join_request_dao.Approve"
|
|
logs.Info(ctx, funcName, "通过入群申请",
|
|
zap.Int64("request_id", id), zap.Int64("reviewer_id", reviewerID))
|
|
|
|
return d.db.WithContext(ctx).
|
|
Model(&model.GroupJoinRequest{}).
|
|
Where("id = ?", id).
|
|
Updates(map[string]interface{}{
|
|
"status": constants.JoinRequestStatusApproved,
|
|
"reviewer_id": reviewerID,
|
|
}).Error
|
|
}
|
|
|
|
// Reject 拒绝入群申请
|
|
func (d *JoinRequestDAO) Reject(ctx context.Context, id, reviewerID int64) error {
|
|
funcName := "dao.join_request_dao.Reject"
|
|
logs.Info(ctx, funcName, "拒绝入群申请",
|
|
zap.Int64("request_id", id), zap.Int64("reviewer_id", reviewerID))
|
|
|
|
return d.db.WithContext(ctx).
|
|
Model(&model.GroupJoinRequest{}).
|
|
Where("id = ?", id).
|
|
Updates(map[string]interface{}{
|
|
"status": constants.JoinRequestStatusRejected,
|
|
"reviewer_id": reviewerID,
|
|
}).Error
|
|
}
|