profile

package
v0.0.0-...-2cbf9d5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package profile contains profile related CRUD functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is used when a specific Profile is requested but does not exist.
	ErrNotFound = errors.New("not found")

	// ErrInvalidID occurs when an ID is not in a valid form.
	ErrInvalidID = errors.New("ID is not in its proper form")

	// ErrForbidden occurs when a user tries to do something that is forbidden to them according to our access control policies.
	ErrForbidden = errors.New("attempted action is not allowed")
)

Functions

This section is empty.

Types

type Info

type Info struct {
	Name        string    `db:"name" json:"name"`                 // Unique profile name
	Type        Type      `db:"type" json:"type"`                 // Profile type
	DisplayName string    `db:"display_name" json:"display_name"` // Display name of the profile.
	UserID      string    `db:"user_id" json:"user_id"`           // ID of the user who created the profile.
	DateCreated time.Time `db:"date_created" json:"date_created"` // When the profile was added.
	DateUpdated time.Time `db:"date_updated" json:"date_updated"` // When the profile record was last modified.
}

Info represents an individual profile.

type NewProfile

type NewProfile struct {
	Name        string `json:"name" validate:"required"`
	Type        string `json:"type" validate:"required"`
	DisplayName string `json:"display_name" validate:"required"`
}

NewProfile is what we require from clients when adding a Profile.

type Profile

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

Profile manages the set of API's for profile access.

func New

func New(log *log.Logger, db *sqlx.DB) Profile

New constructs a Profile for api access.

func (Profile) Create

func (p Profile) Create(ctx context.Context, traceID string, claims auth.Claims, np NewProfile, now time.Time) (Info, error)

Create adds a Profile to the database. It returns the created Profile with fields like ID and DateCreated populated.

func (Profile) Delete

func (p Profile) Delete(ctx context.Context, traceID string, name string) error

Delete removes the profile identified by a given ID.

func (Profile) Query

func (p Profile) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)

Query gets all Profiles from the database.

func (Profile) QueryByName

func (p Profile) QueryByName(ctx context.Context, traceID string, name string) (Info, error)

QueryByName finds the profile identified by a given name.

func (Profile) QueryUserProfile

func (p Profile) QueryUserProfile(ctx context.Context, traceID string, userID string) (Info, error)

QueryUserProfile finds the profile identified by a given user ID.

func (Profile) Update

func (p Profile) Update(ctx context.Context, traceID string, claims auth.Claims, name string, up UpdateProfile, now time.Time) error

Update modifies data about a Profile. It will error if the specified name is invalid or does not reference an existing Profile.

type Type

type Type string

Type represents a particular type of profile.

var (
	// UserProfile represents profiles for users.
	UserProfile Type = "USR"

	// BusinessProfile represents profiles for businesses.
	BusinessProfile Type = "BUS"

	// ServiceProviderProfile represents profiles for service providers.
	ServiceProviderProfile Type = "SER"
)

func TypeFromString

func TypeFromString(s string) (*Type, error)

TypeFromString returns a pointer to type from the provided string or an error when an invalid type string is provided.

func (*Type) String

func (t *Type) String() string

String implementes the Stringer interface.

type UpdateProfile

type UpdateProfile struct {
	Name        *string `json:"name"`
	DisplayName *string `json:"display_name"`
}

UpdateProfile defines what information may be provided to modify an existing Profile. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exceptions around marshalling/unmarshalling.

Jump to

Keyboard shortcuts

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