apollo-backend/internal/domain/user.go

37 lines
745 B
Go
Raw Normal View History

2021-10-09 14:59:20 +00:00
package domain
import (
"context"
"strings"
2021-10-12 14:18:40 +00:00
validation "github.com/go-ozzo/ozzo-validation/v4"
2021-10-09 14:59:20 +00:00
)
type User struct {
ID int64
LastCheckedAt float64
// 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,
validation.Field(&u.Name, validation.Required, validation.Length(3, 32)),
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
}