models

package
v0.0.0-...-15e17f2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorResponse

type ErrorResponse struct {
	Field string `json:"field"`
	Tag   string `json:"tag"`
	Value string `json:"value,omitempty"`
}

func ValidateStruct

func ValidateStruct[T any](payload T) []*ErrorResponse

ValidateStruct validates a struct and returns an ErrorResponse array

type SignInInput

type SignInInput struct {
	Email    string `json:"email"  validate:"required,email"`
	Password string `json:"password"  validate:"required"`
}

SignInInput holds user signin properties

type SignUpInput

type SignUpInput struct {
	Name            string `json:"name" validate:"required"`
	Email           string `json:"email" validate:"required,email"`
	Password        string `json:"password" validate:"required,min=8"`
	PasswordConfirm string `json:"passwordConfirm" validate:"required,min=8"`
}

SignUpInput holds user signup properties

type User

type User struct {
	ID        uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key"`
	Name      string    `gorm:"type:varchar(100);not null"`
	Email     string    `gorm:"type:varchar(100);uniqueIndex;not null"`
	Password  string    `gorm:"type:varchar(100);not null"`
	Role      string    `gorm:"type:varchar(50);default:'user';not null"`
	Provider  string    `gorm:"type:varchar(50);default:'local';not null"`
	Verified  bool      `gorm:"not null;default:false"`
	CreatedAt time.Time `gorm:"autoCreateTime"`
	UpdatedAt time.Time `gorm:"autoUpdateTime"`
	// contains filtered or unexported fields
}

User holds user related properties

func (*User) GetByEmail

func (u *User) GetByEmail(email string) (*User, error)

GetByEmail returns a user from database by email

func (*User) GetByID

func (u *User) GetByID(id uuid.UUID) (*User, error)

GetByID returns a user from database by ID

func (*User) SetDB

func (u *User) SetDB(db *gorm.DB)

SetDB sets the DB connection for a user instance

type UserResponse

type UserResponse struct {
	ID        uuid.UUID `json:"id,omitempty"`
	Name      string    `json:"name,omitempty"`
	Email     string    `json:"email,omitempty"`
	Role      string    `json:"role,omitempty"`
	Provider  string    `json:"provider"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

UserResponse holds user response properties

func FilterUserRecord

func FilterUserRecord(user *User) UserResponse

FilterUserRecord returns a filtered User response

Jump to

Keyboard shortcuts

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