DengBiao 1 rok temu
rodzic
commit
326e59b8ef
2 zmienionych plików z 11 dodań i 3 usunięć
  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 Wyświetl plik

@@ -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 Wyświetl plik

@@ -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,


Ładowanie…
Anuluj
Zapisz