datastore

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package datastore provides an interface and implementations for interacting with a badge datastore.

Index

Constants

View Source
const (
	// ErrBadgeDoesNotExist is returned when the badge requested does not exist in the datastore.
	ErrBadgeDoesNotExist = "the badge requested does not exist"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AirtableBadge

type AirtableBadge struct {
	AirtableID string `json:"id"`
	Fields     Badge  `json:"fields"`
}

AirtableBadge provides a wrapper around the badge model for Airtable requests.

type AirtableBadgeTmp

type AirtableBadgeTmp struct {
	AirtableID string `json:"-"`
	Fields     Badge  `json:"fields"`
}

AirtableBadgeTmp is used to create a badge because the API does not like when AirtableID exists in the POST even though it is empty.

type AirtableDatastore

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

AirtableDatastore is an implementation of the datastore interface for Airtable.

func NewAirTableDataStore

func NewAirTableDataStore(config AirtableDatastoreConfig) (*AirtableDatastore, error)

NewAirTableDatastore provides an initialized datastore for Airtable using the provided configuration.

func (*AirtableDatastore) CreateBadge

func (ds *AirtableDatastore) CreateBadge(id string, badgeType string, enabled bool) error

CreateBadge creates a badge in the Airflow datastore with the provided values.

func (*AirtableDatastore) DeleteBadge

func (ds *AirtableDatastore) DeleteBadge(id string) error

DeleteBadge deletes a badge from the datastore.

func (*AirtableDatastore) DisableBadge

func (ds *AirtableDatastore) DisableBadge(id string) error

DisableBadge disables a badge that exists in the datastore.

func (*AirtableDatastore) EnableBadge

func (ds *AirtableDatastore) EnableBadge(id string) error

EnableBadge enables a badge that exists in the datastore.

func (*AirtableDatastore) GetBadge

func (ds *AirtableDatastore) GetBadge(id string) (*Badge, error)

GetBadge returns a badge with the given ID. If the badge does not exist, ErrBadgeDoesNotExist will be returned.

func (*AirtableDatastore) HasAccess

func (ds *AirtableDatastore) HasAccess(id string) (bool, error)

HasAccess returns true if the badge with the given ID should be given access.

func (*AirtableDatastore) ListBadges

func (ds *AirtableDatastore) ListBadges() ([]Badge, error)

ListBadges returns a list of badges from the datastore.

type AirtableDatastoreConfig

type AirtableDatastoreConfig struct {
	// Key is a valid Airtable API key.
	Key string

	// BaseID is a valid Airtable base id.
	BaseID string
}

AirtableDatastoreConfig is a configuration struct for an Airtable datastore.

type Badge

type Badge struct {
	// ID is the id burned into the RFID badge.
	ID string `json:"id"`

	// Enabled determines if the badge should be considered active.
	Enabled bool `json:"enabled"`

	// Type is the type of badge. E.x. card, sticker, keychain.
	Type string `json:"type"`
}

Badge is a model for a badge in the datastore.

type Datastore

type Datastore interface {
	HasAccess(id string) (bool, error)
	ListBadges() ([]Badge, error)
	CreateBadge(id string, badgeType string, enabled bool) error
	EnableBadge(id string) error
	DisableBadge(id string) error
	DeleteBadge(id string) error
	GetBadge(id string) (*Badge, error)
}

Datastore is an interface for accessing a badge datastore.

type TextFile

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

TextFile implements the datastore interface with a file.

func NewTextFile

func NewTextFile(cfg TextFileConfig) (*TextFile, error)

NewTextFile provides an instantiated datastore.

func (*TextFile) CreateBadge

func (txt *TextFile) CreateBadge(id string, badgeType string, enabled bool) error

func (*TextFile) DeleteBadge

func (txt *TextFile) DeleteBadge(id string) error

func (*TextFile) DisableBadge

func (txt *TextFile) DisableBadge(id string) error

func (*TextFile) EnableBadge

func (txt *TextFile) EnableBadge(id string) error

func (*TextFile) GetBadge

func (txt *TextFile) GetBadge(id string) (*Badge, error)

func (*TextFile) HasAccess

func (txt *TextFile) HasAccess(id string) (bool, error)

func (*TextFile) ListBadges

func (txt *TextFile) ListBadges() ([]Badge, error)

type TextFileConfig

type TextFileConfig struct {
	Path string
}

TextFileConfig is a configuration struct for a a TextFile datastore.

Jump to

Keyboard shortcuts

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