store

package
v0.0.0-...-87faeab Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store interface {
	UserStore
	URLStore
}

Store is composes all the different store abstractions into one single abstraction.

type URL

type URL struct {
	ID                uuid.UUID `db:"id"`
	Owner             uuid.UUID `db:"owner"`
	OriginalURL       string    `db:"original_url"`
	ShortenedURLParam string    `db:"short_url_param"`
	VisitCount        *int      `db:"visit_count,omitempty"`
	CreatedAt         time.Time `db:"created_at"`
	UpdatedAt         time.Time `db:"updated_at"`
}

URL contains all the related info about the shortened url.

type URLStore

type URLStore interface {
	NewURL(ctx context.Context, userID uuid.UUID, originalURL, shortenedURL string) (URL, error)
	GetURLByID(ctx context.Context, id uuid.UUID) (URL, error)
	GetURLByParam(ctx context.Context, param string) (URL, error)
	GetURLByLongStr(ctx context.Context, longURL string) (URL, error)
}

URLStore is a url data store interface.

type User

type User struct {
	ID                   uuid.UUID  `db:"id,omitempty"`
	Email                string     `db:"email,omitempty"`
	Password             string     `db:"password"`
	APIKey               *uuid.UUID `db:"api_key,omitempty"`
	ResetPasswordExpires *time.Time `db:"reset_password_expires,omitempty"`
	ResetPasswordToken   *uuid.UUID `db:"reset_password_token,omitempty"`
	VerificationExpires  time.Time  `db:"verification_expires"`
	VerificationToken    uuid.UUID  `db:"verification_token,omitempty"`
	Verified             bool       `db:"verified,omitempty"`
	CreatedAt            time.Time  `db:"created_at,omitempty"`
	UpdatedAt            time.Time  `db:"updated_at,omitempty"`
}

User represents an authenticated user.

func (User) Compare

func (u User) Compare(hash, password string) (bool, error)

Compare compares the password hash against the passed in password string

func (*User) HashPassword

func (u *User) HashPassword() error

HashPassword hashes the user password using bcrypt hash function

type UserStore

type UserStore interface {
	NewUser(ctx context.Context, email, password string) (User, error)
	GetUserByID(ctx context.Context, id uuid.UUID) (User, error)
	GetUserByEmail(ctx context.Context, email string) (User, error)
	GetUserByVerificationToken(ctx context.Context, token uuid.UUID) (User, error)
	SetUserAPIKey(ctx context.Context, id, key uuid.UUID) error
	SetUserVerified(ctx context.Context, id uuid.UUID) error
}

UserStore is a user data store interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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