data

package
v0.0.0-...-83255bf Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: EUPL-1.2 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeActivation     = "activation"
	ScopeAuthentication = "authentication"
)

Variables

View Source
var (
	ErrRecordNotFound      = errors.New("record not found")
	ErrNotOwned            = errors.New("not owned")
	ErrDuplicateURL        = errors.New("url already exists in another entry")
	ErrDuplicateTagInEntry = errors.New("tag already exists in entry")
	ErrEditConflict        = errors.New("edit conflict")
)
View Source
var (
	ErrDuplicateName  = errors.New("duplicate username")
	ErrDuplicateEmail = errors.New("duplicate email")
)
View Source
var AnonymousUser = &User{}
View Source
var ErrInvalidMediaType = errors.New("not a valid MediaType")

Functions

func ValidateEmail

func ValidateEmail(v *validator.Validator, email string)

func ValidateEntry

func ValidateEntry(v *validator.Validator, item *Item)

FIXME

func ValidateFilters

func ValidateFilters(v *validator.Validator, f Filters)

func ValidatePasswordPlaintext

func ValidatePasswordPlaintext(v *validator.Validator, password string)

func ValidateTokenPlaintext

func ValidateTokenPlaintext(v *validator.Validator, tokenPlaintext string)

func ValidateURL

func ValidateURL(v *validator.Validator, surl, urlType string)

func ValidateUser

func ValidateUser(v *validator.Validator, user *User)

Types

type Article

type Article struct {
	ItemID   ItemID      `json:"-"`
	Content  null.String `json:"content,omitempty"`
	SiteName null.String `json:"site_name,omitempty"`
	Language null.String `json:"lang,omitempty"`
	Version  int64       `json:"-"`
}

type ArticleModel

type ArticleModel struct {
	DB *sql.DB
}

func (ArticleModel) Delete

func (a ArticleModel) Delete(itemID int64) error

func (ArticleModel) Get

func (a ArticleModel) Get(itemID ItemID) (*Article, error)

func (ArticleModel) Insert

func (a ArticleModel) Insert(article *Article, itemID ItemID) error

type Filters

type Filters struct {
	Page         int
	PageSize     int
	Sort         string
	SortSafelist []string
}

type Item

type Item struct {
	ID  ItemID `json:"id"`
	URL string `json:"url"`

	ItemMetadata
	CreationTime time.Time `json:"creation_time"`
	MediaType    MediaType `json:"media_type"`

	Archived   bool   `json:"archived"`
	Public     bool   `json:"public"`
	Pinned     bool   `json:"pinned"`
	ShouldRead bool   `json:"should_read"`
	Read       bool   `json:"read"`
	UserID     UserID `json:"-"`

	Version int64 `json:"version"`
}

type ItemID

type ItemID int64

type ItemMedia

type ItemMedia interface {
	Generate(string) error

	Insert(ItemID) error
	Get(ItemID) error
	Delete(ItemID) error
}

type ItemMetadata

type ItemMetadata struct {
	Title           string      `json:"title"`
	Author          null.String `json:"author"`
	Description     null.String `json:"description"`
	PublicationTime null.Time   `json:"publication_time"`
	ImageURL        null.String `json:"image_url"`
	IconURL         null.String `json:"icon_url"`
}

type ItemModel

type ItemModel struct {
	DB *sql.DB
}

func (ItemModel) Delete

func (i ItemModel) Delete(itemID ItemID) error

func (ItemModel) Get

func (i ItemModel) Get(itemID ItemID) (*Item, error)

func (ItemModel) Insert

func (i ItemModel) Insert(item *Item) error

func (ItemModel) Update

func (i ItemModel) Update(item *Item) error

func (ItemModel) Verify

func (i ItemModel) Verify(userID UserID, itemID ItemID) error

type MediaType

type MediaType string

swagger:enum MediaType ENUM(none, article, document, music, video)

const (
	// MediaTypeNone is a MediaType of type none.
	MediaTypeNone MediaType = "none"
	// MediaTypeArticle is a MediaType of type article.
	MediaTypeArticle MediaType = "article"
	// MediaTypeDocument is a MediaType of type document.
	MediaTypeDocument MediaType = "document"
	// MediaTypeMusic is a MediaType of type music.
	MediaTypeMusic MediaType = "music"
	// MediaTypeVideo is a MediaType of type video.
	MediaTypeVideo MediaType = "video"
)

func ParseMediaType

func ParseMediaType(name string) (MediaType, error)

ParseMediaType attempts to convert a string to a MediaType.

func (MediaType) IsValid

func (x MediaType) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (MediaType) MarshalText

func (x MediaType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*MediaType) Scan

func (x *MediaType) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (MediaType) String

func (x MediaType) String() string

String implements the Stringer interface.

func (*MediaType) UnmarshalText

func (x *MediaType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (MediaType) Value

func (x MediaType) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Models

type Models struct {
	Items    ItemModel
	Articles ArticleModel
	// Labels          LabelModel
	// LabelCategories LabelCategoryModel
	Tokens TokenModel
	Users  UserModel
}

func NewModels

func NewModels(db *sql.DB) Models

type Token

type Token struct {
	Plaintext string    `json:"token"`
	Hash      []byte    `json:"-"`
	ID        UserID    `json:"-"`
	Expiry    time.Time `json:"expiry"`
	Scope     string    `json:"-"`
}

type TokenModel

type TokenModel struct {
	DB *sql.DB
}

func (TokenModel) DeleteAllForUser

func (m TokenModel) DeleteAllForUser(scope string, userID UserID) error

func (TokenModel) Insert

func (m TokenModel) Insert(token *Token) error

func (TokenModel) New

func (m TokenModel) New(userID UserID, ttl time.Duration, scope string) (*Token, error)

type User

type User struct {
	ID           UserID    `json:"id"`
	CreationTime time.Time `json:"creation_time"`
	Name         string    `json:"name"`
	Email        string    `json:"email"`
	Password     password  `json:"-"`
	Activated    bool      `json:"activated"`
	Version      int64     `json:"-"`
}

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

type UserID

type UserID int

type UserModel

type UserModel struct {
	DB *sql.DB
}

func (UserModel) GetByEmail

func (m UserModel) GetByEmail(email string) (*User, error)

func (UserModel) GetForToken

func (m UserModel) GetForToken(tokenScope, tokenPlaintext string) (*User, error)

func (UserModel) Insert

func (m UserModel) Insert(user *User) error

func (UserModel) Update

func (m UserModel) Update(user *User) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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