db

package
v0.0.0-...-f27c042 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPassword = errors.New("Invalid password")
View Source
var ErrUnauthorized = errors.New("You do not have permission to perform this action")
View Source
var ErrUserNotFound = errors.New("User not found")

Functions

This section is empty.

Types

type Chirp

type Chirp struct {
	AuthorID int    `json:"author_id"`
	Body     string `json:"body"`
	ID       int    `json:"id"`
	Deleted  bool
}

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewDB

func NewDB(path string, debug bool) (*DB, error)

func (*DB) CheckToken

func (db *DB) CheckToken(token string) error

func (*DB) CreateChirp

func (db *DB) CreateChirp(body string, user_id int) (Chirp, error)

func (*DB) CreateUser

func (db *DB) CreateUser(email string, password string) (User, error)

func (*DB) DeleteChirp

func (db *DB) DeleteChirp(chirp_id int, user_id int) error

func (*DB) GetChirp

func (db *DB) GetChirp(id int) (Chirp, error)

func (*DB) GetChirps

func (db *DB) GetChirps() ([]Chirp, error)

func (*DB) GetChirpsByUser

func (db *DB) GetChirpsByUser(user_id int, sort_by string) ([]Chirp, error)

func (*DB) GetChirpsFiltered

func (db *DB) GetChirpsFiltered(filter func(Chirp) bool) ([]Chirp, error)

func (*DB) GetChirpsFilteredAndSorted

func (db *DB) GetChirpsFilteredAndSorted(
	filter func(Chirp) bool, cmp func(Chirp, Chirp) int,
) ([]Chirp, error)

func (*DB) GetChirpsOrderedBy

func (db *DB) GetChirpsOrderedBy(sort_by string) ([]Chirp, error)

func (*DB) GetUser

func (db *DB) GetUser(id int) (User, error)

func (*DB) GetUsers

func (db *DB) GetUsers() ([]User, error)

func (*DB) LogInUser

func (db *DB) LogInUser(email string, password string) (User, error)

func (*DB) RevokeToken

func (db *DB) RevokeToken(token string) error

func (*DB) UpdateUser

func (db *DB) UpdateUser(id int, email string, password string) (User, error)

func (*DB) UpgradeUser

func (db *DB) UpgradeUser(user_id int) error

type DBSchema

type DBSchema struct {
	Chirps        map[int]Chirp        `json:"chirps"`
	Users         map[int]User         `json:"users"`
	RevokedTokens map[string]time.Time `json:"revoked_tokens"`
}

type User

type User struct {
	Email       string `json:"email"`
	ID          int    `json:"id"`
	Password    string `json:"password"`
	IsChirpyRed bool   `json:"is_chirpy_red"`
}

Jump to

Keyboard shortcuts

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