model

package
v0.0.0-...-b0db392 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2015 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package model provides basic types for the data model of posty.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByCreatedAtDESC

type ByCreatedAtDESC []*Post

ByCreatedAtDESC represents a sort interface for sorting Posts descendingby CreatedAt

func (ByCreatedAtDESC) Len

func (o ByCreatedAtDESC) Len() int

Len returns the amount of posts

func (ByCreatedAtDESC) Less

func (o ByCreatedAtDESC) Less(i, j int) bool

Less defines the comparator of posts

func (ByCreatedAtDESC) Swap

func (o ByCreatedAtDESC) Swap(i, j int)

Swap swaps two items in the slice

type Model

type Model interface {
	PostPeer() PostPeer
	UserPeer() UserPeer
}

Model defines a basic model consisting of two entities `post` and `user`.

type Post

type Post struct {
	ID        string
	UID       string
	Username  string
	Message   string
	CreatedAt time.Time
	IsNew     bool
	Peer      PostPeer
}

Post represents a users post send to the board

func (*Post) SaveNew

func (p *Post) SaveNew() error

SaveNew saves a new post to the model.

type PostPeer

type PostPeer interface {
	GetByID(id string) (*Post, error)
	GetPosts() ([]*Post, error)
	NewPost(uid string) *Post
	SaveNew(p *Post) error
	Remove(p *Post) error
}

PostPeer defines interactions with the post data.

type User

type User struct {
	ID        string
	OAuthID   string
	Email     string
	Username  string
	Peer      UserPeer
	CreatedAt time.Time
	LastLogin time.Time
}

User represents an user in the model.

func (*User) SaveNew

func (u *User) SaveNew() error

SaveNew saves a new user to the model.

type UserPeer

type UserPeer interface {
	GetByID(id string) (*User, error)
	GetByOAuthID(id string) (*User, error)
	UpdateLastLogin(id string) error
	NewUser() *User
	SaveNew(user *User) error
}

UserPeer defines interactions with the user data.

Directories

Path Synopsis
Package awsdynamo implements `posty/model` persistence for the aws dynamodb database
Package awsdynamo implements `posty/model` persistence for the aws dynamodb database
integrationtest
Package integrationtest provides tests interacting with a dynamodb endpoint.
Package integrationtest provides tests interacting with a dynamodb endpoint.

Jump to

Keyboard shortcuts

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