model

package
v0.0.0-...-bb7c920 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 3 Imported by: 5

Documentation

Overview

Package model holds the various types and interfaces for Parrot.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLocaleIdent = &errors.Error{
		Type:    "InvalidLocaleIdent",
		Message: "invalid field locale ident"}
	ErrInvalidLocaleLanguage = &errors.Error{
		Type:    "InvalidLocaleLanguage",
		Message: "invalid field locale language"}
	ErrInvalidLocaleCountry = &errors.Error{
		Type:    "InvalidLocaleCountry",
		Message: "invalid field locale country"}
)
View Source
var (
	ErrInvalidClientName = &errors.Error{
		Type:    "InvalidClientName",
		Message: "invalid field name"}
	ErrInvalidProjectID = &errors.Error{
		Type:    "InvalidProjectID",
		Message: "invalid field project_id"}
)
View Source
var (
	ErrInvalidEmail = &errors.Error{
		Type:    "InvalidEmail",
		Message: "invalid email"}
	ErrInvalidName = &errors.Error{
		Type:    "InvalidName",
		Message: "invalid name"}
	ErrInvalidPassword = &errors.Error{
		Type:    "InvalidPassword",
		Message: "invalid password"}
)
View Source
var (
	ErrInvalidProjectName = &errors.Error{
		Type:    "InvalidProjectName",
		Message: "invalid field project name"}
)
View Source
var (
	ErrValidationFailure = &errors.Error{
		Type:    "ValidationFailure",
		Message: "data validation failed"}
)
View Source
var Locales = map[string]LocaleInfo{}/* 110 elements not displayed */

Locales is mapping of standard locale idents to LocaleInfo

Functions

func HasMinLength

func HasMinLength(str string, min int) bool

HasMinLength returns true if the string's length is greater than or equal to the min parameter.

func NewValidationError

func NewValidationError(errs []errors.Error) error

NewValidationError constructs and returns a new error.

func ValidEmail

func ValidEmail(str string) bool

ValidEmail returns true if the string is of the valid email format.

Types

type Locale

type Locale struct {
	ID        string            `db:"id" json:"id"`
	Ident     string            `db:"ident" json:"ident"`
	Language  string            `db:"language" json:"language"`
	Country   string            `db:"country" json:"country"`
	Pairs     map[string]string `db:"pairs" json:"pairs"`
	ProjectID string            `db:"project_id" json:"project_id"`
}

func (*Locale) SyncKeys

func (loc *Locale) SyncKeys(t []string)

SyncKeys will add new keys from string slice t to document pairs.

func (*Locale) Validate

func (loc *Locale) Validate() error

Validate returns an error if the locale's data is invalid.

type LocaleInfo

type LocaleInfo struct {
	Ident    string
	Language string
	Country  string
}

LocaleInfo holds the data to specify a standard locale.

type LocaleStorer

type LocaleStorer interface {
	CreateLocale(loc Locale) (*Locale, error)
	DeleteLocale(projID string, ident string) error
}

LocaleStorer is the interface to store locales.

type Project

type Project struct {
	ID   string   `db:"id" json:"id"`
	Name string   `db:"name" json:"name"`
	Keys []string `db:"keys" json:"keys"`
}

func (*Project) SanitizeKeys

func (p *Project) SanitizeKeys()

SanitizeKeys removes empty and duplicate keys.

func (*Project) Validate

func (p *Project) Validate() error

Validate returns an error if the project's data is invalid.

type ProjectClient

type ProjectClient struct {
	ClientID  string `db:"client_id" json:"client_id"`
	Name      string `db:"name" json:"name"`
	Secret    string `db:"secret" json:"secret,omitempty"`
	ProjectID string `db:"project_id" json:"project_id"`
}

func (*ProjectClient) Validate

func (p *ProjectClient) Validate() error

Validate returns an error if the project client's data is invalid.

type ProjectClientStorer

type ProjectClientStorer interface {
	FindOneClient(string) (*ProjectClient, error)
	GetProjectClients(string) ([]ProjectClient, error)
	GetProjectClient(projectID, clientID string) (*ProjectClient, error)
	CreateProjectClient(ProjectClient) (*ProjectClient, error)
	UpdateProjectClientSecret(ProjectClient) (*ProjectClient, error)
	UpdateProjectClientName(ProjectClient) (*ProjectClient, error)
	DeleteProjectClient(projectID, clientID string) error
}

ProjectClientStorer is the interface to store project clients.

type ProjectLocaleStorer

type ProjectLocaleStorer interface {
	UpdateLocalePairs(projID string, localeIdent string, pairs map[string]string) (*Locale, error)
	GetProjectLocaleByIdent(projID string, localeIdent string) (*Locale, error)
	GetProjectLocales(projID string, localeIdents ...string) ([]Locale, error)
}

ProjectLocaleStorer is the interface to store project locales.

type ProjectStorer

type ProjectStorer interface {
	GetProject(string) (*Project, error)
	CreateProject(Project) (*Project, error)
	UpdateProject(Project) (*Project, error)
	DeleteProject(string) error
	UpdateProjectName(projectID, name string) (*Project, error)
	AddProjectKey(projectID, key string) (*Project, error)
	UpdateProjectKey(projectID, oldKey, newKey string) (*Project, int, error)
	DeleteProjectKey(projectID, key string) (*Project, error)
}

ProjectStorer is the interface to store projects.

type ProjectUser

type ProjectUser struct {
	User
	ID        string `json:"id,omitempty"` // omit embed field from User
	ProjectID string `db:"project_id" json:"project_id"`
	UserID    string `db:"user_id" json:"user_id"`
	Role      string `db:"role" json:"role"`
}

type ProjectUserStorer

type ProjectUserStorer interface {
	GetProjectUsers(projID string) ([]ProjectUser, error)
	GetUserProjects(userID string) ([]Project, error)
	GetProjectUser(projID, userID string) (*ProjectUser, error)
	AssignProjectUser(ProjectUser) (*ProjectUser, error)
	RevokeProjectUser(ProjectUser) error
	UpdateProjectUser(ProjectUser) (*ProjectUser, error)
	GetUserProjectRoles(projID string) ([]ProjectUser, error)
}

ProjectUserStorer is the interface to store project users.

type User

type User struct {
	ID       string `db:"id" json:"id"`
	Name     string `db:"name" json:"name,omitempty"`
	Email    string `db:"email" json:"email,omitempty"`
	Password string `db:"password" json:"password,omitempty"`
}

func (*User) Normalize

func (u *User) Normalize()

func (*User) Validate

func (u *User) Validate() error

Validate returns an error if the user's data is invalid. It will normalize the user data before validating

type UserStorer

type UserStorer interface {
	GetUserByID(string) (*User, error)
	GetUserByEmail(string) (*User, error)
	CreateUser(User) (*User, error)
	UpdateUserPassword(User) (*User, error)
	UpdateUserName(User) (*User, error)
	UpdateUserEmail(User) (*User, error)
}

UserStorer is the interface to store users.

type Validatable

type Validatable interface {
	Validate() error
}

Validatable specifies the interface to validate structs.

Jump to

Keyboard shortcuts

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