2022-12-19 08:14:31 +00:00
|
|
|
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 {
|
2023-01-17 14:07:16 +00:00
|
|
|
|
2022-12-19 08:14:31 +00:00
|
|
|
groups := h.storage.CreateGroupMember(group)
|
|
|
|
if groups != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
h.storage.UpdateGroupMember(group)
|
|
|
|
return &group, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 14:07:16 +00:00
|
|
|
groupp.Memberid = group.Memberid
|
2022-12-19 08:14:31 +00:00
|
|
|
groupp.Groupid = group.Groupid
|
|
|
|
groupp.Data = group.Data
|
|
|
|
|
2023-01-17 14:07:16 +00:00
|
|
|
h.storage.UpdateGroupMember(*groupp)
|
2022-12-19 08:14:31 +00:00
|
|
|
|
|
|
|
return &group, nil
|
|
|
|
}
|
|
|
|
|
2023-01-17 14:07:16 +00:00
|
|
|
func (h GroupsManagementHandler) UnsubscribeMember(groupid string) error {
|
|
|
|
_, err := h.storage.GetGroupMember(groupid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
erreur := h.storage.DeleteGroupMember(groupid)
|
|
|
|
if erreur != nil {
|
|
|
|
return erreur
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|