models

package
v0.0.0-...-7a7783f Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 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 AuthUser

type AuthUser struct {
	*User
	Admin bool `json:"admin"`
}

AuthUser represents a user account for private visibility (used for login and update response) Its MarshalJSON function will expose its role.

func (*AuthUser) MarshalJSON

func (u *AuthUser) MarshalJSON() ([]byte, error)

MarshalJSON marshals a given user's information including role

type Post

type Post struct {
	ID            int                `json:"id"`
	Title         string             `json:"title"`
	Slug          string             `json:"slug"`
	Body          string             `json:"body"`
	CreatedAt     time.Time          `json:"createdAt"`
	UpdatedAt     pgtype.Timestamptz `json:"updatedAt"`
	Tags          []string           `json:"tags"`
	Hidden        bool               `json:"hidden"`
	AuthorID      string             `json:"authorid"`
	FeatureImgURL string             `json:"featureImgUrl"`
	Subtitle      string             `json:"subtitle"`
	Views         int                `json:"views"`
}

Post stores the data of a post

func (*Post) MarshalJSON

func (p *Post) MarshalJSON() ([]byte, error)

MarshalJSON marshals post data

type User

type User struct {
	ID        uuid.UUID  `json:"id"`
	Name      string     `json:"name"`
	Email     string     `json:"email"`
	Password  string     `json:"password"`
	Admin     bool       `json:"admin"`
	CreatedAt time.Time  `json:"createdAt"`
	UpdatedAt *time.Time `json:"updatedAt"`
	Username  string     `json:"username"`
}

User represents a user account for public visibility (used for public endpoints) Its MarshalJSON function wont expose its role.

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

CheckPassword compares the given password with the user's password

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin returns if the user is an admin

func (*User) MarshalJSON

func (u *User) MarshalJSON() ([]byte, error)

MarshalJSON marshals a given user's information

func (*User) SetPassword

func (u *User) SetPassword(password string)

SetPassword hashes and salts the given password and then sets it to the user

Jump to

Keyboard shortcuts

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