models

package
v0.0.0-...-811c2de Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2015 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TagStringToTags

func TagStringToTags(tagString string) []string

Convert a string containing comma-separated tags to an array of tags.

Types

type Entity

type Entity struct {
	Id              bson.ObjectId `bson:"_id"`
	ContentType     string
	Owner           string
	OriginalOwner   string
	IsShare         bool
	Title           string
	Tags            []string
	Content         interface{}
	RenderedContent string
	IndexedContent  string
	Assets          []bson.ObjectId
}

An entity represents a post to be displayed on the site. It has an associated content type, is associated with an owner, and may be a share of a previous post.

func GetEntity

func GetEntity(id string, db *mgo.Database) (Entity, error)

Retrive an entity given an ID

func NewEntity

func NewEntity(contentType string, owner string, originalOwner string, isShare bool, title string, tags []string, content interface{}) Entity

Create a new entity with a new ID.

func (*Entity) BelongsToUser

func (e *Entity) BelongsToUser(user User) bool

Determine whether or not the entity belongs to the user.

func (*Entity) Delete

func (e *Entity) Delete(db *mgo.Database) error

Delete an entity from the database

func (*Entity) Save

func (e *Entity) Save(db *mgo.Database, es *elastigo.Conn) error

Save the current entity in the database, generating display and index content in the process

type User

type User struct {
	Username             string
	Email                string
	Hashword             []byte
	Following            []string
	Followers            []string
	Friends              []string
	FriendRequests       []string
	FriendshipsRequested []string
	Status               string
}

A representation of a user in the database, storing only minimal information.

func GetUser

func GetUser(username string, db *mgo.Database) (User, error)

Retrieve a user from the database given a username

func NewUser

func NewUser(username string, email string, password string) (User, error)

func (*User) AddFollowing

func (u *User) AddFollowing(user *User)

Add a unidirectional following relationship between two users

func (*User) AddFriendship

func (u *User) AddFriendship(user *User)

Add a bidirectional friendship relationship between the two users, removing any pending requests if they exist.

func (*User) Authenticate

func (u *User) Authenticate(password string) bool

Attempt to authenticate user with a password.

func (*User) Entities

func (u *User) Entities(db *mgo.Database) ([]Entity, error)

Fetch all given entities for a user XXX This is a naive and expensive approach

func (*User) HasRequestedFriendship

func (u *User) HasRequestedFriendship(username string) bool

Return true if the user has requested to be friends with the user by the given username.

func (*User) IsFollowing

func (u *User) IsFollowing(username string) bool

Return true if the user is following another user by that username.

func (*User) IsFriend

func (u *User) IsFriend(username string) bool

Return true of the user is friends with the user by the given username.

func (*User) Profile

func (u *User) Profile(db *mgo.Database) (Entity, error)

Retrieve just the profile for the user.

func (*User) RemoveFollowing

func (u *User) RemoveFollowing(user *User)

Remove a following relationship between two users.

func (*User) RemoveFriendship

func (u *User) RemoveFriendship(user *User)

Remove a friendship relationship between the two users.

func (*User) RemoveFriendshipRequest

func (u *User) RemoveFriendshipRequest(user *User)

Remove a friendship request between this user and the given user.

func (*User) RequestFriendship

func (u *User) RequestFriendship(user *User)

Create a friendship request between this user and the given user.

func (*User) Save

func (u *User) Save(db *mgo.Database) error

Save a given user model to the database.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

Set a password for the given user.

Jump to

Keyboard shortcuts

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