users

package
v0.44.47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Users routes and controllers logic package for the backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewUserRepository added in v0.44.22

func NewUserRepository(cache db.Cacher) models.UserRepositoryInterface

func NewUserRouter added in v0.44.23

func NewUserRouter(userController *UserController) chi.Router

func NewUserService added in v0.44.23

func NewUserService(
	postRepository models.PostRepositoryInterface,
	subscriptionRepository models.SubscriptionRepositoryInterface,
	requestRepository models.RequestRepositoryInterface,
	tokenRepository models.TokenRepositoryInterface,
	userRepository models.UserRepositoryInterface,
) models.UserServiceInterface

Types

type UserController added in v0.44.23

type UserController struct {
	// contains filtered or unexported fields
}

Structure contents definition for the controller.

func NewUserController added in v0.44.23

func NewUserController(
	postService models.PostServiceInterface,
	userService models.UserServiceInterface,
) *UserController

NewUserController return a pointer to the new controller instance, that has to be populated with User and Post services.

func (*UserController) Activate added in v0.44.23

func (c *UserController) Activate(w http.ResponseWriter, r *http.Request)

Activate is a handler function to complete the user's activation procedure.

@Summary Activate the user via given UUID @Description activate the user via given UUID @Tags users @Produce json @Param uuid path string true "UUID from the activation mail" @Success 200 {object} common.APIResponse{data=models.Stub} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 404 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /users/activation/{uuid} [post]

func (*UserController) Create added in v0.44.23

func (c *UserController) Create(w http.ResponseWriter, r *http.Request)

Create is the users handler that processes input and creates a new user.

@Summary Add new user @Description add new user @Tags users @Accept json @Produce json @Param request body models.User true "new user's request body" @Success 200 {object} common.APIResponse{data=models.Stub} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 403 {object} common.APIResponse{data=models.Stub} @Failure 409 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /users [post]

func (*UserController) Delete added in v0.44.23

func (c *UserController) Delete(w http.ResponseWriter, r *http.Request)

Delete is the users handler that processes and deletes given user (oneself) form the database.

@Summary Delete user @Description delete user @Tags users @Produce json @Param userID path string true "ID of the user to delete" @Success 200 {object} common.APIResponse{data=models.Stub} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 403 {object} common.APIResponse{data=models.Stub} @Failure 404 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /users/{userID} [delete]

func (*UserController) GetAll added in v0.44.23

func (c *UserController) GetAll(w http.ResponseWriter, r *http.Request)

GetAll is the users handler that processes and returns existing users list.

@Summary Get a list of users @Description get a list of users @Tags users @Produce json @Param X-Page-No header string true "page number" @Success 200 {object} common.APIResponse{data=users.GetAll.responseData} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 404 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /users [get]

func (*UserController) GetByID added in v0.44.23

func (c *UserController) GetByID(w http.ResponseWriter, r *http.Request)

GetByID is the users handler that processes and returns existing user's details according to callerID.

@Summary Get the user's details @Description get the user's details @Tags users @Accept json @Produce json @Success 200 {object} common.APIResponse{data=users.GetByID.responseData} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 404 {object} common.APIResponse{data=models.Stub} @Router /users/{userID} [get]

func (*UserController) GetPosts added in v0.44.23

func (c *UserController) GetPosts(w http.ResponseWriter, r *http.Request)

GetPosts fetches posts only from specified user.

@Summary Get user posts @Description get user posts @Tags users @Produce json @Param X-Hide-Replies header string false "hide replies" @Param X-Page-No header string true "page number" @Param userID path string true "user's ID for their posts" @Success 200 {object} common.APIResponse{data=users.GetPosts.responseData} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /users/{userID}/posts [get]

func (*UserController) PassphraseReset added in v0.44.26

func (c *UserController) PassphraseReset(w http.ResponseWriter, r *http.Request)

PassphraseReset handles a new passphrase regeneration.

@Summary Reset the passphrase @Description reset the passphrase @Tags users @Accept json @Produce json @Param request body users.UserUpdateRequest true "fill the e-mail address, or UUID fields" @Success 200 {object} common.APIResponse{data=models.Stub} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 404 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /users/passphrase/reset [post] @Router /users/passphrase/request [post]

func (*UserController) Update added in v0.44.23

func (c *UserController) Update(w http.ResponseWriter, r *http.Request)

Update is the users handler that allows the user to change their lists/options/passphrase.

@Summary Update user's data @Description update user's data @Tags users @Produce json @Param request body users.UserUpdateRequest true "data to update" @Param userID path string true "ID of the user to update" @Success 200 {object} common.APIResponse{data=models.Stub} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 403 {object} common.APIResponse{data=models.Stub} @Failure 404 {object} common.APIResponse{data=models.Stub} @Failure 409 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /users/{userID}/lists [patch] @Router /users/{userID}/options [patch] @Router /users/{userID}/passphrase [patch]

func (*UserController) UploadAvatar added in v0.44.23

func (c *UserController) UploadAvatar(w http.ResponseWriter, r *http.Request)

UploadAvatar is a handler function to update user's avatar directly in the app.

@Summary Post user's avatar @Description post user's avatar @Tags users @Accept json @Produce json @Param request body users.UserUpdateRequest true "new avatar data" @Param userID path string true "user's ID for avatar update" @Success 200 {object} common.APIResponse{data=models.Stub} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 403 {object} common.APIResponse{data=models.Stub} @Failure 404 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /users/{userID}/avatar [post]

type UserRepository added in v0.44.22

type UserRepository struct {
	// contains filtered or unexported fields
}

The implementation of pkg/models.UserRepositoryInterface.

func (*UserRepository) Delete added in v0.44.22

func (r *UserRepository) Delete(userID string) error

func (*UserRepository) GetAll added in v0.44.22

func (r *UserRepository) GetAll() (*map[string]models.User, error)

func (*UserRepository) GetByID added in v0.44.22

func (r *UserRepository) GetByID(userID string) (*models.User, error)

func (*UserRepository) GetPage added in v0.44.24

func (r *UserRepository) GetPage(pageOpts interface{}) (*map[string]models.User, error)

func (*UserRepository) Save added in v0.44.22

func (r *UserRepository) Save(user *models.User) error

type UserService added in v0.44.23

type UserService struct {
	// contains filtered or unexported fields
}

func (*UserService) Activate added in v0.44.26

func (s *UserService) Activate(ctx context.Context, UUID string) error

func (*UserService) Create added in v0.44.23

func (s *UserService) Create(ctx context.Context, user *models.User) error

func (*UserService) Delete added in v0.44.23

func (s *UserService) Delete(ctx context.Context, userID string) error

func (*UserService) FindAll added in v0.44.23

func (s *UserService) FindAll(ctx context.Context) (*map[string]models.User, error)

func (*UserService) FindByID added in v0.44.23

func (s *UserService) FindByID(ctx context.Context, userID string) (*models.User, error)

func (*UserService) FindPostsByID added in v0.44.37

func (s *UserService) FindPostsByID(ctx context.Context, userID string) (*map[string]models.Post, *map[string]models.User, error)

func (*UserService) ProcessPassphraseRequest added in v0.44.26

func (s *UserService) ProcessPassphraseRequest(ctx context.Context, userRequest interface{}) error

func (*UserService) Update added in v0.44.23

func (s *UserService) Update(ctx context.Context, userRequest interface{}) error

func (*UserService) UpdateAvatar added in v0.44.26

func (s *UserService) UpdateAvatar(ctx context.Context, userRequest interface{}) (*string, error)

type UserUpdateRequest added in v0.44.23

type UserUpdateRequest struct {
	// Lists update request payload.
	FlowList    map[string]bool `json:"flow_list"`
	RequestList map[string]bool `json:"request_list"`
	ShadeList   map[string]bool `json:"shade_list"`

	// Options updata request payload (legacy fields).
	UIDarkMode    bool                  `json:"dark_mode"`
	LiveMode      bool                  `json:"live_mode"`
	LocalTimeMode bool                  `json:"local_time_mode"`
	Private       bool                  `json:"private"`
	AboutText     string                `json:"about_you"`
	WebsiteLink   string                `json:"website_link"`
	OptionsMap    models.UserOptionsMap `json:"options_map"`

	// New passphrase request payload.
	NewPassphraseHex     string `json:"new_passphrase_hex"`
	CurrentPassphraseHex string `json:"current_passphrase_hex"`

	// New avatar upload/update request payload.
	AvatarByteData []byte `json:"data"`
	AvatarFileName string `json:"figure"`

	// Passphrase reset request
	UUID  string `json:"uuid"`
	Email string `json:"email"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL