Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterHandlers ¶
func RegisterHandlers(g *echo.Group, service Service, requireLogin echo.MiddlewareFunc, optionalLogin echo.MiddlewareFunc, logger log.Logger, mailer Mailer)
Types ¶
type CreateUserRequest ¶
type CreateUserRequest struct {
Email string `json:"email" validate:"required,email"`
Username string `json:"username" validate:"required,alphanum,min=1,max=20"`
Password string `json:"password" validate:"required,alphanum,min=8,max=30"`
}
CreateUserRequest represents a user creation request.
type Repository ¶
type Repository interface {
// Get returns the user with the specified user ID.
Get(ctx context.Context, id string) (entity.User, error)
// Count returns the number of users.
Count(ctx context.Context) (int, error)
// Query returns the list of users with the given offset and limit.
Query(ctx context.Context, offset, limit int) ([]entity.User, error)
// Create saves a new user in the storage.
Create(ctx context.Context, User entity.User) error
// Update updates the user with given ID in the storage.
Update(ctx context.Context, User entity.User) error
// Patch patches a sub entry in the user with given ID in the storage.
Patch(ctx context.Context, key, path string, val interface{}) error
// Delete removes the user with given ID from the storage.
Delete(ctx context.Context, id string) error
EmailExists(ctx context.Context, email string) (bool, error)
Likes(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Followers(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Following(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Submissions(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Comments(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Activities(ctx context.Context, id string, offset, limit int) ([]interface{}, error)
CountActivities(ctx context.Context) (int, error)
DeleteActivity(ctx context.Context, kind, username, target string) error
}
Repository encapsulates the logic to access users from the data source.
func NewRepository ¶
func NewRepository(db *dbcontext.DB, logger log.Logger) Repository
NewRepository creates a new user repository.
type Service ¶
type Service interface {
Get(ctx context.Context, id string) (User, error)
Query(ctx context.Context, offset, limit int) ([]User, error)
Count(ctx context.Context) (int, error)
Create(ctx context.Context, input CreateUserRequest) (User, error)
Update(ctx context.Context, id string, input interface{}) (User, error)
Patch(ctx context.Context, id, path string, input interface{}) error
Delete(ctx context.Context, id string) (User, error)
Activities(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Likes(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Followers(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Following(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Submissions(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
Comments(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
CountActivities(ctx context.Context) (int, error)
CountLikes(ctx context.Context, id string) (int, error)
CountFollowing(ctx context.Context, id string) (int, error)
CountFollowers(ctx context.Context, id string) (int, error)
CountComments(ctx context.Context, id string) (int, error)
CountSubmissions(ctx context.Context, id string) (int, error)
Follow(ctx context.Context, id string) error
Unfollow(ctx context.Context, id string) error
UpdateAvatar(ctx context.Context, id string, src io.Reader) error
}
Service encapsulates usecase logic for users.
type UpdateUserRequest ¶
type UpdateUserRequest struct {
Name string `json:"name" validate:"omitempty,min=1,max=32"`
Location string `json:"location" validate:"omitempty,alphanumunicode,min=2,max=16"`
URL string `json:"url" validate:"omitempty,url,max=64"`
Bio string `json:"bio" validate:"omitempty,printascii,min=1,max=64"`
}
UpdateUserRequest represents a user update request.
Click to show internal directories.
Click to hide internal directories.