api

package
v0.0.0-...-5f8c1fa Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbortIfError

func AbortIfError(c *gin.Context, err error) bool

AbortIfError stops request processing and displays an error page if param err is not nil. This returns true if it actually did have to abort. When it returns true, the caller should return to ensure that no further processing of the request occurs. If this returns false, there was no error, and the caller can continue processing.

func StatusCodeForError

func StatusCodeForError(err error) (status int)

StatusCodeForError returns the http.StatusCode for the specified error. If the error doesn't map to a code, this returns 500 by default.

Types

type AlertViewList

type AlertViewList struct {
	Count    int                   `json:"count"`
	Next     string                `json:"next"`
	Previous string                `json:"previous"`
	Results  []*pgmodels.AlertView `json:"results"`
}

AlertViewList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type ChecksumViewList

type ChecksumViewList struct {
	Count    int                      `json:"count"`
	Next     string                   `json:"next"`
	Previous string                   `json:"previous"`
	Results  []*pgmodels.ChecksumView `json:"results"`
}

ChecksumViewList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type DeletionRequestViewList

type DeletionRequestViewList struct {
	Count    int                             `json:"count"`
	Next     string                          `json:"next"`
	Previous string                          `json:"previous"`
	Results  []*pgmodels.DeletionRequestView `json:"results"`
}

DeletionRequestViewList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type GenericFileList

type GenericFileList struct {
	Count    int                     `json:"count"`
	Next     string                  `json:"next"`
	Previous string                  `json:"previous"`
	Results  []*pgmodels.GenericFile `json:"results"`
}

GenericFileList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type GenericFileViewList

type GenericFileViewList struct {
	Count    int                         `json:"count"`
	Next     string                      `json:"next"`
	Previous string                      `json:"previous"`
	Results  []*pgmodels.GenericFileView `json:"results"`
}

GenericFileViewList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type InstitutionViewList

type InstitutionViewList struct {
	Count    int                         `json:"count"`
	Next     string                      `json:"next"`
	Previous string                      `json:"previous"`
	Results  []*pgmodels.InstitutionView `json:"results"`
}

InstitutionViewList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type IntellectualObjectList

type IntellectualObjectList struct {
	Count    int                                `json:"count"`
	Next     string                             `json:"next"`
	Previous string                             `json:"previous"`
	Results  []*pgmodels.IntellectualObjectView `json:"results"`
}

IntellectualObjectList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type JsonList

type JsonList struct {
	// Count is the total number of items in the result set.
	Count int `json:"count"`
	// Next is the URL for the next page of results.
	Next string `json:"next"`
	// Previous is the URL for the previous page of results.
	Previous string `json:"previous"`
	// Results is the list of items on this page of the result set.
	Results interface{} `json:"results"`
}

JsonList provides the structure for an API response that contains a list of items.

func NewJsonList

func NewJsonList(items interface{}, pager *common.Pager) *JsonList

NewJsonList creates a new json list response structure.

func NewListFromJson

func NewListFromJson(jsonStr string) (*JsonList, error)

NewListFromJson converts a json string to a JsonList object. This is used primarily in API testing.

type PremisEventViewList

type PremisEventViewList struct {
	Count    int                         `json:"count"`
	Next     string                      `json:"next"`
	Previous string                      `json:"previous"`
	Results  []*pgmodels.PremisEventView `json:"results"`
}

PremisEventViewList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type Request

type Request struct {
	PathAndQuery string                            `json:"pathAndQuery"`
	CurrentUser  *pgmodels.User                    `json:"currentUser"`
	GinContext   *gin.Context                      `json:"-"`
	Auth         *middleware.ResourceAuthorization `json:"resourceAuth"`
	Error        error                             `json:"error"`
}

func NewRequest

func NewRequest(c *gin.Context) *Request

func (*Request) AssertValidIDs

func (req *Request) AssertValidIDs(resourceID, instID int64) error

AssertValidIDs returns an error if resource or institution ID in an endpoint's URL params don't match the resource/institution ID in the JSON of the request body. This is for security. E.g. We don't want someone posting to a URL that purports to update one object when in fact the JSON will be updating a different object.

func (*Request) BaseURL

func (req *Request) BaseURL() string

BaseURL returns the base of param _url. The base includes the scheme, optional port, and hostname. In other words, the URL stripped of path and query.

func (*Request) GetFilterCollection

func (req *Request) GetFilterCollection() *pgmodels.FilterCollection

GetFilterCollection returns a collection of filters the user wants to apply to an index/list request. These come from the query string. Call the ToQuery() method of the returned FilterCollection to translate query string params to SQL.

func (*Request) LoadResourceList

func (req *Request) LoadResourceList(items interface{}, orderByColumn, direction string) (*common.Pager, error)

LoadResourceList loads a list of resources for an index page. Param items should be a pointer to a slice of the type of item you want to load (GenericFile, Institution, etc.). Params orderByColumn and direction indicate a default sort order to be applied if the request did not explicitly include a sort order. (I.e. no sort=column__direction on the query string.)

func (*Request) ToJson

func (req *Request) ToJson(pretty bool) (string, error)

ToJson returns the request object as JSON (minus the gin context object). This is primarily for interactive debugging. Param pretty is for pretty printing.

func (*Request) ValidateFilters

func (req *Request) ValidateFilters() error

VailidateFilters returns an error if the query string contains invalid or unrecognized values. Even though GetFilterCollection below applies only valid filters, the caller should know when we are ignoring their filters, so they don't mistakenly accept invalid results.

This problem appeared in integration testing with preservation services, when some Registry calls included old Pharos filter params that are no longer valid in Registry. Registry would silently ignore those filters and return *unfiltered* results, which preserv would then act on.

It's much better to fail and force the developer (that jerk!) to fix the issues in preservation services.

type RequestError

type RequestError struct {
	StatusCode int
	Error      string
}

type StorageRecordList

type StorageRecordList struct {
	Count    int                       `json:"count"`
	Next     string                    `json:"next"`
	Previous string                    `json:"previous"`
	Results  []*pgmodels.StorageRecord `json:"results"`
}

StorageRecordList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

type WorkItemViewList

type WorkItemViewList struct {
	Count    int                      `json:"count"`
	Next     string                   `json:"next"`
	Previous string                   `json:"previous"`
	Results  []*pgmodels.WorkItemView `json:"results"`
}

WorkItemViewList is used in testing to convert a generic JsonList into a typed list that we can test with assertions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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