app

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Name       = "pingcrm-echo"
	Version    = "dev"     // It will be overwritten by the build script
	CommitHash = "unknown" // It will be overwritten by the build script
)

Functions

func AuthCreateHandler

func AuthCreateHandler(c echo.Context) error

func AuthDestroyHandler

func AuthDestroyHandler(c echo.Context) error

func AuthRequired

func AuthRequired() echo.MiddlewareFunc

func AuthStoreHandler

func AuthStoreHandler(c echo.Context) error

func ContactsCreateHandler

func ContactsCreateHandler(c echo.Context) error

func ContactsDestroyHandler

func ContactsDestroyHandler(c echo.Context) error

func ContactsEditHandler

func ContactsEditHandler(c echo.Context) error

func ContactsIndexHandler

func ContactsIndexHandler(c echo.Context) error

func ContactsRestoreHandler

func ContactsRestoreHandler(c echo.Context) error

func ContactsStoreHandler

func ContactsStoreHandler(c echo.Context) error

func ContactsUpdateHandler

func ContactsUpdateHandler(c echo.Context) error

func CreateContact

func CreateContact(ctx context.Context, db *DB, contact *Contact) error

func CreateOrganization

func CreateOrganization(ctx context.Context, db *DB, org *Organization) error

func CreateUser

func CreateUser(ctx context.Context, db *DB, user *User) error

func DashboardIndexHandler

func DashboardIndexHandler(c echo.Context) error

func ErrorHandler

func ErrorHandler(err error, c echo.Context)

func ImagesShowHandler

func ImagesShowHandler(c echo.Context) error

func IsErrNoRows

func IsErrNoRows(err error) bool

func LoadContactWithOrganization

func LoadContactWithOrganization(ctx context.Context, db *DB, contacts ...*Contact) error

func LoadOrganizationWithContacts

func LoadOrganizationWithContacts(ctx context.Context, db *DB, orgs ...*Organization) error

func LoadUserWithAccount

func LoadUserWithAccount(ctx context.Context, db *DB, user *User) error

func OrganizationsCreateHandler

func OrganizationsCreateHandler(c echo.Context) error

func OrganizationsDestroyHandler

func OrganizationsDestroyHandler(c echo.Context) error

func OrganizationsEditHandler

func OrganizationsEditHandler(c echo.Context) error

func OrganizationsIndexHandler

func OrganizationsIndexHandler(c echo.Context) error

func OrganizationsRestoreHandler

func OrganizationsRestoreHandler(c echo.Context) error

func OrganizationsStoreHandler

func OrganizationsStoreHandler(c echo.Context) error

func OrganizationsUpdateHandler

func OrganizationsUpdateHandler(c echo.Context) error

func ParamInt64

func ParamInt64(c echo.Context, name string, defaultVal ...int64) int64

func RedirectIfAuthenticated

func RedirectIfAuthenticated() echo.MiddlewareFunc

func ReportsIndexHandler

func ReportsIndexHandler(c echo.Context) error

func RestoreContact

func RestoreContact(ctx context.Context, db *DB, id int64) error

func RestoreOrganization

func RestoreOrganization(ctx context.Context, db *DB, id int64) error

func RestoreUser

func RestoreUser(ctx context.Context, db *DB, id int64) error

func SessionMiddleware

func SessionMiddleware(secret []byte) echo.MiddlewareFunc

func SoftDeleteContact

func SoftDeleteContact(ctx context.Context, db *DB, id int64) error

func SoftDeleteOrganization

func SoftDeleteOrganization(ctx context.Context, db *DB, id int64) error

func SoftDeleteUser

func SoftDeleteUser(ctx context.Context, db *DB, id int64) error

func UpdateContact

func UpdateContact(ctx context.Context, db *DB, contact *Contact) error

func UpdateOrganization

func UpdateOrganization(ctx context.Context, db *DB, org *Organization) error

func UpdateUser

func UpdateUser(ctx context.Context, db *DB, user *User) error

func UsersCreateHandler

func UsersCreateHandler(c echo.Context) error

func UsersDestroyHandler

func UsersDestroyHandler(c echo.Context) error

func UsersEditHandler

func UsersEditHandler(c echo.Context) error

func UsersIndexHandler

func UsersIndexHandler(c echo.Context) error

func UsersRestoreHandler

func UsersRestoreHandler(c echo.Context) error

func UsersStoreHandler

func UsersStoreHandler(c echo.Context) error

func UsersUpdateHandler

func UsersUpdateHandler(c echo.Context) error

Types

type Account

type Account struct {
	Id        int64      `db:"id"`
	Name      string     `db:"name"`
	CreatedAt time.Time  `db:"created_at"`
	UpdatedAt time.Time  `db:"updated_at"`
	DeleteAt  *time.Time `db:"deleted_at"`
}

func GetAccountByBuilder

func GetAccountByBuilder(ctx context.Context, db *DB, builder QueryBuilder) (*Account, error)

func GetAccountById

func GetAccountById(ctx context.Context, db *DB, id int64) (*Account, error)

type App

type App struct {
	Echo   *echo.Echo
	Config *Config
	DB     *DB
}

func NewApp

func NewApp(c *Config) (*App, error)

func (*App) Close

func (a *App) Close()

func (*App) Start

func (a *App) Start() error

type Config

type Config struct {
	Addr       string
	IsDev      bool
	IsDemo     bool
	Secret     []byte
	DataDir    string
	PublicFs   embed.FS
	ViewsFs    embed.FS
	DatabaseFs embed.FS
}

func NewConfig

func NewConfig() *Config

func (*Config) DatabasePath

func (c *Config) DatabasePath() string

func (*Config) GetViteManifest

func (c *Config) GetViteManifest() inertia.ViteManifest

func (*Config) SchemaDDL

func (c *Config) SchemaDDL() string

type Contact

type Contact struct {
	Id             int64         `db:"id"`
	AccountId      int64         `db:"account_id"`
	OrganizationId *int64        `db:"organization_id"`
	FirstName      string        `db:"first_name"`
	LastName       string        `db:"last_name"`
	Email          *string       `db:"email"`
	Phone          *string       `db:"phone"`
	Address        *string       `db:"address"`
	City           *string       `db:"city"`
	Region         *string       `db:"region"`
	Country        *string       `db:"country"`
	PostalCode     *string       `db:"postal_code"`
	CreatedAt      time.Time     `db:"created_at"`
	UpdatedAt      time.Time     `db:"updated_at"`
	DeletedAt      *time.Time    `db:"deleted_at"`
	Organization   *Organization `db:"-"`
}

func GetContactByBuilder

func GetContactByBuilder(ctx context.Context, db *DB, builder QueryBuilder) (*Contact, error)

func GetContactById

func GetContactById(ctx context.Context, db *DB, id int64) (*Contact, error)

func NewContact

func NewContact() *Contact

func (*Contact) Name

func (c *Contact) Name() string

func (*Contact) ToMap

func (c *Contact) ToMap(keys ...string) map[string]interface{}

type ContactFilters

type ContactFilters struct {
	Search    string `json:"search" query:"search"`
	Trashed   string `json:"trashed" query:"trashed"`
	AccountId int64  `json:"-" query:"-"`
}

type ContactList

type ContactList []*Contact

func ListContactsByBuilder

func ListContactsByBuilder(ctx context.Context, db *DB, builder QueryBuilder) (ContactList, error)

func PaginateContactsByFilters

func PaginateContactsByFilters(ctx context.Context, db *DB, p *pagination.Factory, filter *ContactFilters) (*pagination.Paginator, ContactList, error)

func (ContactList) ByIds

func (l ContactList) ByIds() map[int64]*Contact

func (ContactList) ByOrganizationIds

func (l ContactList) ByOrganizationIds() map[int64]ContactList

func (ContactList) Ids

func (l ContactList) Ids() []int64

func (ContactList) OrganizationIds

func (l ContactList) OrganizationIds() []int64

func (ContactList) ToMap

func (l ContactList) ToMap(keys ...string) []map[string]interface{}

type DB

type DB struct {
	*sqlx.DB
	// Path is a sqlite3 database file path.
	Path string
}

DB is a database client. It supports only sqlite3.

func NewDB

func NewDB(dbPath string) (*DB, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) CountContextByBuilder

func (db *DB) CountContextByBuilder(ctx context.Context, builder QueryBuilder) (uint64, error)

func (*DB) ExecContextByBuilder

func (db *DB) ExecContextByBuilder(ctx context.Context, builder QueryBuilder) (sql.Result, error)

func (*DB) GetContextByBuilder

func (db *DB) GetContextByBuilder(ctx context.Context, dest interface{}, builder QueryBuilder) error

func (*DB) Init

func (db *DB) Init(databaseFs embed.FS) error

func (*DB) IsNotExist

func (db *DB) IsNotExist() bool

func (*DB) SelectContextByBuilder

func (db *DB) SelectContextByBuilder(ctx context.Context, dest interface{}, builder QueryBuilder) error

type FlashMessage

type FlashMessage struct {
	Success string
	Error   string
}

type Organization

type Organization struct {
	Id         int64       `db:"id"`
	AccountId  int64       `db:"account_id"`
	Name       string      `db:"name"`
	Email      *string     `db:"email"`
	Phone      *string     `db:"phone"`
	Address    *string     `db:"address"`
	City       *string     `db:"city"`
	Region     *string     `db:"region"`
	Country    *string     `db:"country"`
	PostalCode *string     `db:"postal_code"`
	CreatedAt  time.Time   `db:"created_at"`
	UpdatedAt  time.Time   `db:"updated_at"`
	DeletedAt  *time.Time  `db:"deleted_at"`
	Contacts   ContactList `db:"-"`
}

func GetOrganizationByBuilder

func GetOrganizationByBuilder(ctx context.Context, db *DB, builder QueryBuilder) (*Organization, error)

func GetOrganizationById

func GetOrganizationById(ctx context.Context, db *DB, id int64) (*Organization, error)

func NewOrganization

func NewOrganization() *Organization

func (*Organization) ToMap

func (o *Organization) ToMap(keys ...string) map[string]interface{}

type OrganizationFilters

type OrganizationFilters struct {
	Search    string `json:"search" query:"search"`
	Trashed   string `json:"trashed" query:"trashed"`
	AccountId int64  `json:"-" query:"-"`
}

type OrganizationList

type OrganizationList []*Organization

func ListOrganizationsByAccountId

func ListOrganizationsByAccountId(ctx context.Context, db *DB, accountId int64) (OrganizationList, error)

func ListOrganizationsByBuilder

func ListOrganizationsByBuilder(ctx context.Context, db *DB, builder QueryBuilder) (OrganizationList, error)

func (OrganizationList) ByIds

func (l OrganizationList) ByIds() map[int64]*Organization

func (OrganizationList) Ids

func (l OrganizationList) Ids() []int64

func (OrganizationList) ToMap

func (l OrganizationList) ToMap(keys ...string) []map[string]interface{}

type QueryBuilder

type QueryBuilder interface {
	ToSql() (string, []interface{}, error)
}

type SessionWrapper

type SessionWrapper struct {
	// contains filtered or unexported fields
}

func NewSessionWrapper

func NewSessionWrapper(c echo.Context) (*SessionWrapper, error)

func (*SessionWrapper) Errors

func (s *SessionWrapper) Errors() (map[string]string, error)

func (*SessionWrapper) Flash

func (s *SessionWrapper) Flash() (*FlashMessage, error)

func (*SessionWrapper) LoginWithUserId

func (s *SessionWrapper) LoginWithUserId(id int64) error

func (*SessionWrapper) Logout

func (s *SessionWrapper) Logout() error

func (*SessionWrapper) Set

func (s *SessionWrapper) Set(key string, value interface{}) error

func (*SessionWrapper) SetErrors

func (s *SessionWrapper) SetErrors(errs map[string]string) error

func (*SessionWrapper) SetFlashError

func (s *SessionWrapper) SetFlashError(msg string) error

func (*SessionWrapper) SetFlashSuccess

func (s *SessionWrapper) SetFlashSuccess(msg string) error

func (*SessionWrapper) User

func (s *SessionWrapper) User() (*User, error)

func (*SessionWrapper) UserId

func (s *SessionWrapper) UserId() (int64, error)

type User

type User struct {
	Id              int64      `db:"id"`
	AccountId       int64      `db:"account_id"`
	FirstName       string     `db:"first_name"`
	LastName        string     `db:"last_name"`
	Email           string     `db:"email"`
	EmailVerifiedAt *time.Time `db:"email_verified_at"`
	Password        string     `db:"password"`
	Owner           bool       `db:"owner"`
	PhotoPath       *string    `db:"photo_path"`
	RememberToken   string     `db:"remember_token"`
	CreatedAt       time.Time  `db:"created_at"`
	UpdatedAt       time.Time  `db:"updated_at"`
	DeletedAt       *time.Time `db:"deleted_at"`
	Account         *Account   `db:"-"`
}

func GetUserByBuilder

func GetUserByBuilder(ctx context.Context, db *DB, builder QueryBuilder) (*User, error)

func GetUserByEmail

func GetUserByEmail(ctx context.Context, db *DB, email string) (*User, error)

func GetUserById

func GetUserById(ctx context.Context, db *DB, id int64) (*User, error)

func NewUser

func NewUser() *User

func (*User) IsDemoUser

func (u *User) IsDemoUser() bool

func (*User) Name

func (u *User) Name() string

func (*User) SetPlainPassword

func (u *User) SetPlainPassword(plain string)

func (*User) ToMap

func (u *User) ToMap(keys ...string) map[string]interface{}

func (*User) VerifyPassword

func (u *User) VerifyPassword(plain string) bool

type UserFilters

type UserFilters struct {
	Search    string `json:"search" query:"search"`
	Role      string `json:"role" query:"role"`
	Trashed   string `json:"trashed" query:"trashed"`
	AccountId int64  `json:"-" query:"-"`
}

type UserList

type UserList []*User

func ListUsersByBuilder

func ListUsersByBuilder(ctx context.Context, db *DB, builder QueryBuilder) (UserList, error)

func ListUsersByFilters

func ListUsersByFilters(ctx context.Context, db *DB, filter *UserFilters) (UserList, error)

func (UserList) Ids

func (l UserList) Ids() []int64

func (UserList) ToMap

func (l UserList) ToMap(keys ...string) []map[string]interface{}

type ValidationErrors

type ValidationErrors map[string]string

func (ValidationErrors) Set

func (v ValidationErrors) Set(key, message string) ValidationErrors

type Validator added in v0.2.0

type Validator struct {
	*validation.Validator
}

func NewValidator added in v0.2.0

func NewValidator() *Validator

func (*Validator) ErrorMessageMap added in v0.2.0

func (v *Validator) ErrorMessageMap() map[string]string

Jump to

Keyboard shortcuts

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