Documentation ¶
Index ¶
- type DB
- func (db *DB) AllImages() (*[]Image, error)
- func (db *DB) DeleteImage(id uuid.UUID) (*Image, error)
- func (db *DB) DeletePost(id uuid.UUID, user uuid.UUID) (*Post, error)
- func (db *DB) FindImage(id uuid.UUID) (*Image, error)
- func (db *DB) FindImagesByUser(user uuid.UUID) (*[]Image, error)
- func (db *DB) FindPost(id uuid.UUID) (*Post, error)
- func (db *DB) FindPostsByUser(user uuid.UUID) (*[]Post, error)
- func (db *DB) GetPosts(start int, end int) (*[]Post, error)
- func (db *DB) GetUserByEmail(email string) (*User, error)
- func (db *DB) GetUserByID(user uuid.UUID) (*User, error)
- func (db *DB) GetUserByUname(uname string) (*User, error)
- func (db *DB) InsertImage(user uuid.UUID, url string, medium string, small string, caption string) (*Image, error)
- func (db *DB) InsertPost(user uuid.UUID, title string, slug string, subtitle string, short string, ...) (*Post, error)
- func (db *DB) InsertUser(uname string, digest []byte, role string, email string, gpg string) (*User, error)
- func (db *DB) PublishedPosts(start int, end int) (*[]Post, error)
- func (db *DB) UnpublishedPosts() (*[]Post, error)
- func (db *DB) UpdatePost(id uuid.UUID, user uuid.UUID, title string, slug string, subtitle string, ...) (*Post, error)
- type Datastore
- type Image
- type Post
- type Tag
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB holds the database access method (allows us to mock the database)
func CreateDB ¶
CreateDB initializes the database connection and returns a new DB struct pointer databaseName is expected to be a PostgreSQL URL
func (*DB) DeleteImage ¶
DeleteImage takes an id of an image and if exists deletes from database returns error if not found
func (*DB) DeletePost ¶
DeletePost deletes and returns the image from the database that matches the uuid
func (*DB) FindImagesByUser ¶
FindImagesByUser returns an slice of images from the database for a given user
func (*DB) FindPostsByUser ¶
FindPostsByUser returns a slice of posts created by the given user
func (*DB) GetUserByEmail ¶
GetUserByEmail ...
func (*DB) GetUserByUname ¶
GetUserByUname ...
func (*DB) InsertImage ¶
func (db *DB) InsertImage(user uuid.UUID, url string, medium string, small string, caption string) (*Image, error)
InsertImage attempts to insert an image into the database provided three sizes of the image (original, medium, and small) return an error if it cannot be added or user reference invalid
func (*DB) InsertPost ¶
func (db *DB) InsertPost(user uuid.UUID, title string, slug string, subtitle string, short string, content string, digest string, published bool) (*Post, error)
InsertPost creates a post for the given user and returns the post
func (*DB) InsertUser ¶
func (db *DB) InsertUser(uname string, digest []byte, role string, email string, gpg string) (*User, error)
InsertUser ...
func (*DB) PublishedPosts ¶
PublishedPosts returns all published posts in database
func (*DB) UnpublishedPosts ¶
UnpublishedPosts returns all unpublished posts in database
type Datastore ¶
type Datastore interface { // User Functions InsertUser(uname string, digest []byte, role string, email string, gpg string) (*User, error) GetUserByEmail(email string) (*User, error) GetUserByID(user uuid.UUID) (*User, error) GetUserByUname(uname string) (*User, error) // Post Functions PublishedPosts(start int, end int) (*[]Post, error) UnpublishedPosts() (*[]Post, error) GetPosts(start int, end int) (*[]Post, error) FindPost(id uuid.UUID) (*Post, error) FindPostsByUser(user uuid.UUID) (*[]Post, error) InsertPost(user uuid.UUID, title string, slug string, subtitle string, short string, content string, digest string, published bool) (*Post, error) UpdatePost(id uuid.UUID, user uuid.UUID, title string, slug string, subtitle string, short string, content string, digest string, published bool) (*Post, error) DeletePost(id uuid.UUID, user uuid.UUID) (*Post, error) // Image Functions AllImages() (*[]Image, error) FindImage(id uuid.UUID) (*Image, error) FindImagesByUser(user uuid.UUID) (*[]Image, error) InsertImage(user uuid.UUID, url string, medium string, small string, caption string) (*Image, error) DeleteImage(id uuid.UUID) (*Image, error) }
Datastore interface contains all of our functions for the PostgreSQL database this allows us to mock the database during tests!
type Image ¶
type Image struct { ID uuid.UUID `db:"id" json:"id"` UserID uuid.UUID `db:"user_id" json:"user_id"` URL string `db:"url" json:"url"` Medium string `db:"medium" json:"medium"` Small string `db:"small" json:"small"` Caption string `db:"caption" json:"caption"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"` CreatedAt time.Time `db:"created_at" json:"created_at"` }
Image struct based on image table in database
type Post ¶
type Post struct { ID uuid.UUID `db:"id" json:"id"` UserID uuid.UUID `db:"user_id" json:"user_id"` Title string `db:"title" json:"title"` Slug string `db:"slug" json:"slug"` SubTitle string `db:"sub_title" json:"sub_title"` Short string `db:"short" json:"short"` PostContent string `db:"post_content" json:"post_content"` Digest string `db:"digest" json:"digest"` Published bool `db:"published" json:"published"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"` CreatedAt time.Time `db:"created_at" json:"created_at"` }
Post struct based on posts table in database
type Tag ¶
type Tag struct { ID uuid.UUID `db:"id" json:"id"` Name string `db:"name" json:"name"` Slug string `db:"slug" json:"slug"` }
Tag struct based on tag table in database
type User ¶
type User struct { ID uuid.UUID `db:"id"` Uname string `db:"uname"` Digest []byte `db:"digest"` Role string `db:"role"` Email string `db:"email"` GpgKey string `db:"email"` LastOnlineAt time.Time `db:"updated_at"` CreatedAt time.Time `db:"created_at"` }
User struct based on users table in database