models

package
v0.0.0-...-5707e41 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2014 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SIZE_MAX     = 4096
	SIZE_DEFAULT = 5

	SORT_DATE      = "date"
	SORT_RELEVANCE = "relevance"
	SORT_RATING    = "rating"
	SORT_RANDOM    = "random"
)
View Source
const (
	TAG_DELIM = ","

	QUOTE_CHAR_MAX   = 1024
	QUOTE_AUTHOR_MAX = 32

	TAG_PER_QUOTE_MAX = 32
	TAG_CHAR_MAX      = 32
)
View Source
const (
	VOTE_UP     = "up"
	VOTE_DOWN   = "down"
	VOTE_DELETE = "delete"
)

Variables

View Source
var (
	SortStrings = []string{
		SORT_DATE, SORT_RELEVANCE,
		SORT_RATING, SORT_RANDOM,
	}

	UnixEpochBinder = revel.Binder{
		Bind: func(params *revel.Params, key string, typ reflect.Type) reflect.Value {
			var t time.Time

			params.Bind(&t, key)

			if t.IsZero() {
				return reflect.Zero(typ)
			}

			return reflect.ValueOf(UnixEpoch(t.Unix()))
		},
		Unbind: func(output map[string]string, key string, value interface{}) {
			e := value.(UnixEpoch).Time()
			output[key] = e.Format(revel.DateFormat)
		},
	}

	ArgsBinder = revel.Binder{
		Bind: func(params *revel.Params, key string, t reflect.Type) reflect.Value {
			var arg Args

			val := reflect.ValueOf(&arg).Elem()
			typ := val.Type()

			for i := 0; i < typ.NumField(); i++ {
				dest := val.Field(i)
				dest.Set(
					revel.Bind(params,
						toKey(typ.Field(i).Name),
						dest.Type(),
					),
				)
			}
			return reflect.ValueOf(arg)
		},
		Unbind: func(output map[string]string, key string, value interface{}) {
			arg := value.(Args)
			val := reflect.ValueOf(&arg).Elem()
			typ := val.Type()

			if IsZero(val) {
				return
			}

			for i := 0; i < typ.NumField(); i++ {
				if field := val.Field(i); !IsZero(field) {
					revel.Unbind(output,
						toKey(typ.Field(i).Name),
						field.Interface(),
					)
				}
			}
		},
	}
)
View Source
var (
	VoteTypeStrings = []string{
		VOTE_UP,
		VOTE_DOWN,
		VOTE_DELETE,
	}

	ValidVoteType = regexp.MustCompile(
		strings.Join(VoteTypeStrings, `|`),
	)
)
View Source
var TagsBinder = revel.Binder{
	Bind: revel.ValueBinder(func(v string, t reflect.Type) reflect.Value {
		if len(v) == 0 {
			return reflect.Zero(t)
		}
		s := strings.Split(v, TAG_DELIM)
		for i := range s {
			s[i] = strings.TrimSpace(s[i])
		}
		return reflect.ValueOf(s)
	}),
	Unbind: nil,
}

Functions

func IsZero

func IsZero(v reflect.Value) bool

Types

type Args

type Args struct {
	Id          int
	Tag, Search string
	From, To    UnixEpoch

	Sort string
	Desc bool

	Page, Size int
}

func (Args) Merge

func (dest Args) Merge(src Args) Args

Returns a new Args struct containing all non-zero values from dest and non-zero values from src for which there is a zero value in dest note: reverse merge for templating: Args{Sort:"relevence"}.Merge(arg)

type Quote

type Quote struct {
	QuoteId int
	Quote   string
	Author  string
	Created int64
	Rating  int
	Tags    TagsArray
	UserId  string
}

func (*Quote) Validate

func (quote *Quote) Validate(v *revel.Validation)

type QuoteEntry

type QuoteEntry struct {
	QuoteId int
	Quote   string
	Author  string
	Created int64
	Rating  int
	UserId  string
}

func (*QuoteEntry) PreInsert

func (q *QuoteEntry) PreInsert(s gorp.SqlExecutor) error

type QuoteTypeConverter

type QuoteTypeConverter struct{}

func (QuoteTypeConverter) FromDb

func (me QuoteTypeConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)

func (QuoteTypeConverter) ToDb

func (me QuoteTypeConverter) ToDb(val interface{}) (interface{}, error)

type TagEntry

type TagEntry struct {
	QuoteId int
	Tag     string
}

type TagsArray

type TagsArray []string

type UnixEpoch

type UnixEpoch int64

func (UnixEpoch) Int

func (u UnixEpoch) Int() int64

func (UnixEpoch) Time

func (u UnixEpoch) Time() time.Time

type VoteEntry

type VoteEntry struct {
	UserId   string
	QuoteId  int
	VoteType string
	Created  int64
}

func (*VoteEntry) PreInsert

func (v *VoteEntry) PreInsert(s gorp.SqlExecutor) error

Jump to

Keyboard shortcuts

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