user

package
v0.0.0-...-caa70b2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//TimeFormat1 to format date into
	TimeFormat1 = "2000-01-01"
	//TimeFormat2 Other format to format date time
	TimeFormat2 = "January 01, 2000"
)

Variables

This section is empty.

Functions

func ConvertToPageDto

func ConvertToPageDto(page domain.Page[User]) *domain.Page[Dto]

ConvertToPageDto converts User entities Page into a User DTO Page.

Types

type ChangePasswordRequest

type ChangePasswordRequest struct {
	Username    string `json:"username"`
	OldPassword string `json:"oldPassword"`
	NewPassword string `validate:"required,min=8,max=72" json:"newPassword"`
}

type ConfirmEmailRequest

type ConfirmEmailRequest struct {
	ID   string `json:"id"`
	Code string `json:"code"`
}

type CreateRequest

type CreateRequest struct {
	Username string `validate:"required,min=3,max=24" json:"username"`
	Password string `validate:"required,min=8,max=72" json:"password"`
	Request
}

type CreateResponse

type CreateResponse struct {
	Dto
}

type Dto

type Dto struct {
	ID          string    `json:"id"`
	CreatedAt   time.Time `json:"createdAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
	Email       string    `validate:"required,min=3" json:"email"`
	FullName    string    `json:"fullname"`
	DateOfBirth time.Time `json:"dateOfBirth"`
	Location    string    `json:"location"`
	Gender      GenderDto `json:"gender"`
	Enabled     bool      `json:"enabled"`
}

UserDto represents user DTO.

func ConvertToDto

func ConvertToDto(u *User) *Dto

ConvertToDto converts User entity into a User DTO.

type Gender

type Gender uint8

Gender is either MALE, FEMALE or OTHER.

const (
	MALE Gender = iota
	FEMALE
	OTHER
)

func (Gender) Stringify

func (g Gender) Stringify() string

Stringify converts Gender into string.

type GenderDto

type GenderDto string

GenderDto can be Male, Female and Other.

func (GenderDto) Numberfy

func (g GenderDto) Numberfy() Gender

Numberfy converts GenderDto into a user.Gender.

type Option

type Option func(*User)

func Credentials

func Credentials(crd *security.Credentials) Option

func DateOfBirth

func DateOfBirth(dob time.Time) Option

func Email

func Email(e string) Option

func Enabled

func Enabled(e bool) Option

func FullName

func FullName(fn string) Option

func Id

func Id(id uuid.UUID) Option

func Location

func Location(l string) Option

func Roles

func Roles(roles ...*security.Role) Option

func Sex

func Sex(g Gender) Option

type Request

type Request struct {
	Email       string    `validate:"required,min=3" json:"email"`
	FullName    string    `json:"fullname"`
	DateOfBirth time.Time `json:"dateOfBirth"`
	Location    string    `json:"location"`
	Gender      GenderDto `json:"gender"`
}

type RolesRequest

type RolesRequest struct {
	ID    string   `json:"id"`
	Roles []string `json:"roles"`
	Cmd   string   `json:"command"` // ADD or DELETE
}

type SignInRequest

type SignInRequest struct {
	Username string `validate:"required,min=3,max=24" json:"username"`
	Password string `validate:"required,min=8,max=72" json:"password"`
}

type SignInResponse

type SignInResponse struct {
	Token string `json:"token"`
}

type SignUpResponse

type SignUpResponse struct {
	ID string `json:"id"`
}

type UpdateRequest

type UpdateRequest struct {
	ID string `json:"id"`
	Request
}

type UpdateResponse

type UpdateResponse struct {
	Dto
}

type User

type User struct {
	bun.BaseModel `bun:"table:users,alias:u"`

	domain.Entity
	Email       string                `bun:"email,notnull,unique"`
	FullName    string                `bun:"full_name,nullzero"`
	DateOfBirth time.Time             `bun:"date_of_birth,nullzero"`
	Location    string                `bun:"location,nullzero"`
	Gender      Gender                `bun:"gender,nullzero"`
	Enabled     bool                  `bun:"enabled"`
	Credentials *security.Credentials `bun:"rel:has-one,join:id=user_id"`
	Roles       []*security.Role      `bun:"rel:has-many,join:id=user_id"`
}

User represents database entity.

func ConvertToUser

func ConvertToUser(r *Dto) (*User, error)

ConvertToUser converts User DTO into a User entity.

func New

func New(opts ...Option) *User

Jump to

Keyboard shortcuts

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