db

package
v0.0.0-...-7f22e17 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2017 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Overview

create.go -- DB queries that create objects

db.go -- Database Connection for Application (moved everything into CRUD letter files for simplicity) >Keeping all DB access functions in this package to keep things clean

delete.go -- DB queries that delete objects

read.go -- DB queries that read objects

update.go -- DB queries that edit objects

Index

Constants

This section is empty.

Variables

View Source
var Connection *mgo.Session

Functions

func ActivateAccount

func ActivateAccount(user bson.ObjectId) error

[UPDATE] activates account (when email is verified)

func AddAdmin

func AddAdmin(oldAdmin, user bson.ObjectId, group string) error

[UPDATE] pushes a thread to a user's watchlist

func AddFriend

func AddFriend(friend, user bson.ObjectId) error

[UPDATE] saves a friend

func AddName

func AddName(user bson.ObjectId, name string) error

[UPDATE] activates account (when email is verified)

func AddUsername

func AddUsername(username string, user bson.ObjectId) error

[UPDATE] adds username for a given uid

func ChangePassword

func ChangePassword(newPassword string, oldPassword string, user bson.ObjectId) error

[UPDATE] changes password for a given uid

func ChangeUsername

func ChangeUsername(username string, user bson.ObjectId) error

[UPDATE] changes username for a given uid

func CheckGroup

func CheckGroup(group string) (*models.Group, error)

[READ] gets group info -- meta info about group from group collection

func CreateGroup

func CreateGroup(group string, user bson.ObjectId, private bool) error

[CREATE] creates a group, rather, reserves a namespace for a group

func CreateHeadPost

func CreateHeadPost(author, body, content, contentType string, authorId bson.ObjectId) *models.Post

[CREATE] creates a head post for a given thread -- leave thread id unset

func CreateNotification

func CreateNotification(id bson.ObjectId, link, text string) error

[CREATE] creates a notification for the Id

func CreatePost

func CreatePost(authorId, thread bson.ObjectId, responseTo []bson.ObjectId,
	author, body, content, contentType string) (*models.Post, error)

[CREATE] creates a post for a given thread

func CreateThread

func CreateThread(group string, anonymous bool, post *models.Post) error

[CREATE] creates a thread from a struct of a given JSON -- also creates an mthread for each location

func CreateUser

func CreateUser(email, username, password string) (string, error)

[CREATE] creates user in the Database with given email, username, and hashed password

func DeleteGroup

func DeleteGroup(group string, user bson.ObjectId) error

[DELETE] remove a thread

func DeletePost

func DeletePost(postID, userID bson.ObjectId) error

[DELETE] removes a post

func DeleteThread

func DeleteThread(threadID, userID bson.ObjectId) error

[DELETE] remove a thread

func DeleteUser

func DeleteUser(user bson.ObjectId) error

[UPDATE] deletes a user's account (in reality, updates 'deleted' to 'true')

func EditPost

func EditPost(text string, post, user bson.ObjectId) error

[UPDATE] change the text for a given post (id)

func GetFriends

func GetFriends(author string) ([]bson.ObjectId, error)

[READ] gets user's friends -- resolving "joins"

func GetFriendsById

func GetFriendsById(author bson.ObjectId) ([]bson.ObjectId, error)

[READ] gets user's friends -- resolving "joins"

func GetFriendsJoined

func GetFriendsJoined(id bson.ObjectId) ([]string, error)

[READ] gets a user's friends -- in a string slice format

func GetGroup

func GetGroup(group string, page int) ([]models.Mthread, error)

[READ] gets available threads for a given group on a particular page

func GetGroupInfo

func GetGroupInfo(grp string) (*models.GroupInfo, error)

[READ] get metadata about group

func GetIdFromEmail

func GetIdFromEmail(email string) string

[READ] gets user data -- posts, watchlist, thread likes, friends -- just returns what we need

func GetIdFromUsername

func GetIdFromUsername(username string) string

[READ] gets user data -- posts, watchlist, thread likes, friends -- just returns what we need

func GetNotifications

func GetNotifications(userId bson.ObjectId) ([]models.Notification, error)

[READ]

func GetPermission

func GetPermission(group string, user string) *models.Permission

[READ] checks if user is a member of a group

func GetPopularPosts

func GetPopularPosts(id string, skip int) (*models.PopularPosts, error)

[READ] kinda like getting a thread, but it's just the most popular posts (8 of them)

func GetSaved

func GetSaved(userId bson.ObjectId) ([]models.Mthread, error)

[READ]

func GetThread

func GetThread(threadID bson.ObjectId) (*models.ResThread, error)

[READ] gets all posts for a given thread

func GetThreadParent

func GetThreadParent(thread string) string

[READ] returns group that the given thead (hex string) belongs to

func GetThreadSize

func GetThreadSize(thread string) int

[READ] get a thread's length (how many posts are in a thread)

func GetUser

func GetUser(user string) (*models.GetUser, error)

[READ] gets user data -- posts, watchlist, thread likes, friends -- just returns what we need

func GetUsername

func GetUsername(id bson.ObjectId) string

[READ] gets user's username

func GroupExists

func GroupExists(group string) bool

[Misc] Checks if group exists

func IsMember

func IsMember(group string, user string) bool

[READ] checks if user is a member of a group

func LoginCheck

func LoginCheck(email, hashword string) (string, bool)

[READ] compares the user & hashed password given to the one in the DB

func RemoveAdmin

func RemoveAdmin(oldAdmin, user bson.ObjectId, group string) error

[UPDATE] Removes admins, only the author can do this

func RemoveFriend

func RemoveFriend(friend, user bson.ObjectId) error

[UPDATE] removes a friend

func RemoveUser

func RemoveUser(user bson.ObjectId) error

[DELETE] actually deletes a user (for dev use only!)

func RemoveUsername

func RemoveUsername(username string, user bson.ObjectId) error

[UPDATE] removes username for a given uid -- musn't be username

func RequestFriend

func RequestFriend(user bson.ObjectId, username, friend string) error

func SaveThread

func SaveThread(mthread, user bson.ObjectId) error

[UPDATE] pushes a thread to a user's watchlist

func SearchGroups

func SearchGroups(str string) ([]string, error)

[READ] searches groups for match

func SearchThreads

func SearchThreads(id string, str string, page int) ([]models.Mthread, error)

[READ] search posts text index for a given string

func SearchUsers

func SearchUsers(str string) ([]string, error)

[READ] searches usernames and names for match -- EXACT

func UnsaveThread

func UnsaveThread(thread, user bson.ObjectId) error

[UPDATE] removes a thread from a user's watchlist

Types

This section is empty.

Jump to

Keyboard shortcuts

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