groups-management/handlers/groupsmember.go

81 lines
2.0 KiB
Go

package handlers
import (
"git.coopgo.io/coopgo-platform/groups-management/storage"
"github.com/google/uuid"
)
func (h GroupsManagementHandler) AddGroupMember(group storage.GroupMember) (*storage.GroupMember, error) {
if group.ID == "" {
group.ID = uuid.NewString()
}
// Store the account
if err := h.storage.CreateGroupMember(group); err != nil {
return nil, err
}
return &group, nil
}
func (h GroupsManagementHandler) GetGroupMember(id string) (group *storage.GroupMember, err error) {
group, err = h.storage.GetGroupMember(id)
return
}
func (h GroupsManagementHandler) GetGroupsMember(namespaces []string) (groups []storage.GroupMember, err error) {
groups, err = h.storage.GetGroupsMember(namespaces)
return
}
func (h GroupsManagementHandler) GetGroupsBatchMember(groupids []string) (groups []storage.GroupMember, err error) {
groups, err = h.storage.GetGroupsMemberByIds(groupids)
return
}
func (h GroupsManagementHandler) SubscribeMember(group storage.GroupMember) (*storage.GroupMember, error) {
groupp, err := h.storage.GetGroupMember(group.ID)
if err != nil {
//return err
groups := h.storage.CreateGroupMember(group)
if groups != nil {
return nil, err
} else {
h.storage.UpdateGroupMember(group)
return &group, nil
}
}
groupp.Groupid = group.Groupid
groupp.Data = group.Data
h.storage.UpdateGroupMember(*groupp)
// // return nil
// // if group.Memberid == "" {
// // group.Memberid = uuid.NewString()
// // }
// Store the account
// if err := h.storage.CreateGroupMember(group); err != nil {
// return nil, err
// }
return &group, nil
}
// func (h GroupsManagementHandler) UnsubscribeMember(groupid string, subscriber string) error {
// group, err := h.storage.GetGroupMember(groupid)
// if err != nil {
// return err
// }
// members := []string{}
// for _, m := range group.Members {
// if m != subscriber {
// members = append(members, m)
// }
// }
// group.Members = members
// h.storage.UpdateGroupMember(*group)
// return nil
// }