apollo-backend/internal/domain/user.go

40 lines
796 B
Go
Raw Normal View History

2021-10-09 14:59:20 +00:00
package domain
import (
"context"
"strings"
2022-03-28 21:05:01 +00:00
"time"
2021-10-12 14:18:40 +00:00
validation "github.com/go-ozzo/ozzo-validation/v4"
2021-10-09 14:59:20 +00:00
)
2022-03-28 21:05:01 +00:00
const UserRefreshInterval = 2 * time.Minute
2021-10-09 14:59:20 +00:00
type User struct {
2022-03-28 21:05:01 +00:00
ID int64
NextCheckAt time.Time
2021-10-09 14:59:20 +00:00
// Reddit information
UserID string
Name string
}
func (u *User) NormalizedName() string {
return strings.ToLower(u.Name)
}
2021-10-12 14:18:40 +00:00
func (u *User) Validate() error {
return validation.ValidateStruct(u,
2022-05-13 14:29:09 +00:00
validation.Field(&u.Name, validation.Required, validation.Length(3, 20)),
2021-10-14 03:50:34 +00:00
validation.Field(&u.UserID, validation.Required, validation.Length(4, 9)),
2021-10-12 14:18:40 +00:00
)
}
2021-10-09 14:59:20 +00:00
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
2021-10-09 14:59:20 +00:00
}