db

package
v0.0.0-...-ec5c457 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2017 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBannedUserToCommunity

func AddBannedUserToCommunity(id, uid string) error

func AddFollowedCommunityToUser

func AddFollowedCommunityToUser(id, cslug string) error

func AddIgnoredUserToUser

func AddIgnoredUserToUser(id, ignored string) error

func AddModsToCommunity

func AddModsToCommunity(id, uid string) error

func AddVoteToPoll

func AddVoteToPoll(id, optiontitle, uid string) error

func CreateMentionsNotificationsFromPost

func CreateMentionsNotificationsFromPost(tid, senderSlug, postContent string)

Receives the topic id and post content, and create all the notifications for each mention/user inserting them on DB

func DeleteBannedUserToCommunity

func DeleteBannedUserToCommunity(id, uid string) error

func DeleteCommunity

func DeleteCommunity(id string) error

func DeleteCommunityBySlug

func DeleteCommunityBySlug(slug string) error

func DeleteFollowedCommunityToUser

func DeleteFollowedCommunityToUser(id, cslug string) error

func DeleteIgnoredUserToUser

func DeleteIgnoredUserToUser(id, ignored string) error

func DeleteModsToCommunity

func DeleteModsToCommunity(id, uid string) error

func DeleteNotification

func DeleteNotification(id string) error

func DeleteNotificationsByUser

func DeleteNotificationsByUser(uid string) error

func DeletePoll

func DeletePoll(id string) error

func DeletePollByTopic

func DeletePollByTopic(id string) error

func DeletePost

func DeletePost(id string) error

func DeleteTopic

func DeleteTopic(id string) error

func DeleteVoteToPoll

func DeleteVoteToPoll(id, optiontitle, uid string) error

func EnsureIndex

func EnsureIndex()

func GetDB

func GetDB() *mgo.Database

func IncrementPostsNumber

func IncrementPostsNumber(id string, n int) error

func IncrementTopicsNumber

func IncrementTopicsNumber(id string, n int) error

func MarkAsReadAllNotificationsByUser

func MarkAsReadAllNotificationsByUser(uid string) error

func UpdateCommunity

func UpdateCommunity(u Community) error

func UpdatePost

func UpdatePost(u Post) error

func UpdateTopic

func UpdateTopic(u Topic) error

func UpdateTopicLastUpdate

func UpdateTopicLastUpdate(id string, t int64) error

func UpdateUser

func UpdateUser(u User) error

func UpdateUserLastOnline

func UpdateUserLastOnline(id string, t int64) error

func UpdateUserLastPost

func UpdateUserLastPost(id string, t int64) error

Types

type Community

type Community struct {
	Id            bson.ObjectId   `json:"id"`
	Name          string          `json:"name"`
	Slug          string          `json:"slug"`
	Description   string          `json:"description"`
	Picture       string          `json:"picture"`      // Community picture (header picture?)
	Mods          []bson.ObjectId `json:"mods"`         // Community Moderators
	Banned_Users  []bson.ObjectId `json:"banned_users"` // Community Moderators
	Creation_Date int64           `json:"creation_date"`
	Posts_number  int64           `json:"posts_number"`  // number of total posts(messages) on the community
	Topics_number int64           `json:"topics_number"` // number of total topics on the community
}

func AddCommunity

func AddCommunity(u Community) (Community, error)

func GetAllCommunities

func GetAllCommunities() ([]Community, error)

func GetCommunityBySlug

func GetCommunityBySlug(slug string) (Community, error)

func (*Community) GenerateSlug

func (c *Community) GenerateSlug() string

func (*Community) IncrementPostsNumber

func (c *Community) IncrementPostsNumber(n int) error

func (*Community) IncrementTopicsNumber

func (c *Community) IncrementTopicsNumber(n int) error

func (*Community) IsBanned

func (c *Community) IsBanned(u User) bool

func (*Community) IsMod

func (c *Community) IsMod(u User) bool

func (*Community) UserCanPost

func (c *Community) UserCanPost(u User) bool

type DB

type DB struct {
	MongoSession *mgo.Session
	Name         string
	Host         string
}

func GetInstance

func GetInstance() *DB

type Notification

type Notification struct {
	Id            bson.ObjectId `json:"id"`
	Type          string        `json:"type"`   // type of notification (mention, new_post...)
	Params        []string      `json:"params"` // params for the notification, example: in a mention [topicid, user who mention, mentioned user]
	Uid           bson.ObjectId `json:"uid"`    // sent to User ID
	Read          bool          `json:"read"`
	Creation_Date int64         `json:"creation_date"`
}

func AddNotification

func AddNotification(u Notification) (Notification, error)

func GetNotificationById

func GetNotificationById(id string) (Notification, error)

func GetNotificationsByUser

func GetNotificationsByUser(uid string) ([]Notification, error)

func (*Notification) GetAllEntities

func (n *Notification) GetAllEntities() map[string]interface{}

func (*Notification) GetAllEntitiesForMention

func (n *Notification) GetAllEntitiesForMention() map[string]interface{}

func (*Notification) MarkAsRead

func (n *Notification) MarkAsRead()

type Poll

type Poll struct {
	Id              bson.ObjectId `json:"id"`
	Title           string        `json:"title"`
	Options         []PollOption  `json:"options"` // params for the notification, example: in a mention [topicid, user who mention, mentioned user]
	Tid             bson.ObjectId `json:"tid"`     // topic ID of the Poll
	Creation_Date   int64         `json:"creation_date"`
	Allowed_Options int64         // number of allowed options to select for each user
}

func AddPoll

func AddPoll(u Poll) (Poll, error)

func GetPollById

func GetPollById(id string) (Poll, error)

func GetPollByTopic

func GetPollByTopic(id string) (Poll, error)

type PollOption

type PollOption struct {
	Title string          `json:"title"`
	Votes []bson.ObjectId `json:"votes"` // user ids which voted for this option
}

type Post

type Post struct {
	Id             bson.ObjectId `json:"id"`
	Uid            bson.ObjectId `json:"uid"`
	Tid            bson.ObjectId `json:"tid"` // topic ID
	Content        string        `json:"content"`
	Creation_Date  int64         `json:"creation_date"`
	Editation_Date int64         `json:"editation_date"`
}

func AddPost

func AddPost(u Post) (Post, error)

func GetPostById

func GetPostById(id string) (Post, error)

func GetPostsByTopicId

func GetPostsByTopicId(tid string, limit, start int) ([]Post, error)

func GetPostsByTopicIdWithoutIgnored

func GetPostsByTopicIdWithoutIgnored(tid string, limit, start int, ignored []bson.ObjectId) ([]Post, error)

func (*Post) IsOwner

func (p *Post) IsOwner(u User) bool

type Topic

type Topic struct {
	Id             bson.ObjectId `json:"id"`
	Title          string        `json:"title"`
	Slug           string        `json:"slug"`
	Content        string        `json:"content"` // main post content
	Uid            bson.ObjectId `json:"uid"`
	Community      string        `json:"community"` // community slug
	Creation_Date  int64         `json:"creation_date"`
	Editation_Date int64         `json:"editation_date"`
	Last_Update    int64         `json:"last_update"`
	Posts_number   int64         `json:"posts_number"` // number of posts(messages) on the topic
}

func AddTopic

func AddTopic(u Topic) (Topic, error)

func GetTopicById

func GetTopicById(id string) (Topic, error)

func GetTopicsByCommunity

func GetTopicsByCommunity(cslugs []string, limit, start int) ([]Topic, error)

func GetTopicsByCommunityWithoutIgnoredUsers

func GetTopicsByCommunityWithoutIgnoredUsers(cslugs []string, limit, start int, ignored []bson.ObjectId) ([]Topic, error)

func GetTopicsByUser

func GetTopicsByUser(uid string, limit, start int) ([]Topic, error)

func GetTopicsListWithoutIgnoredUsers

func GetTopicsListWithoutIgnoredUsers(limit, start int, ignored []bson.ObjectId) ([]Topic, error)

func (*Topic) GenerateSlug

func (t *Topic) GenerateSlug() string

func (*Topic) IncrementPostsNumber

func (t *Topic) IncrementPostsNumber(n int) error

func (*Topic) IsOwner

func (t *Topic) IsOwner(u User) bool

type User

type User struct {
	Id                   bson.ObjectId   `json:"id"`
	Username             string          `json:"username"`
	Slug                 string          `json:"slug"`
	Email                string          `json:"email"`
	Password             string          `json:"password"`
	Picture              string          `json:"picture"`
	Followed_Communities []string        `json:"followed_communities"` // slugs
	Last_Post_Time       int64           `json:"last_post_time"`
	Last_Online_Time     int64           `json:"last_online_time"`
	Creation_Date        int64           `json:"creation_date"`
	Posts_Number         int64           `json:"posts_number"`
	Topics_Number        int64           `json:"topics_number"`
	IsAdmin              bool            `json:"isadmin"`
	IsBanned             bool            `json:"isbanned"`
	Ignored_Users        []bson.ObjectId `json:"ignored_users"` // users id array
	Activated            bool            `json:"activated"`
}

func AddUser

func AddUser(u User) (User, error)

func GetUserById

func GetUserById(id string) (User, error)

func GetUserByIdSafe

func GetUserByIdSafe(id string) (User, error)

func GetUserByPassword

func GetUserByPassword(password string) (User, error)

func GetUserBySlug

func GetUserBySlug(slug string) (User, error)

func GetUserBySlugSafe

func GetUserBySlugSafe(slug string) (User, error)

func GetUsersByIds

func GetUsersByIds(ids []bson.ObjectId) ([]User, error)

func GetUsersByIdsSafe

func GetUsersByIdsSafe(ids []bson.ObjectId) ([]User, error)

func (*User) Activate

func (u *User) Activate(option bool)

func (*User) ChangePassword

func (u *User) ChangePassword(oldpass, newpass string) bool

func (*User) GeneratePasswordHash

func (u *User) GeneratePasswordHash(pass string) string

func (*User) GenerateSlug

func (u *User) GenerateSlug() string

func (*User) MakeAdmin

func (u *User) MakeAdmin(option bool)

Jump to

Keyboard shortcuts

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