Documentation ¶
Index ¶
- Constants
- func NewMiddleware(service Service, logger log.Logger) middleware
- func RegisterHandlers(g *echo.Group, service Service, maxAvatarSize int, ...)
- type ConfirmAccountResponse
- type CreateUserRequest
- type Mailer
- type Repository
- type Service
- type UpdateEmailRequest
- type UpdatePasswordRequest
- type UpdateUserRequest
- type Uploader
- type User
Constants ¶
View Source
const (
KB = 1000
)
Variables ¶
This section is empty.
Functions ¶
func NewMiddleware ¶ added in v0.4.0
NewMiddleware creates a new user Middleware.
Types ¶
type ConfirmAccountResponse ¶ added in v0.3.0
ConfirmAccountResponse holds data coming from the token generator.
type CreateUserRequest ¶
type CreateUserRequest struct { Email string `json:"email" validate:"required,email" example:"mike@protonmail.com"` Username string `json:"username" validate:"required,alphanum,min=1,max=20" example:"mike"` Password string `json:"password" validate:"required,min=8,max=30" example:"control123"` }
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 // Exists checks if a user exists with a given ID. Exists(ctx context.Context, id string) (bool, error) EmailExists(ctx context.Context, email string) (bool, error) GetByEmail(ctx context.Context, email string) (entity.User, 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) }
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) Exists(ctx context.Context, id string) (bool, 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 GetByEmail(ctx context.Context, id string) (User, error) UpdateAvatar(ctx context.Context, id string, src io.Reader) error UpdatePassword(ctx context.Context, input UpdatePasswordRequest) error UpdateEmail(ctx context.Context, input UpdateEmailRequest) error GenerateConfirmationEmail(ctx context.Context, user User) ( ConfirmAccountResponse, error) }
Service encapsulates use case logic for users.
func NewService ¶
func NewService(repo Repository, logger log.Logger, tokenGen secure.TokenGenerator, sec secure.Password, bucket string, upl Uploader, actSvc activity.Service) Service
NewService creates a new user service.
type UpdateEmailRequest ¶ added in v0.3.0
type UpdateEmailRequest struct { Password string `json:"password" validate:"required,min=8,max=30" example:"control123"` NewEmail string `json:"email" validate:"required,email" example:"mike@proton.me"` }
UpdateEmailRequest represents an email update request.
type UpdatePasswordRequest ¶ added in v0.3.0
type UpdatePasswordRequest struct { OldPassword string `json:"old" validate:"required,min=8,max=30" example:"control123"` NewPassword string `json:"new_password" validate:"required,necsfield=OldPassword,min=8,max=30" example:"secretControl"` }
UpdatePasswordRequest represents a password update request.
type UpdateUserRequest ¶
type UpdateUserRequest struct { Name string `json:"name" validate:"omitempty,min=1,max=32" example:"Ibn Taymiyyah"` Location string `json:"location" validate:"omitempty,min=1,max=16" example:"Damascus"` URL string `json:"url" validate:"omitempty,url,max=64" example:"https://en.wikipedia.org/wiki/Ibn_Taymiyyah"` Bio string `json:"bio" validate:"omitempty,min=1,max=64" example:"What really counts are good endings, not flawed beginnings."` }
UpdateUserRequest represents a user update request.
Click to show internal directories.
Click to hide internal directories.