Adding UserGroups struct to handle the list of groups a user is in

Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
Ethan Wellenreiter 2025-05-07 00:00:09 -04:00
parent a99ef367c7
commit 064faeadca
3 changed files with 12 additions and 5 deletions

View File

@ -7,3 +7,8 @@ type Group struct {
Owner int64 `json:"owner"`
Moderators []int64 `json:"moderators"`
}
type UserGroups struct {
UserID int64 `json:"user_id"`
GroupIDs []int64 `json:"group_ids"`
}

View File

@ -48,9 +48,11 @@ func (s *SQLGroupsStore) GetByID(ctx context.Context, id int64) (*Group, error)
return s.getByID(ctx, id)
}
func (s *SQLGroupsStore) GetUserGroups(ctx context.Context, userID int64) ([]int64, error) {
func (s *SQLGroupsStore) GetUserGroups(ctx context.Context, userID int64) (*UserGroups, error) {
// Implement logic to retrieve user's groups from the database
var groups []int64
usergroups := &UserGroups{
UserID: userID,
}
ctx, cancel := context.WithTimeout(ctx, QueryTimeoutDuration)
defer cancel()
@ -68,9 +70,9 @@ func (s *SQLGroupsStore) GetUserGroups(ctx context.Context, userID int64) ([]int
if err != nil {
return nil, err
}
groups = append(groups, groupid)
usergroups.GroupIDs = append(usergroups.GroupIDs, groupid)
}
return groups, nil
return usergroups, nil
}
// func (s *SQLGroupsStore) GetUsersInGroup(ctx context.Context, groupId int64) ([]*User, error) {

View File

@ -66,7 +66,7 @@ type Storage struct {
}
Groups interface {
GetByID(context.Context, int64) (*Group, error)
GetUserGroups(context.Context, int64) ([]int64, error)
GetUserGroups(context.Context, int64) (*UserGroups, error)
// GetUsersInGroup(context.Context, int64) ([]*User, error)
Create(context.Context, *Group) error
Delete(context.Context, int64) error