mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-10 22:17:44 +00:00
39 lines
796 B
Go
39 lines
796 B
Go
package domain
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"time"
|
|
|
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
|
)
|
|
|
|
const UserRefreshInterval = 2 * time.Minute
|
|
|
|
type User struct {
|
|
ID int64
|
|
NextCheckAt time.Time
|
|
|
|
// Reddit information
|
|
UserID string
|
|
Name string
|
|
}
|
|
|
|
func (u *User) NormalizedName() string {
|
|
return strings.ToLower(u.Name)
|
|
}
|
|
|
|
func (u *User) Validate() error {
|
|
return validation.ValidateStruct(u,
|
|
validation.Field(&u.Name, validation.Required, validation.Length(3, 20)),
|
|
validation.Field(&u.UserID, validation.Required, validation.Length(4, 9)),
|
|
)
|
|
}
|
|
|
|
type UserRepository interface {
|
|
GetByID(context.Context, int64) (User, error)
|
|
GetByName(context.Context, string) (User, error)
|
|
|
|
CreateOrUpdate(context.Context, *User) error
|
|
Delete(context.Context, int64) error
|
|
}
|