database

package
v0.0.0-...-fd49861 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *sql.DB
View Source
var ErrEditPost = errors.New("Posts can only be edited for 10 minutes")

ErrEditPost occurs when a user tries to edit a post after the designated time

View Source
var ErrNoThread = errors.New("Couldn't find that thread")

ErrNoThread occurs when a thread doesn't exist

View Source
var ErrWrongPassword = errors.New("Wrong password")

ErrWrongPassword when a user enters a password that doesn't match

Functions

This section is empty.

Types

type Database

type Database struct {
}

func (*Database) ConfirmUser

func (d *Database) ConfirmUser(userID string, confirmCode int) (confirmed bool, err error)

ConfirmUser sets a user to active in the database

func (*Database) CreateUser

func (d *Database) CreateUser(user *model.User) (userid string, confirm int, err error)

CreateUser creates a new user.

func (*Database) DeleteThread

func (d *Database) DeleteThread(threadID string) (err error)

DeleteThread will do a soft delete on a thread and all of its corresponding posts.

func (*Database) EditPost

func (d *Database) EditPost(id string, body string) (post model.Post, err error)

EditPost allows a user to edit a post within 10 minutes of posting it.

func (*Database) EditUser

func (d *Database) EditUser(user *model.User) (err error)

EditUser updates an existing user.

func (*Database) GetMessage

func (d *Database) GetMessage(messageID string) (model.Message, error)

GetMessage will get a message with the given ID.

func (*Database) GetMessagePosts

func (d *Database) GetMessagePosts(messageID string) ([]model.MessagePost, error)

GetMessagePosts will return all posts under a given thread.

func (*Database) GetMessages

func (d *Database) GetMessages(num int, userid string) ([]model.Message, error)

GetMessages retrieves a given number of messages.

func (*Database) GetPost

func (d *Database) GetPost(postID string) (post model.Post, err error)

GetPost retrieves a single post.

func (*Database) GetPosts

func (d *Database) GetPosts(threadId string) ([]model.Post, error)

GetPosts will return all posts under a given thread.

func (*Database) GetThread

func (d *Database) GetThread(threadID string) (model.Thread, error)

GetThread will get a thread with the given ID.

func (*Database) GetThreads

func (d *Database) GetThreads(num int, since string) ([]model.Thread, error)

GetThreads retrieves a given number of threads.

func (*Database) GetUser

func (d *Database) GetUser(username string) (user model.User, err error)

GetUser retrieves a given user.

func (*Database) GetUserInfo

func (d *Database) GetUserInfo(userID string) (userInfo model.UserInfo, err error)

GetUserInfo retrieves metadata about a user.

func (*Database) GetUsers

func (d *Database) GetUsers(search string) ([]model.User, error)

GetUsers will return a list of users whose username matches a search string.

func (*Database) HandlePasswordMigration

func (d *Database) HandlePasswordMigration(user *model.User, credentials *model.Credentials) error

HandlePasswordMigration will check a user's password against their hashed MD5 password from the legacy site. If it's a match, it will encrypt their password with bcrypt and delete the hashed password.

func (*Database) InitDb

func (d *Database) InitDb(environment string, configPath string) error

InitDb will initalize the database by setting and using environmental

func (*Database) PostMessage

func (d *Database) PostMessage(newMessage *model.NewMessage) (message model.NewMessage, err error)

PostMessage will create a new message "thread".

func (*Database) PostMessagePost

func (d *Database) PostMessagePost(message *model.MessagePost) (newMessage model.MessagePost, err error)

PostMessagePost will create a new message_post in an existing message.

func (*Database) PostPost

func (d *Database) PostPost(post *model.Post) (newPost model.Post, err error)

PostPost will create a new post.

func (*Database) PostThread

func (d *Database) PostThread(newThread *model.NewThread) (thread model.NewThread, err error)

PostThread creates a new thread.

type IDatabase

type IDatabase interface {
	InitDb(s string, e string) error
	EditUser(u *model.User) error
	CreateUser(u *model.User) (string, int, error)
	ConfirmUser(s string, i int) (bool, error)
	GetUser(s string) (model.User, error)
	GetUsers(s string) ([]model.User, error)
	GetThread(s string) (model.Thread, error)
	GetMessage(s string) (model.Message, error)
	GetMessages(i int, u string) ([]model.Message, error)
	GetMessagePosts(s string) ([]model.MessagePost, error)
	GetPost(s string) (model.Post, error)
	GetPosts(s string) ([]model.Post, error)
	GetThreads(i int, since string) ([]model.Thread, error)
	GetUserInfo(userID string) (model.UserInfo, error)
	HandlePasswordMigration(u *model.User, c *model.Credentials) error
	PostThread(t *model.NewThread) (model.NewThread, error)
	PostPost(p *model.Post) (model.Post, error)
	PostMessage(t *model.NewMessage) (model.NewMessage, error)
	PostMessagePost(p *model.MessagePost) (model.MessagePost, error)
	DeleteThread(s string) error
	EditPost(i string, b string) (model.Post, error)
}

type MockDatabase

type MockDatabase struct {
}

func (*MockDatabase) GetPosts

func (m *MockDatabase) GetPosts(threadId string) ([]model.Post, error)

func (*MockDatabase) GetThread

func (m *MockDatabase) GetThread(threadId string) (model.Thread, error)

func (*MockDatabase) GetUser

func (m *MockDatabase) GetUser(username string) (result model.User, err error)

func (*MockDatabase) InitDb

func (m *MockDatabase) InitDb(s string, e string) error

Jump to

Keyboard shortcuts

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