items

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: CC0-1.0 Imports: 12 Imported by: 0

Documentation

Overview

Package items allows for interactions with items in the Library of Congress digital collections.

It provides a Repository interface for generalized interactions storing and retrieving items from a data store, as well as a concrete type that implements that interface for a PostgreSQL database using the pgx package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	ID        string
	URL       sql.NullString
	Title     sql.NullString
	Year      sql.NullInt32
	Date      sql.NullString
	Subjects  []string
	Resources []ItemResource
	Files     []ItemFile
	Languages []string
	API       sql.NullString // The entire API response stored as JSONB
	Updated   time.Time
}

Item is a representation of an item in the LOC digital collections, along with its resources and files.

func (*Item) Fetch

func (i *Item) Fetch(client *http.Client) error

Fetch gets an item's metadata from the LOC.gov API.

func (*Item) Fetched

func (item *Item) Fetched() bool

Fetched reports whether the full metadata has been fetched for an item.

func (*Item) FullText

func (item *Item) FullText() (text []PlainText, has bool)

FullText returns a slice of plain text objects containing the page-level text, cleaned up to be plain text. The boolean return value keeps track of whether there is or isn't text available at this level.

func (Item) String

func (item Item) String() string

String

type ItemFile

type ItemFile struct {
	ItemID          string
	ResourceSeq     int
	FileSeq         int
	FormatSeq       int
	Mimetype        sql.NullString
	FullText        sql.NullString
	FullTextService sql.NullString
	WordCoordinates sql.NullString
	URL             sql.NullString
	Info            sql.NullString
	Use             sql.NullString
}

ItemFile is a file contained within an item. Unlike the LOC.gov API, this model does not make a firm distinction between a file and format.

type ItemResource

type ItemResource struct {
	ItemID       string
	ResourceSeq  int
	FullTextFile sql.NullString
	DJVUTextFile sql.NullString
	Image        sql.NullString
	PDF          sql.NullString
	URL          sql.NullString
	Caption      sql.NullString
}

ItemResource is a resource attached to an item.

type ItemResponse

type ItemResponse struct {
	ItemDetails struct {
		ID       string   `json:"id"`
		URL      string   `json:"url"`
		Date     string   `json:"date"`
		Subjects []string `json:"subject_headings"`
		Title    string   `json:"title"`
		Language []string `json:"language"`
	} `json:"item"`
	Resources []struct {
		FulltextFile string `json:"fulltext_file,omitempty"`
		DJVUTextFile string `json:"djvu_text_file,omitempty"`
		Image        string `json:"image,omitempty"`
		PDF          string `json:"pdf,omitempty"`
		URL          string `json:"url,omitempty"`
		Caption      string `json:"caption,omitempty"`
		Files        [][]struct {
			Mimetype        string `json:"mimetype,omitempty"`
			Fulltext        string `json:"fulltext,omitempty"`
			FulltextService string `json:"fulltext_service,omitempty"`
			WordCoordinates string `json:"word_coordinates,omitempty"`
			URL             string `json:"url,omitempty"`
			Info            string `json:"info,omitempty"`
			Use             string `json:"use,omitempty"`
		} `json:"files"`
	} `json:"resources"`
}

ItemResponse represents an item-level object returned from the API. Many more fields are returned and will be stored in the database as a JSONB field, but these are the ones that will be serialized to regular database fields.

type PlainText

type PlainText struct {
	Text string
}

PlainText is the cleaned up, plain text of part (or all) of an item.

type Repo

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

Repo is a data store using PostgreSQL with the pgx native interface.

func NewItemRepo

func NewItemRepo(db *pgxpool.Pool) *Repo

NewItemRepo returns an item repo using PostgreSQL with the pgx native interface.

func (*Repo) Get

func (r *Repo) Get(ctx context.Context, ID string) (*Item, error)

Get fetches an item from the database by its ID.

func (*Repo) GetAllUnfetched

func (r *Repo) GetAllUnfetched(ctx context.Context) ([]string, error)

GetAllUnfetched gets the IDs of all items which still need to be fetched

func (*Repo) Save

func (r *Repo) Save(ctx context.Context, item *Item) error

Save serializes an item to the database, either creating it in the database or updating the fields.

type Repository

type Repository interface {
	Get(ctx context.Context, ID string) (*Item, error)
	GetAllUnfetched(ctx context.Context) ([]string, error)
	Save(ctx context.Context, item *Item) error
}

Repository is an interface describing a data store for items.

Jump to

Keyboard shortcuts

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