wp-go/app/pkg/dao/users.go

33 lines
855 B
Go
Raw Permalink Normal View History

package dao
2023-01-12 12:42:16 +00:00
import (
"context"
2023-05-04 12:36:17 +00:00
"github.com/fthvgb1/wp-go/app/pkg/models"
"github.com/fthvgb1/wp-go/helper/slice"
"github.com/fthvgb1/wp-go/model"
2023-01-12 12:42:16 +00:00
)
func GetUserById(ctx context.Context, uid uint64, _ ...any) (r models.Users, err error) {
2023-01-12 12:42:16 +00:00
r, err = model.FindOneById[models.Users](ctx, uid)
return
}
func AllUsername(ctx context.Context, _ ...any) (map[string]uint64, error) {
r, err := model.SimpleFind[models.Users](ctx, model.SqlBuilder{
{"user_status", "=", "0", "int"},
}, "display_name,ID")
if err != nil {
return nil, err
}
return slice.ToMap(r, func(t models.Users) (string, uint64) {
return t.DisplayName, t.Id
}, true), nil
}
func GetUserByName(ctx context.Context, u string, _ ...any) (r models.Users, err error) {
2023-01-12 12:42:16 +00:00
r, err = model.FirstOne[models.Users](ctx, model.SqlBuilder{{
"display_name", u,
2023-01-12 12:42:16 +00:00
}}, "*", nil)
return
}