model

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package model contains the models used by exlibris. Each model lives in its own file and should be initialized in main.go so that migrations run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APObject

type APObject struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `sql:"index"`
	ID        string     `gorm:"primary key"`
	UserID    string     `gorm:"not null"`
	ReadID    uint       `gorm:"not null"`
}

An APObject is an ActivityPub object (Read, Like, etc).

type Author

type Author struct {
	Created time.Time
	Updated time.Time
	Deleted time.Time
	ID      string `gorm:"primary_key" json:"id"`
	Name    string `json:"name"`
}

An Author is someone who has written a Book.

func (*Author) ToType

func (a *Author) ToType() vocab.Type

ToType returns a representation of an author as an ActivityPub object.

type Book

type Book struct {
	ID        string   `gorm:"primary_key" json:"id"`
	Title     string   `gorm:"not null;index" json:"title"`
	Published int      `json:"published,omitempty"`
	ISBN      string   `json:"isbn,omitempty"`
	Authors   []Author `gorm:"-"`
	// contains filtered or unexported fields
}

A Book is something that can be read. Currently this only supports things which are in the Library of Congress API, but eventually it'd be great to support fanfiction and other online-only sources.

func NewBook

func NewBook(id string, title string, published int, isbn string) *Book

NewBook returns a new instance of a book

func (*Book) ToType

func (b *Book) ToType() vocab.Type

ToType returns a representation of a book as an ActivityPub object.

type BookAuthor

type BookAuthor struct {
	gorm.Model
	FKBook   int
	FKAuthor int
}

BookAuthor is a many to many model describing the authors for books

type BookSubject

type BookSubject struct {
	gorm.Model
	BookFK    int
	SubjectFK int
}

BookSubject for a book

type ContextKey

type ContextKey string

A ContextKey is a key used to represent a model in a context

const (
	// ContextKeyRequestedUser  is the key to use for the username of the endpoint being requested.
	ContextKeyRequestedUser ContextKey = "username"

	// ContextKeyAuthenticatedUser is the key to use for a User object that was retrieved from a JWT. It should not be set until the JWT has been verified as being signed by the user specified in the `kid` field.
	ContextKeyAuthenticatedUser ContextKey = "authuser"

	// ContextKeyJWT is the key to use for a User's JWT in a context
	ContextKeyJWT ContextKey = "jwt"
)
const (
	// ContextKeyRead is the context key to use for the read action
	ContextKeyRead ContextKey = "read"
)

type Federater

type Federater interface {
	ToType() vocab.Type
}

A Federater is a representation of a model as an ActivityPub object.

type OutboxEntry

type OutboxEntry struct {
	CreatedAt  time.Time
	UserID     string `gorm:"primary_key"`
	Serialized string `gorm:"primary_key"`
}

An OutboxEntry represents an entry in a user's AP outbox.

type Read

type Read struct {
	gormuuid.UUID
	Created time.Time
	Updated time.Time
	Deleted time.Time
	BookID  string `gorm:"not null"`
	Book    *Book  `gorm:"-"`
	UserID  string `gorm:"not null"`
	User    *User  `gorm:"-"`
}

Read is a many to many model describing a user who read a book. Because GORM does weird things with foreign keys we need to do it manually, unfortunately.

func (*Read) ToType

func (r *Read) ToType() vocab.Type

ToType returns a representation of a read activity as an ActivityPub object.

type Review

type Review struct {
	gorm.Model
	FKBook int
	FKUser int
	Text   string
}

Review models a book review

type Subject

type Subject struct {
	gorm.Model
	Subject string
}

Subject for a book

type User

type User struct {
	CreatedAt        time.Time
	UpdatedAt        time.Time
	DeletedAt        *time.Time `sql:"index"`
	ID               string     `gorm:"primary_key"`
	Username         string     `gorm:"unique;not null;index"`
	DisplayName      string     `gorm:"not null"`
	Email            string     `gorm:"not null"`
	Password         []byte     `json:"-"`
	PrivateKey       []byte     `json:"-"`
	Summary          string
	CryptoPrivateKey crypto.PrivateKey `gorm:"-"`
	Local            bool              `json:"-"`
}

A User is a person interacting with the app. They may not be registered on this server.

func NewUser

func NewUser(username, password, email, displayName string) (*User, error)

NewUser creates a user and handles generating the ID, key and hashed password.

func (*User) GenerateJWT

func (u *User) GenerateJWT() (string, error)

GenerateJWT generates a JWT for the user.

func (*User) GenerateKeys

func (u *User) GenerateKeys() error

GenerateKeys is used on user registration to generate a private key for a user. It can theoretically be used to invalidate all existing tokens/sessions.

func (*User) IRI

func (u *User) IRI() *url.URL

IRI returns a url representing the user's profile

func (*User) InboxIRI

func (u *User) InboxIRI() *url.URL

InboxIRI returns a url representing the user's inbox

func (*User) IsPassword

func (u *User) IsPassword(password string) bool

IsPassword verifies that the specified password matches what's in the database.

func (*User) OutboxIRI

func (u *User) OutboxIRI() *url.URL

OutboxIRI returns a url representing the user's outbox

func (*User) SetPassword

func (u *User) SetPassword(password string)

SetPassword is used to hash the password the user wishes to use.

func (*User) ToType

func (u *User) ToType() vocab.Type

ToType returns a representation of a user as an ActivityPub object.

func (*User) ValidateJWT

func (u *User) ValidateJWT(t string) bool

ValidateJWT accepts a JWT and private key and verifies the token was signed by the key.

Jump to

Keyboard shortcuts

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