part of group messages history
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func GetUserById(ctx context.Context, userId uuid.UUID) (*User, error) {
|
||||
user, err := CacheGetUserById(userId)
|
||||
if err != nil {
|
||||
user = &User{Id: userId}
|
||||
err = DbGetWholeUser(ctx, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func GetUserByToken(ctx context.Context, token string) (*User, error) {
|
||||
userId, err := TokenValidateGetId(token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return GetUserById(ctx, userId)
|
||||
}
|
||||
|
||||
func GetGroup(ctx context.Context, groupId uuid.UUID) (*Group, error) {
|
||||
group, err := CacheGetGroup(groupId)
|
||||
if err != nil {
|
||||
group = &Group{Id: groupId}
|
||||
if err = DbGroupGetById(ctx, group); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = DbGroupGetMembers(ctx, group); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
CacheSaveGroup(group)
|
||||
}
|
||||
return group, nil
|
||||
}
|
||||
Reference in New Issue
Block a user