mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-14 16:07:42 +00:00
36 lines
745 B
Go
36 lines
745 B
Go
package domain
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
|
)
|
|
|
|
type User struct {
|
|
ID int64
|
|
LastCheckedAt float64
|
|
|
|
// 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, 32)),
|
|
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
|
|
}
|