2023-01-21 13:13:33 +00:00
|
|
|
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"
|
2023-01-21 13:13:33 +00:00
|
|
|
"github.com/fthvgb1/wp-go/helper/slice"
|
2023-01-18 15:02:59 +00:00
|
|
|
"github.com/fthvgb1/wp-go/model"
|
2023-01-12 12:42:16 +00:00
|
|
|
)
|
|
|
|
|
2023-10-26 13:38:31 +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
|
|
|
|
}
|
|
|
|
|
2023-11-02 14:40:13 +00:00
|
|
|
func AllUsername(ctx context.Context, _ ...any) (map[string]struct{}, error) {
|
2023-01-21 13:13:33 +00:00
|
|
|
r, err := model.SimpleFind[models.Users](ctx, model.SqlBuilder{
|
|
|
|
{"user_status", "=", "0", "int"},
|
|
|
|
}, "user_login")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return slice.ToMap(r, func(t models.Users) (string, struct{}) {
|
|
|
|
return t.UserLogin, struct{}{}
|
|
|
|
}, true), nil
|
|
|
|
}
|
|
|
|
|
2023-10-26 13:38:31 +00:00
|
|
|
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{{
|
|
|
|
"user_login", u,
|
|
|
|
}}, "*", nil)
|
|
|
|
return
|
|
|
|
}
|