2023-01-12 12:42:16 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-05-04 12:36:17 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/models"
|
2023-11-07 07:18:34 +00:00
|
|
|
"github.com/fthvgb1/wp-go/cache/cachemanager"
|
2023-01-12 12:42:16 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2024-01-13 13:15:54 +00:00
|
|
|
// GetUserByName query func see dao.GetUserByName
|
2023-01-12 12:42:16 +00:00
|
|
|
func GetUserByName(ctx context.Context, username string) (models.Users, error) {
|
2024-01-13 13:15:54 +00:00
|
|
|
return cachemanager.GetBy[models.Users]("usernameToUserData", ctx, username, time.Second)
|
2023-01-12 12:42:16 +00:00
|
|
|
}
|
|
|
|
|
2024-01-13 13:15:54 +00:00
|
|
|
// GetAllUsername query func see dao.AllUsername
|
|
|
|
func GetAllUsername(ctx context.Context) (map[string]uint64, error) {
|
|
|
|
return cachemanager.GetVarVal[map[string]uint64]("allUsername", ctx, time.Second)
|
2023-01-21 13:13:33 +00:00
|
|
|
}
|
|
|
|
|
2024-01-13 13:15:54 +00:00
|
|
|
// GetUserById query func see dao.GetUserById
|
2023-01-12 12:42:16 +00:00
|
|
|
func GetUserById(ctx context.Context, uid uint64) models.Users {
|
2024-01-10 15:50:23 +00:00
|
|
|
r, err := cachemanager.GetBy[models.Users]("userData", ctx, uid, time.Second)
|
2023-04-07 14:59:07 +00:00
|
|
|
logs.IfError(err, "get user", uid)
|
2023-01-12 12:42:16 +00:00
|
|
|
return r
|
|
|
|
}
|