core

package
v0.0.0-...-d215556 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package core provides the core domain modules and service interfaces for the Apollo library.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEmailAddress = errors.New("invalid e-mail address")
	ErrEmailAddressEmpty   = errors.New("e-mail address is empty")
)
View Source
var (
	ErrUserDoesNotExist         = errors.New("user does not exist")
	ErrOrganisationDoesNotExist = errors.New("organisation does not exist")
	ErrNoActiveOrganisation     = errors.New("user has not chosen an organisation")
	ErrNotFound                 = errors.New("not found")
	ErrUnauthenticated          = errors.New("authentication required")
	ErrForbidden                = errors.New("user is not authorized")
	ErrConflict                 = errors.New("conflict")
)
View Source
var (
	SupportedCountryIso2Codes = []string{"BE"}
	ErrVatCountryNotSupported = errors.New("VAT numbers for this country are not supported (yet)")
	ErrVatInvalidCode         = errors.New("The VAT number doesn't start with a valid code")
)

Functions

This section is empty.

Types

type Address

type Address struct {
	ID         AddressID
	Street     string
	Number     string
	PostalCode string
	City       string
	Country    string
	ExtraLine  *string
}

type AddressID

type AddressID = ID

type AddressService

type AddressService interface {
	// Creates an Address from an Address struct, the ID field of the struct gets ignored here
	CreateAddress(ctx context.Context, address Address) (*Address, error)
	GetAddress(ctx context.Context, addressID AddressID) (*Address, error)
	DeleteAddress(ctx context.Context, addressID AddressID) error
	UpdateAddress(ctx context.Context, addressID AddressID, update AddressUpdateData) (*Address, error)
	ListAddresses(ctx context.Context) ([]Address, error)
}

type AddressUpdateData

type AddressUpdateData struct {
	Street     *string
	Number     *string
	PostalCode *string
	City       *string
	Country    *string
	ExtraLine  *string
}

type EmailAddress

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

func ParseEmailAddress

func ParseEmailAddress(address string) (*EmailAddress, error)

ParseEmailAddress parses an e-mail address from any string. This uses RFC-5322 to determine valid e-mail addresses, e.g. "Biggie Smalls <notorious@example.com>"

func (*EmailAddress) String

func (email *EmailAddress) String() string

func (*EmailAddress) UnmarshalText

func (email *EmailAddress) UnmarshalText(text []byte) error

type EmailService

type EmailService interface {
	// SendEmail will build and send a basic e-mail message containing both a HTML template version
	// (optional) as well as a plaintext alternative (required).
	SendEmail(
		ctx context.Context,
		address EmailAddress,
		subject string,
		template *templ.Component,
		plaintextMessage string,
	) error

	// SendNotification will send a specific plain-text notification to the configured notification
	// address.
	SendNotification(
		ctx context.Context,
		subject string,
		message string,
		args ...any,
	) error

	// SendRawMessage will send a raw gomail message using the existing configuration.
	SendRawMessage(ctx context.Context, message *gomail.Message) error
}

type ID

type ID int32

func ParseID

func ParseID(id string) (ID, error)

ParseID parses a string into an ID.

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(text []byte) error

type Organisation

type Organisation struct {
	ID       OrganisationID
	Name     string
	ParentID *OrganisationID
}

func ParseOrganisation

func ParseOrganisation(id int32, name string, parentID *int32) (*Organisation, error)

type OrganisationID

type OrganisationID = ID

type OrganisationService

type OrganisationService interface {
	// Create a new organisation with the specified data.
	CreateOrganisation(ctx context.Context, name string, parentID *OrganisationID) (*Organisation, error)
	// Retrieve the organisation with the specified id or ErrOrganisationDoesNotExist if no such organisation exists.
	GetOrganisation(ctx context.Context, id OrganisationID) (*Organisation, error)
	// Update an existing organisation and return the result.
	UpdateOrganisation(ctx context.Context, id OrganisationID, name string) (*Organisation, error)
	// Retrieve all existing organisations.
	ListOrganisations(ctx context.Context) ([]Organisation, error)
	// Retrieve the amount of existing organisations.
	GetAmountOfOrganisations(ctx context.Context) (uint64, error)
	// Delete the organisation with the specified id or ErrOrganisationDoesNotExist if no such organisation exists.
	DeleteOrganisation(ctx context.Context, id OrganisationID) error
	// List the organisations a user belongs to or ErrUserDoesNotExist if no such user exists
	ListOrganisationsForUser(ctx context.Context, id UserID) ([]Organisation, error)
	// List the users that belong to an organisation or ErrOrganisationDoesNotExist if no such organisation exists
	ListUsersInOrganisation(ctx context.Context, id OrganisationID) ([]User, error)
	// Return a User for the given organisation and email or ErrNotFound if no such member exisits
	GetMemberByEmail(ctx context.Context, OrgID OrganisationID, email EmailAddress) (*User, error)
	// Add user to an existing organisation
	AddUser(ctx context.Context, UserID UserID, OrgID OrganisationID) error
	// Remove user from an organisation
	RemoveUser(ctx context.Context, UserID UserID, OrgID OrganisationID) error
}

type User

type User struct {
	ID     UserID
	Name   string
	Email  EmailAddress
	Admin  bool
	Lang   string
	Joined time.Time
}

type UserID

type UserID = ID

type UserService

type UserService interface {
	// Create a new user with the specified data.
	CreateUser(ctx context.Context, name string, email EmailAddress, lang string) (*User, error)
	// Retrieve the user with the specified id or ErrUserDoesNotExist if no such user exists.
	GetUser(ctx context.Context, id UserID) (*User, error)
	// Retrieve all existing users.
	ListUsers(ctx context.Context) ([]User, error)
	// Retrieve the amount of existing users.
	GetAmountOfUsers(ctx context.Context) (uint64, error)
	// Delete the user with the specified id or ErrUserDoesNotExist if no such user exists.
	DeleteUser(ctx context.Context, id UserID) error
	// Update the user's admin state to the specified state.
	UpdateUserAdmin(ctx context.Context, id UserID, admin bool) error
	// Update the user with the specified data.
	UpdateUser(ctx context.Context, id UserID, data UserUpdate) (*User, error)
}

type UserUpdate

type UserUpdate struct {
	Name  *string
	Email *string
	Lang  *string
}

type VatNumber

type VatNumber interface {
	// String returns the string representation for this vat number
	String() string
	// Display returns a formatted string representation for this vat number
	Display() string
}

func NewVatNumber

func NewVatNumber(vat string) (VatNumber, error)

NewVatNumber parses a vat number from any string.

Jump to

Keyboard shortcuts

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