user

package
v0.0.0-...-9139af7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDeleteUserInvalidPassword = gonethttpresponse.NewFailResponseError(
		"password",
		"invalid password",
		nil,
		http.StatusUnauthorized,
	)
	ErrChangeUsernameAlreadyRegistered = gonethttpresponse.NewFailResponseError(
		"username",
		"username is already registered",
		nil,
		http.StatusBadRequest,
	)
)
View Source
var (
	Service    = &service{}
	Controller = &controller{}
	Module     = &gonethttp.Module{
		Pattern:    "/user",
		Service:    Service,
		Controller: Controller,
		BeforeLoadFn: func(m *gonethttp.Module) {
			m.Middlewares = gonethttp.NewMiddlewares(
				internalmiddleware.AuthenticateAccessToken,
			)
		},
		RegisterRoutesFn: func(m *gonethttp.Module) {
			m.RegisterExactRoute(
				"PUT /profile",
				Controller.UpdateProfile,
				internalmiddleware.Validate(
					&UpdateProfileRequest{},
					func(
						body *UpdateProfileRequest,
						validations *govalidatormappervalidation.StructValidations,
					) {
						if body.Birthdate != nil {
							internalvalidator.Service.Birthdate(
								"birthdate",
								*body.Birthdate,
								internal.BirthdateOptions,
								validations,
							)
						}
					},
				),
			)
			m.RegisterExactRoute(
				"GET /profile",
				Controller.GetMyProfile,
			)
			m.RegisterExactRoute(
				"PUT /username",
				Controller.ChangeUsername,
				internalmiddleware.Validate(
					&ChangeUsernameRequest{},
					func(
						body *ChangeUsernameRequest,
						validations *govalidatormappervalidation.StructValidations,
					) {
						internalvalidator.Service.Username(
							"username",
							body.Username,
							validations,
						)
					},
				),
			)
			m.RegisterExactRoute(
				"DELETE /",
				Controller.DeleteUser,
				internalmiddleware.Validate(&DeleteUserRequest{}),
			)
		},
	}
)

Functions

This section is empty.

Types

type ChangeUsernameRequest

type ChangeUsernameRequest struct {
	Username string `json:"username"`
}

ChangeUsernameRequest is the request DTO to change username

type DeleteUserRequest

type DeleteUserRequest struct {
	Password string `json:"password"`
}

DeleteUserRequest is the request DTO to delete a user

type GetMyProfileResponseBody

type GetMyProfileResponseBody struct {
	gonethttpresponse.BaseJSendSuccessBody
	Data GetMyProfileResponseData `json:"data"`
}

GetMyProfileResponseBody is the response body DTO to get my profile

type GetMyProfileResponseData

type GetMyProfileResponseData struct {
	FirstName       string     `json:"first_name"`
	LastName        string     `json:"last_name"`
	Birthdate       *time.Time `json:"birthdate,omitempty"`
	Username        string     `json:"username"`
	Email           string     `json:"email"`
	EmailIsVerified bool       `json:"email_is_verified"`
	Phone           *string    `json:"phone,omitempty"`
	PhoneIsVerified *bool      `json:"phone_is_verified,omitempty"`
	HasTOTPEnabled  bool       `json:"has_totp_enabled"`
}

GetMyProfileResponseData is the response data DTO to get my profile

type UpdateProfileRequest

type UpdateProfileRequest struct {
	FirstName *string    `json:"first_name,omitempty"`
	LastName  *string    `json:"last_name,omitempty"`
	Birthdate *time.Time `json:"birthdate,omitempty"`
}

UpdateProfileRequest is the request DTO to update profile

Jump to

Keyboard shortcuts

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