document

package
v0.0.0-...-c32710b Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeDeleteDocumentByIDEndpoint

func MakeDeleteDocumentByIDEndpoint(s Service) endpoint.Endpoint

MakeDeleteDocumentByIDEndpoint returns an endpoint to delete a document by ID

func MakeGetDocumentByIDEndpoint

func MakeGetDocumentByIDEndpoint(s Service) endpoint.Endpoint

MakeGetDocumentByIDEndpoint returns an endpoint to get a document by ID

func MakeSaveDocumentEnpoint

func MakeSaveDocumentEnpoint(s Service) endpoint.Endpoint

MakeSaveDocumentEnpoint returns an endpoint to save a document

func MakeSearchDocumentsEndpoint

func MakeSearchDocumentsEndpoint(s Service) endpoint.Endpoint

MakeSearchDocumentsEndpoint returns an endpoint to search for documents

func MakeSearchListEndpoint

func MakeSearchListEndpoint(s Service) endpoint.Endpoint

MakeSearchListEndpoint returns an endpoint to search for lists {Tags, Senders}

Types

type ActionResult

type ActionResult string

ActionResult is a code specifying a specific outcome/result swagger:enum ActionResult

const (
	// None is the default result
	None ActionResult = "none"
	// Saved indicates that an item was saved
	Saved ActionResult = "saved"
	// Deleted indicates that an item was deleted
	Deleted ActionResult = "deleted"
	// Error indicates any error
	Error = 99
)

type DeleteDocumentByIDRequest

type DeleteDocumentByIDRequest struct {
	ID string
}

DeleteDocumentByIDRequest holds an ID to delete a document

type DeleteDocumentByIDResponse

type DeleteDocumentByIDResponse struct {
	Err error  `json:"err,omitempty"`
	ID  string `json:"id,omitempty"`
}

DeleteDocumentByIDResponse is the response object of a delete operation

func (DeleteDocumentByIDResponse) Failed

func (r DeleteDocumentByIDResponse) Failed() error

Failed implements endpoint.Failer.

type DocEntity

type DocEntity struct {
	ID            string         `db:"id"`
	Title         string         `db:"title"`
	FileName      string         `db:"filename"`
	AltID         string         `db:"alternativeid"`
	PreviewLink   sql.NullString `db:"previewlink"`
	Amount        float32        `db:"amount"`
	Created       time.Time      `db:"created"`
	Modified      sql.NullTime   `db:"modified"`
	TagList       string         `db:"taglist"`
	SenderList    string         `db:"senderlist"`
	InvoiceNumber sql.NullString `db:"invoicenumber"`
}

DocEntity represents a record in the persistence store

type DocSearch

type DocSearch struct {
	Title  string
	Tag    string
	Sender string
	From   time.Time
	Until  time.Time
	Limit  int
	Skip   int
}

DocSearch is used to search for documents

type Document

type Document struct {
	ID            string   `json:"id"`
	Title         string   `json:"title"`
	AltID         string   `json:"alternativeId"`
	Amount        float32  `json:"amount"`
	Created       string   `json:"created"`
	Modified      string   `json:"modified,omitempty"`
	FileName      string   `json:"fileName"`
	PreviewLink   string   `json:"previewLink,omitempty"`
	UploadToken   string   `json:"uploadFileToken,omitempty"`
	Tags          []string `json:"tags"`
	Senders       []string `json:"senders"`
	InvoiceNumber string   `json:"invoiceNumber,omitempty"`
}

Document represents a document entity swagger:model

func (Document) String

func (d Document) String() string

type GetDocumentByIDRequest

type GetDocumentByIDRequest struct {
	ID string
}

GetDocumentByIDRequest combines the necessary parameters for a document request

type GetDocumentByIDResponse

type GetDocumentByIDResponse struct {
	Err      error    `json:"err,omitempty"`
	Document Document `json:"document,omitempty"`
}

GetDocumentByIDResponse is the document response object

func (GetDocumentByIDResponse) Failed

func (r GetDocumentByIDResponse) Failed() error

Failed implements endpoint.Failer.

type IDResult

type IDResult struct {
	Result
	ID string `json:"id,omitempty"`
}

IDResult is a generic result which returns an ID swagger:model

type ListType

type ListType string

ListType identifies a list

const (
	// Tags is a listtype holding tag-like entries
	Tags ListType = "Tags"
	// Senders is a listtype for email-like senders
	Senders ListType = "Senders"
)

type OrderBy

type OrderBy struct {
	Field string
	Order SortDirection
}

OrderBy is used to sort a result list

type PagedDocResult

type PagedDocResult struct {
	Documents []DocEntity
	Count     int
}

PagedDocResult wraps a list of documents and returns the total number of documents

type PagedDocument

type PagedDocument struct {
	Documents    []Document `json:"documents"`
	TotalEntries int        `json:"totalEntries"`
}

PagedDocument represents a paged result swagger:model

type Repository

type Repository interface {
	shared.BaseRepository
	Get(id string) (d DocEntity, err error)
	Exists(id string, a persistence.Atomic) (filePath string, err error)
	Save(doc DocEntity, a persistence.Atomic) (d DocEntity, err error)
	Delete(id string, a persistence.Atomic) (err error)
	Search(s DocSearch, order []OrderBy) (PagedDocResult, error)
	SearchLists(s string, st SearchType) ([]string, error)
}

Repository is the CRUD interface for documents in the persistence store

func NewRepository

func NewRepository(c persistence.Connection) (Repository, error)

NewRepository creates a new instance using an existing connection

type Result

type Result struct {
	Message      string       `json:"message"`
	ActionResult ActionResult `json:"result"`
}

Result is a generic result object swagger:model

type SaveDocumentRequest

type SaveDocumentRequest struct {
	Document Document
	User     security.User
}

SaveDocumentRequest holds a document which is either created or updated

type SaveDocumentResponse

type SaveDocumentResponse struct {
	Err error  `json:"err,omitempty"`
	ID  string `json:"id,omitempty"`
}

SaveDocumentResponse returns the document if the request was successfull

func (SaveDocumentResponse) Failed

func (r SaveDocumentResponse) Failed() error

Failed implements endpoint.Failer.

type SearchDocumentsRequest

type SearchDocumentsRequest struct {
	// Title of the document, search for parts of the field
	Title string
	// Tag of a document, search for parts of the field
	Tag string
	// Sender of a document, search for parts of the field
	Sender string
	// From timestamp to search
	From time.Time
	// Until timestamp to search
	Until time.Time
	// Limit defines the max number of entries to return
	Limit int
	// Skip is used for paged-requests, skip #num entries
	Skip int
}

SearchDocumentsRequest holds parameters to get a filtered list of documents

type SearchDocumentsResponse

type SearchDocumentsResponse struct {
	Err    error         `json:"err,omitempty"`
	Result PagedDocument `json:"result"`
}

SearchDocumentsResponse is the response of a search-request

func (SearchDocumentsResponse) Failed

func (r SearchDocumentsResponse) Failed() error

Failed implements endpoint.Failer.

type SearchListRequest

type SearchListRequest struct {
	Name       string
	SearchType ListType
}

SearchListRequest searches the given name for a type of list {Tags, Senders}

type SearchListResponse

type SearchListResponse struct {
	Err     error    `json:"err,omitempty"`
	Entries []string `json:"entries,omitempty"`
}

SearchListResponse holds the result of the SearchListRequest or an error

func (SearchListResponse) Failed

func (r SearchListResponse) Failed() error

Failed implements endpoint.Failer.

type SearchType

type SearchType uint

SearchType is used to determine if the search is performend on tags or senders

const (
	// TAGS is used to search tags within the documents table
	TAGS SearchType = iota
	// SENDERS is used to search senders within the documents table
	SENDERS
)

func (SearchType) String

func (s SearchType) String() string

type Service

type Service interface {
	// GetDocumentByID returns a document object specified by the given id
	GetDocumentByID(id string) (d Document, err error)
	// DeleteDocumentByID deletes a document specified by the given id
	DeleteDocumentByID(id string) (err error)
	// SearchDocuments performs a search and returns paginated results
	SearchDocuments(title, tag, sender string, from, until time.Time, limit, skip int) (p PagedDocument, err error)
	// SearchList searches for senders or tags
	SearchList(name string, st SearchType) (l []string, err error)
	// SaveDocument receives a document and stores it
	// either creation a new document or updating an existing
	SaveDocument(doc Document, user security.User) (d Document, err error)
}

Service defines the methods of the document logic

func NewService

func NewService(logger logging.Logger, repo Repository, fileSvc filestore.FileService, uploadClient upload.Client) Service

NewService returns a Service with all of the expected middlewares wired in.

type ServiceMiddleware

type ServiceMiddleware func(Service) Service

ServiceMiddleware describes a service (as opposed to endpoint) middleware. it is used to intercept the method execution and perform actions before/after the serivce method execution

func ServiceLoggingMiddleware

func ServiceLoggingMiddleware(logger logging.Logger) ServiceMiddleware

ServiceLoggingMiddleware takes a logger as a dependency and returns a ServiceLoggingMiddleware.

type SortDirection

type SortDirection uint

SortDirection can either by ASC or DESC

const (
	// ASC as ascending sort direction
	ASC SortDirection = iota
	// DESC is descending sort direction
	DESC
)

func (SortDirection) String

func (s SortDirection) String() string

Jump to

Keyboard shortcuts

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