DengBiao преди 1 година
родител
ревизия
326e59b8ef
променени са 2 файла, в които са добавени 11 реда и са изтрити 3 реда
  1. +8
    -2
      internal/logic/app/group_app.go
  2. +3
    -1
      internal/logic/domain/group/model/group.go

+ 8
- 2
internal/logic/app/group_app.go Целия файл

@@ -4,9 +4,11 @@ import (
"context"
"database/sql"
"errors"
"gim/internal/business/comm/utils"
"gim/internal/logic/domain/group/model"
"gim/internal/logic/domain/group/repo"
"gim/pkg/db"
"gim/pkg/grpclib"
"gim/pkg/pb"
)

@@ -16,8 +18,12 @@ var GroupApp = new(groupApp)

// CreateGroup 创建群组
func (*groupApp) CreateGroup(ctx context.Context, userId int64, in *pb.CreateGroupReq) (int64, error) {
group := model.CreateGroup(userId, in)
err := repo.GroupRepo.Save(group)
masterId, err := grpclib.GetCtxMasterId(ctx)
if err != nil {
return 0, err
}
group := model.CreateGroup(userId, utils.StrToInt64(masterId), in)
err = repo.GroupRepo.Save(group)
if err != nil {
return 0, err
}


+ 3
- 1
internal/logic/domain/group/model/group.go Целия файл

@@ -31,6 +31,7 @@ type Group struct {
Introduction string // 群简介
UserNum int32 // 群组人数
IsAllMemberBanned int32 // 是否全员禁言(1:是 2:否)
MasterId int64 // 站长id
Extra string // 附加字段
CreateTime time.Time // 创建时间
UpdateTime time.Time // 更新时间
@@ -81,12 +82,13 @@ func (g *Group) ToProto() *pb.Group {
}
}

func CreateGroup(userId int64, in *pb.CreateGroupReq) *Group {
func CreateGroup(userId, masterId int64, in *pb.CreateGroupReq) *Group {
now := time.Now()
group := &Group{
Name: in.Name,
AvatarUrl: in.AvatarUrl,
Introduction: in.Introduction,
MasterId: masterId,
Extra: in.Extra,
Members: make([]GroupUser, 0, len(in.MemberIds)+1),
CreateTime: now,


Зареждане…
Отказ
Запис