stories

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2018 License: MIT Imports: 7 Imported by: 8

Documentation

Overview

Package stories represents the story resource

Index

Constants

View Source
const (
	// TableName is the database table for this resource
	TableName = "stories"
	// KeyName is the primary key value for this resource
	KeyName = "id"
	// Order defines the default sort order in sql for this resource
	Order = "name asc, id desc"
)

Variables

This section is empty.

Functions

func AllowedParams

func AllowedParams() []string

AllowedParams returns the cols editable by everyone

func AllowedParamsAdmin

func AllowedParamsAdmin() []string

AllowedParamsAdmin returns the cols editable by admins

func Popular() *query.Query

Popular returns a query for all stories with points over a certain threshold

func Published

func Published() *query.Query

Published returns a query for all stories with status >= published.

func Query

func Query() *query.Query

Query returns a new query for stories with a default order.

func Where

func Where(format string, args ...interface{}) *query.Query

Where returns a new query for stories with the format and arguments supplied.

Types

type Story

type Story struct {
	// resource.Base defines behaviour and fields shared between all resources
	resource.Base

	// status.ResourceStatus defines a status field and associated behaviour
	status.ResourceStatus

	CommentCount int64
	Name         string
	Summary      string
	URL          string
	Points       int64
	Rank         int64
	UserID       int64

	// UserName denormalises the user name - use join instead?
	UserName string
}

Story handles saving and retreiving stories from the database

func Find

func Find(id int64) (*Story, error)

Find fetches a single story record from the database by id.

func FindAll

func FindAll(q *query.Query) ([]*Story, error)

FindAll fetches all story records matching this query from the database.

func FindFirst added in v1.0.1

func FindFirst(format string, args ...interface{}) (*Story, error)

FindFirst fetches a single story record from the database using a where query with the format and args provided.

func New

func New() *Story

New creates and initialises a new story instance.

func NewWithColumns

func NewWithColumns(cols map[string]interface{}) *Story

NewWithColumns creates a new story instance and fills it with data from the database cols provided.

func (*Story) CanonicalURL

func (s *Story) CanonicalURL() string

CanonicalURL is the canonical URL of the story on this site including a slug for seo

func (*Story) Code

func (s *Story) Code() bool

Code returns true if this is a link to a git repository At present we only check for github urls, we should at least check for bitbucket

func (*Story) CommentCountDisplay

func (s *Story) CommentCountDisplay() string

CommentCountDisplay returns the comment count or ellipsis if count is 0

func (*Story) DestinationURL

func (s *Story) DestinationURL() string

DestinationURL returns the URL of the story if no url is set, it uses the CanonicalURL

func (*Story) Domain

func (s *Story) Domain() string

Domain returns the domain of the story URL

func (*Story) Editable

func (s *Story) Editable() bool

Editable returns true if this story is editable. Stories are editable if less than 1 hours old

func (*Story) GodocURL

func (s *Story) GodocURL() string

GodocURL returns the godoc.org URL for this story, or empty string if none

func (*Story) NameDisplay

func (s *Story) NameDisplay() string

NameDisplay returns a title string without hashtags (assumed to be at the end), by truncating the title at the first #

func (*Story) NegativePoints

func (s *Story) NegativePoints() int64

NegativePoints returns a negative point score or 0 if points is above 0

func (*Story) OwnedBy

func (s *Story) OwnedBy(uid int64) bool

OwnedBy returns true if this user id owns this story.

func (*Story) PrimaryURL

func (s *Story) PrimaryURL() string

PrimaryURL returns the URL to use for this story in lists Videos and Show Ask stories link to the story for other links for now it is the destination

func (*Story) ShowAsk

func (s *Story) ShowAsk() bool

ShowAsk returns true if this is a Show: or Ask: story

func (*Story) Tags

func (s *Story) Tags() []string

Tags are defined as words beginning with # in the title TODO: for speed and clarity we could extract at submit time instead and store in db

func (*Story) VetURL

func (s *Story) VetURL() string

VetURL returns a URL for goreportcard.com, for code repos

func (*Story) YouTube

func (s *Story) YouTube() bool

YouTube returns true if this is a youtube video

func (*Story) YouTubeURL

func (s *Story) YouTubeURL() string

YouTubeURL returns the youtube URL

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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