users

package
v0.46.6 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Users routes and controllers logic package for the backend.

Index

Constants

View Source
const (
	LOGGER_WORKER_NAME string = "userController"
)

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(
	pollRepository models.PollRepositoryInterface,
	postRepository models.PostRepositoryInterface,
	subscriptionRepository models.SubscriptionRepositoryInterface,
	requestRepository models.RequestRepositoryInterface,
	tokenRepository models.TokenRepositoryInterface,
	userRepository models.UserRepositoryInterface,
) models.UserServiceInterface

Types

type UserActivationRequest added in v0.45.23

type UserActivationRequest struct {
	UUID string `json:"uuid" example:"550e8400-e29b-41d4-a716-446655440000"`
}

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,
	statService models.StatServiceInterface,
	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 an user via an UUID string
@Description		This function call provides a method for the new user's activation using a received UUID string in payload.
@Tags			users
@Produce		json
@Param			request	body		users.UserActivationRequest	true	"A received UUID string to activate the user after the registration."
@Success		200		{object}	common.APIResponse{data=models.Stub} "The user was activated successfully."
@Failure		400		{object}	common.APIResponse{data=models.Stub} "The request body contains invalid data, or data types."
@Failure		404		{object}	common.APIResponse{data=models.Stub} "The UUID string does not match any user in the system."
@Failure		500		{object}	common.APIResponse{data=models.Stub} "There is a problem processing the request (e.g. a problem accessing the database)."
@Router			/users/activation [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		This function call provides a method on how to create a new user in the system.
@Tags			users
@Accept			json
@Produce		json
@Param			request	body	users.UserCreateRequest 	true		     "The request body containing all listed fields for a new user's creation."
@Success		201		{object}	common.APIResponse{data=models.Stub} "The request was processed successfully and an user was created."
@Failure		400		{object}	common.APIResponse{data=models.Stub} "The request body contains invalid data, or data types."
@Failure		403		{object}	common.APIResponse{data=models.Stub} "This response code may occur when the registration is disabled."
@Failure		409		{object}	common.APIResponse{data=models.Stub} "The nickname and/or e-mail fields contain data, that had been already used by someone else."
@Failure		500		{object}	common.APIResponse{data=models.Stub} "There is a problem processing the request in the internal server logic. This may occur when a new user cannot be saved to the database for example."
@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		This function call ensures a caller's user account is deleted while all posted items (posts and polls) are purged too. Additionally, all associated requests and tokens are deleted as well.
@Tags			users
@Produce		json
@Param			userID	path		string	true	"ID of the user to be purged"
@Success		200		{object}	common.APIResponse{data=models.Stub}	"The submitted user account has been deleted."
@Failure		400		{object}	common.APIResponse{data=models.Stub}	"Invalid input data."
@Failure		403		{object}	common.APIResponse{data=models.Stub}	"Blocked attempt to cross-delete other (foreign) user account. The userID param has to be equal to the caller's nickname."
@Failure		404		{object}	common.APIResponse{data=models.Stub}	"Such user does not exist in the system."
@Failure		500		{object}	common.APIResponse{data=models.Stub}	"There is an internal processing problem present (e.g. data could not be saved to the database)."
@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		This function call retrieves a paginated list of user accounts. The page number starts at 0 (and is the default value if not provided in a request).
@Tags			users
@Produce		json
@Param			X-Page-No	header		integer	false	"Page number (default is 0)"
@Success		200			{object}	common.APIResponse{data=users.GetAll.responseData} 	"Requested page of user accounts returned."
@Failure		400			{object}	common.APIResponse{data=models.Stub}			"Invalid input data."
@Failure		500			{object}	common.APIResponse{data=models.Stub}			"A generic problem in the internal system's logic. See the `message` KV in JSON to gain more information."
@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		This function call retrieves an user's data that is to be specified in the URI path (as `userID` param below in the request section). A special keyword `caller` can be used to retrieve all reasonable data for the user calling the API. The identity is assured using the refresh token, which is encoded into the refresh HTTP cookie.
@Tags			users
@Accept			json
@Produce		json
@Param			userID			path		string	true	"User's ID to be shown"
@Success		200			{object}	common.APIResponse{data=users.GetByID.responseData}	"Requested user's data (may be limited according to the caller)."
@Failure		400			{object}	common.APIResponse{data=models.Stub}			"Invalid input data."
@Failure		404			{object}	common.APIResponse{data=models.Stub}			"User not found in the database."
@Failure		500			{object}	common.APIResponse{data=models.Stub}			"A generic problem in the internal system's logic. See the `message` KV in JSON to gain more information."
@Router			/users/caller [get]
@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		This function call is a very specific combination of the users' and posts' services. It retrieves a paginated list of posts made by such user. Special restrictions are applied, such as the privacy (private account, which is not followed by the caller is shown blank). If the list is empty, ensure you are following such user/account.
@Tags			users
@Produce		json
@Param			X-Hide-Replies	header		string	false	"Optional boolean specifying the request of so-called root posts (those not being a reply). Default is false."
@Param			X-Page-No	header		string	false	"Page number (default is 0)."
@Param			userID		path		string	true	"User's ID (usually the nickname)."
@Success		200				{object}	common.APIResponse{data=users.GetPosts.responseData}	"A paginated list of the user's posts (special restriction may apply)."
@Failure		400				{object}	common.APIResponse{data=models.Stub}			"Invalid input data."
@Failure		500				{object}	common.APIResponse{data=models.Stub}			"A very internal service's logic problem. See the `message` field to gain more information."
@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		This function call is to be called when an user forgets their passphrase and wants a new one. This very call does the passphrase regeneration under the hood specifically.
@Description
@Description		Internally, this is a mailing procedure as two mails has to be delivered and the content used with the API/client to successfully reset the passphrase. This call generates the second mail.
@Tags			users
@Accept			json
@Produce		json
@Param			request	body		users.UserPassphraseReset	true	"Received UUID string to confirm the reset."
@Success		200		{object}	common.APIResponse{data=models.Stub} 	"The passphrase was changed successfully."
@Failure		400		{object}	common.APIResponse{data=models.Stub}	"Invalid data received."
@Failure		404		{object}	common.APIResponse{data=models.Stub}	"Such user does not exist in the system."
@Failure		500		{object}	common.APIResponse{data=models.Stub}	"There is an internal processing problem present (e.g. data could not be saved to the database)."
@Router			/users/passphrase/reset [post]

func (*UserController) PassphraseResetRequest added in v0.44.23

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

PassphraseResetRequest handles a new passphrase generation request creation.

@Summary		Request the passphrase reset
@Description		This function call is to be used when an user forgets their passphrase and wants a new one. This very call generates a request for such reset only.
@Description
@Description		Internally, this is a mailing procedure as two mails has to be delivered and the content used with the API/client to successfully reset the passphrase. This call generates the first mail.
@Tags			users
@Accept			json
@Produce		json
@Param			request	body		users.UserPassphraseRequest	true	"User's  e-mail address."
@Success		200		{object}	common.APIResponse{data=models.Stub} 	"The passphrase reset request was created successfully."
@Failure		400		{object}	common.APIResponse{data=models.Stub}	"Invalid data received."
@Failure		404		{object}	common.APIResponse{data=models.Stub}	"Such user does not exist in the system."
@Failure		500		{object}	common.APIResponse{data=models.Stub}	"There is an internal processing problem present (e.g. data could not be saved to the database)."
@Router			/users/passphrase/request [post]

func (*UserController) UpdateLists added in v0.45.19

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

UpdateLists is the users handler that allows the user to change their lists.

@Summary		Update user's list properties
@Description		This function call enables the caller to modify lists saved with other user's data in the database.
@Description
@Description 		Those lists are KV structures, that hold another user's nickname as key, and a boolean as a value to specify whether such list should apply its logic on such user.
@Description		At least one list has to be specified.
@Tags			users
@Produce		json
@Param			request	body		users.UserUpdateListsRequest	true	"Lists object data as a desired state recipe."
@Param			userID	path		string					true	"ID of the user to update"
@Success		200		{object}	common.APIResponse{data=models.Stub}	"User's lists have been updated."
@Failure		400		{object}	common.APIResponse{data=models.Stub}	"Invalid data received."
@Failure		403		{object}	common.APIResponse{data=models.Stub}	"This code can occur when one wants to update another user (this feature to be prepared for a possible admin panel function)."
@Failure		404		{object}	common.APIResponse{data=models.Stub}	"Such user does not exist."
@Failure		500		{object}	common.APIResponse{data=models.Stub}	"There is a processing problem in the internal logic, or some system's component does not behave (e.g. database is unavailable)."
@Router			/users/{userID}/lists [patch]

func (*UserController) UpdateOptions added in v0.45.19

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

UpdateOptions is the users handler that allows the user to change their options.

@Summary		Update user's option properties
@Description		This function call enables the caller to modify some of their properties (options) saved in the database.
@Description
@Description		Note: the duality in the options' configuration (map vs. separated booleans) reflects the attempt for backward compatibility with older clients (v0.45.18 and older).
@Description		The preferred one is the map configuration.
@Tags			users
@Produce		json
@Param			request	body		users.UserUpdateOptionsRequest	true	"A JSON object containing at least one option with a desired value."
@Param			userID	path		string					true	"ID of the user to update"
@Success		200		{object}	common.APIResponse{data=models.Stub} 	"User's options were updated successfully."
@Failure		400		{object}	common.APIResponse{data=models.Stub}	"Invalid data received."
@Failure		403		{object}	common.APIResponse{data=models.Stub}	"Unauthorized attempt to modify a foreign option set."
@Failure		404		{object}	common.APIResponse{data=models.Stub}	"Such user does not exist in the system."
@Failure		500		{object}	common.APIResponse{data=models.Stub}	"There is an internal processing problem (e.g. data could not be saved in database)."
@Router			/users/{userID}/options [patch]

func (*UserController) UpdatePassphrase added in v0.45.19

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

UpdatePassphrase is the users handler that allows the user to change their passphrase.

@Summary		Update user's passphrase
@Description		This function call enables the caller to modify their current passphrase. The current and a new passphrase are to be sent (hashed using sha512 algorithm).
@Description
@Description		The problem there is on how to fetch the current passphrase. This can be achieved using a web browser in dev tools (F12), where the hash is to be found on the Network card.
@Description		Another problem is that the server uses a secret (pepper), that is appended to a passphrase before loading it into the has algorithm. This secret cannot be fetched via API, as it is a sensitive variable saved as the environmental variable where the server is run.
@Tags			users
@Produce		json
@Param			request	body		users.UserUpdatePassphraseRequest	true	"Hexadecimal representation of the sha512-hashed passphrases."
@Param			userID	path		string					true	"ID of the user to update"
@Success		200		{object}	common.APIResponse{data=models.Stub} 	"User has been updated."
@Failure		400		{object}	common.APIResponse{data=models.Stub}	"Invalid data received."
@Failure		403		{object}	common.APIResponse{data=models.Stub}	"Unauthorized attempt to modify a forigner's passphrase."
@Failure		404		{object}	common.APIResponse{data=models.Stub}	"Such user does not exist in the system."
@Failure		500		{object}	common.APIResponse{data=models.Stub}	"There is an internal processing problem present (e.g. data could not be saved to the database)."
@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		This function call presents a method to change one's avatar URL property while also uploading a new picture as a profile photo. Binary data and a figure's extension (JPG, JPEG, PNG) has to be encapsulated into the JSON object as base64 formatted text.
@Tags			users
@Accept			json
@Produce		json
@Param			request	body		users.UserUploadAvatarRequest	true	"The data object containing the new avatar's data."
@Param			userID	path		string					true	"User's ID for avatar update."
@Success		200		{object}	common.APIResponse{data=models.Stub}	"The avatar was uploaded and updated successfully."
@Failure		400		{object}	common.APIResponse{data=models.Stub}	"Invalid data received."
@Failure		403		{object}	common.APIResponse{data=models.Stub}	"Unauthorized attempt to modify a forigner's avatar."
@Failure		404		{object}	common.APIResponse{data=models.Stub}	"Such user does not exist in the system."
@Failure		500		{object}	common.APIResponse{data=models.Stub}	"There is an internal processing problem present (e.g. data could not be saved to the database)."
@Router			/users/{userID}/avatar [post]

type UserCreateRequest added in v0.45.19

type UserCreateRequest struct {
	Nickname      string `json:"nickname" example:"alice"`
	PassphraseHex string `` /* 160-byte string literal not displayed */
	Email         string `json:"email" example:"alice@example.com"`
}

type UserPassphraseRequest added in v0.45.23

type UserPassphraseRequest struct {
	// Passphrase reset pre-request
	Email string `json:"email" example:"alice@example.com"`
}

type UserPassphraseReset added in v0.45.23

type UserPassphraseReset struct {
	// Passphrase reset request
	UUID string `json:"uuid" example:"550e8400-e29b-41d4-a716-446655440000"`
}

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, createRequestI interface{}) 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 UserUpdateListsRequest added in v0.45.19

type UserUpdateListsRequest struct {
	// Lists update request payload.
	FlowList    map[string]bool `json:"flow_list" example:"bob:false"`
	RequestList map[string]bool `json:"request_list" example:"cody:true"`
	ShadeList   map[string]bool `json:"shade_list" example:"dave:true"`
}

type UserUpdateOptionsRequest added in v0.45.19

type UserUpdateOptionsRequest struct {
	// 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" example:"let's gooo"`
	WebsiteLink   string                `json:"website_link" example:"https://example.com"`
	OptionsMap    models.UserOptionsMap `json:"options_map" example:"private:true"`
}

type UserUpdatePassphraseRequest added in v0.45.19

type UserUpdatePassphraseRequest struct {
	// New passphrase request payload.
	NewPassphraseHex     string `json:"new_passphrase_hex"`
	CurrentPassphraseHex string `json:"current_passphrase_hex"`
}

type UserUploadAvatarRequest added in v0.45.19

type UserUploadAvatarRequest struct {
	// New avatar upload/update request payload.
	AvatarByteData []byte `json:"data" format:"base64"`
	AvatarFileName string `json:"figure" example:"avatar.jpeg"`
}

Jump to

Keyboard shortcuts

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