database

package
v0.0.0-...-db51e23 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 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 Comment

type Comment struct {
	ID        int       `json:"id"`
	AuthorId  int       `json:"author_id"`
	Author    string    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
}

type DB

type DB interface {
	// Stash operations
	GetPublicStashes() ([]*Stash, error)
	GetPublicStashesUser(userId int) ([]*Stash, error)
	GetUserStashes(userId int) ([]*Stash, error)
	GetStashDetailed(stashId int) (*StashDetail, error)
	CheckOwner(userId int, stashId int) (bool, error)
	CheckStashPublic(stashId int) (bool, error)

	//User operations
	GetUserByEmail(email string) (*User, error)
	GetUserProfile(userId int) (*UserDetail, error)
	UpsertUser(username string, name string, email string, pictue string) error

	// Comment operations
	GetComments(stashId int) ([]*Comment, error)

	//Link operations
	GetLinks(stashId int) ([]*Link, error)
}

func NewPostgresDB

func NewPostgresDB(connStr string) (DB, error)

Takes in a connection string and returns a DB interface, which is a pointer to the Postgres Database

type Link struct {
	ID      int     `json:"id"`
	Url     string  `json:"url"`
	Comment *string `json:"comment"` // Optional(Can be nil)
}

type Postgres

type Postgres struct {
	Pool *pgxpool.Pool
}

func (*Postgres) CheckOwner

func (pg *Postgres) CheckOwner(userId int, stashId int) (bool, error)

func (*Postgres) CheckStashPublic

func (pg *Postgres) CheckStashPublic(stashId int) (bool, error)

func (*Postgres) GetComments

func (pg *Postgres) GetComments(stashId int) ([]*Comment, error)
func (pg *Postgres) GetLinks(stashId int) ([]*Link, error)

func (*Postgres) GetPublicStashes

func (pg *Postgres) GetPublicStashes() ([]*Stash, error)

func (*Postgres) GetPublicStashesUser

func (pg *Postgres) GetPublicStashesUser(userId int) ([]*Stash, error)

func (*Postgres) GetStashDetailed

func (pg *Postgres) GetStashDetailed(stashId int) (*StashDetail, error)

func (*Postgres) GetUserByEmail

func (pg *Postgres) GetUserByEmail(email string) (*User, error)

func (*Postgres) GetUserProfile

func (pg *Postgres) GetUserProfile(userId int) (*UserDetail, error)

Returns User by email

func (*Postgres) GetUserStashes

func (pg *Postgres) GetUserStashes(userId int) ([]*Stash, error)

func (*Postgres) UpsertUser

func (pg *Postgres) UpsertUser(
	username string,
	name string,
	email string,
	pictue string,
) error

This function takes in the google idtoken payload as the input and inserts user into the database if they don't exist.

type Stash

type Stash struct {
	ID         int       `json:"id"`
	Author     string    `json:"author"`
	AuthorId   int       `json:"author_id"`
	Title      string    `json:"title"`
	Body       *string   `json:"body"` // Optional(Can be nil)
	Stars      int       `json:"stars"`
	Created_at time.Time `json:"created_at"`
}

type StashDetail

type StashDetail struct {
	// Embed Stash
	Stash
	IsPublic bool       `json:"is_public"`
	Links    []*Link    `json:"links"`
	Comments []*Comment `json:"comments"`
}

type User

type User struct {
	ID       int     `json:"id"`
	Username string  `json:"username"`
	Picture  *string `json:"picture"`
}

type UserDetail

type UserDetail struct {
	// Embed User
	User
	Stars         int       `json:"stars"`
	Created_at    time.Time `json:"created_at"`
	PublicStashes []*Stash  `json:"public_stashes"`
}

Jump to

Keyboard shortcuts

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