Documentation
¶
Index ¶
- func AbortIfError(c *gin.Context, err error) bool
- func StatusCodeForError(err error) (status int)
- type AlertViewList
- type ChecksumViewList
- type DeletionRequestViewList
- type GenericFileList
- type GenericFileViewList
- type InstitutionViewList
- type IntellectualObjectList
- type JsonList
- type PremisEventViewList
- type Request
- func (req *Request) AssertValidIDs(resourceID, instID int64) error
- func (req *Request) BaseURL() string
- func (req *Request) GetFilterCollection() *pgmodels.FilterCollection
- func (req *Request) LoadResourceList(items interface{}, orderByColumn, direction string) (*common.Pager, error)
- func (req *Request) ToJson(pretty bool) (string, error)
- func (req *Request) ValidateFilters() error
- type RequestError
- type StorageRecordList
- type WorkItemViewList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbortIfError ¶
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 ¶
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 ¶
NewJsonList creates a new json list response structure.
func NewListFromJson ¶
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 (*Request) AssertValidIDs ¶
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 ¶
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 ¶
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 ¶
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 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.