Documentation
¶
Index ¶
- type DB
- func (db *DB) AllPosts(prevDate string, limit int) ([]*Post, error)
- func (db *DB) CreatePost(Post *Post) error
- func (db *DB) CreateUser(user *User) error
- func (db *DB) DeletePost(Post *Post) error
- func (db *DB) DeleteUser(user *User) error
- func (db *DB) EmailCheck(email string) (bool, error)
- func (db *DB) NameCheck(name string) (bool, error)
- func (db *DB) OnePost(id uuid.UUID) (*Post, error)
- func (db *DB) SearchUsers(query, prevDate string, limit int) ([]*User, error)
- func (db *DB) UpdatePost(Post *Post) error
- func (db *DB) UpdateUserPhoto(user *User) error
- type Datastore
- type Post
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is our database type By attaching the Datastore interface's methods, our DB struct will implement the Datastore interface.
func (*DB) AllPosts ¶
AllPosts takes a previous date and limit and returns all posts in reverse chronological order or an error.
func (*DB) CreatePost ¶
CreatePost creates a new post in the DB and returns an error. CreatePost expects Post will come in with id uuid.UUID, title string, body string, created time.Time, uid uuid.UUID
func (*DB) CreateUser ¶
CreateUser creates a new user and returns nil or an error CreateUser expects user will come in with name string, email string, pwd []byte
func (*DB) DeletePost ¶
DeletePost deletes one specific Post from DB and returns an error. DeletePost expects Post will come in with id uuid.UUID
func (*DB) DeleteUser ¶
DeleteUser deletes one specific user from DB, along with associated posts, and returns nil or an error. DeleteUser expects user will come in with id uuid.UUID
func (*DB) EmailCheck ¶
EmailCheck checks if an email is already in use when a new user signs up.
func (*DB) SearchUsers ¶
SearchUsers takes a search query and limit and returns all posts in reverse chronological order or an error.
func (*DB) UpdatePost ¶
UpdatePost updates a specific Post in DB and returns an error. UpdatePost expects Post will come in with id uuid.UUID, title string, body string, updated time.Time
func (*DB) UpdateUserPhoto ¶
UpdateUserPhoto updates a user's profile photo and returns nil or an error. UpdateUserPhoto expects user will come in with avatar string, updated time.Time
type Datastore ¶
type Datastore interface {
//Sample User methods
SearchUsers(query, prevDate string, limit int) ([]*User, error)
CreateUser(user *User) error
EmailCheck(email string) (bool, error)
NameCheck(name string) (bool, error)
UpdateUserPhoto(user *User) error
DeleteUser(user *User) error
//Sample Post methods
AllPosts(prevDate string, limit int) ([]*Post, error)
OnePost(id uuid.UUID) (*Post, error)
CreatePost(Post *Post) error
UpdatePost(Post *Post) error
DeletePost(Post *Post) error
}
Datastore is an interface to work with the Postgres database. The Server struct in API/app/server.go includes this Datastore interface for handlers to access via dependency injection. Using an interface allows us to easily create mock databases for testing purposes.
type Post ¶
type Post struct {
ID uuid.UUID `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Author User `json:"author"`
}
Post type defined
type User ¶
type User struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Email string `json:"email,omitempty"`
Password string `json:"password,omitempty"`
Avatar string `json:"avatar"`
Created time.Time `json:"created,omitempty"`
Updated time.Time `json:"updated,omitempty"`
}
User type defined