dao

package
v0.0.0-...-6a0d18d Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encrypt

func Encrypt(plainText string) (cryptext string)

hash plaintext with SHA-1

func SessionDeleteAll

func SessionDeleteAll() (err error)

SessionDeleteAll delete all sessions from database

func UserDeleteAll

func UserDeleteAll() (err error)

UserDeleteAll delete all users from database

Types

type Post

type Post struct {
	UUID      string    `bson:"uuid,omitempty"`
	Body      string    `bson:"body,omitempty"`
	ThreadID  string    `bson:"threadid"`
	UserID    string    `bson:"userid"`
	CreatedAt time.Time `bson:"created_at_time"`
}

Post which store post information

func (*Post) CreatedAtDate

func (post *Post) CreatedAtDate() string

CreatedAtDate use the CreatedAtDate function

func (*Post) User

func (post *Post) User() (user User, err error)

User get the user who wrote the post

type Session

type Session struct {
	UUID      string    `bson:"uuid,omitempty"`
	Email     string    `bson:"email,omitempty"`
	UserID    string    `bson:"userid"`
	CreatedAt time.Time `bson:"created_at_time"`
}

Session which store Session information

func (*Session) Check

func (session *Session) Check() (valid bool, err error)

Check if session is valid in the database

func (*Session) DeleteByUUID

func (session *Session) DeleteByUUID() (err error)

DeleteByUUID delete session from database

func (*Session) User

func (session *Session) User() (user User, err error)

User get the user from the session

type Thread

type Thread struct {
	UUID      string    `bson:"uuid,omitempty"`
	Topic     string    `bson:"topic,omitempty"`
	UserID    string    `bson:"userid"`
	CreatedAt time.Time `bson:"created_at_time"`
}

Thread which store thread information

func ThraedByUUID

func ThraedByUUID(uuid string) (conv Thread, err error)

ThraedByUUID get a thread by the uuid

func Threads

func Threads() (threads []Thread, err error)

Threads Get all threads in the database and returns it

func (*Thread) CreatedAtDate

func (thread *Thread) CreatedAtDate() string

CreatedAtDate format the CreatedAt date to display nicely on the screen

func (*Thread) Posts

func (thread *Thread) Posts() (posts []Post, err error)

Posts get posts to a thread

func (*Thread) User

func (thread *Thread) User() (user User, err error)

User get the user who started this thread

type User

type User struct {
	UUID      string    `bson:"uuid,omitempty"`
	Name      string    `bson:"name,omitempty"`
	Email     string    `bson:"email,omitempty"`
	Password  string    `bson:"password,omitempty"`
	CreatedAt time.Time `bson:"created_at_time"`
}

User which store User information

func UserByEmail

func UserByEmail(email string) (user User, err error)

UserByEmail get a single user given the email

func UserByUUID

func UserByUUID(uuid string) (user User, err error)

UserByUUID get a single user given the UUID

func Users

func Users() (users []User, err error)

Users get all users in the database and returns it

func (*User) Create

func (user *User) Create() (err error)

Create a new user, save user info into the database

func (*User) CreatePost

func (user *User) CreatePost(conv Thread, body string) (post Post, err error)

CreatePost create a new post to a thread

func (*User) CreateSession

func (user *User) CreateSession() (session Session, err error)

CreateSession create a new session for an existing user

func (*User) CreateThread

func (user *User) CreateThread(topic string) (conv Thread, err error)

CreateThread create a new thread

func (*User) Delete

func (user *User) Delete() (err error)

Delete user from database

func (*User) Session

func (user *User) Session() (session Session, err error)

Session get the session for an existing user

func (*User) Update

func (user *User) Update() (err error)

Update user information in the database

Jump to

Keyboard shortcuts

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