models

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

API Errors -> Error map

Functions

func CleanBundle added in v1.4.0

func CleanBundle(bundle *Bundle)

CleanBundle removes any whitespace from the Bundle fields (except for the CreatedAt, UpdatedAt, ScheduledAt and etag fields)

func CleanContentItem added in v1.3.0

func CleanContentItem(contentItem *ContentItem)

func ValidateError added in v1.2.0

func ValidateError(e *Error) error

func ValidateRole added in v1.12.0

func ValidateRole(role Role) bool

Types

type Action added in v1.2.0

type Action string

Action enum type representing the action taken by a user

const (
	ActionCreate Action = "CREATE"
	ActionRead   Action = "READ"
	ActionUpdate Action = "UPDATE"
	ActionDelete Action = "DELETE"
)

Define the possible values for the Action enum

type AuthEntityData added in v1.4.0

type AuthEntityData struct {
	EntityData    *permissionsAPISDK.EntityData
	IsServiceAuth bool
	Headers       datasetAPISDK.Headers
}

func CreateAuthEntityData added in v1.4.0

func CreateAuthEntityData(entityData *permissionsAPISDK.EntityData, serviceToken string) *AuthEntityData

func (*AuthEntityData) GetUserEmail added in v1.4.0

func (a *AuthEntityData) GetUserEmail() string

func (*AuthEntityData) GetUserID added in v1.4.0

func (a *AuthEntityData) GetUserID() string

type Bundle

type Bundle struct {
	ID            string         `bson:"id"                        json:"id"`
	BundleType    BundleType     `bson:"bundle_type"               json:"bundle_type"`
	CreatedBy     *User          `bson:"created_by,omitempty"      json:"created_by,omitempty"`
	CreatedAt     *time.Time     `bson:"created_at,omitempty"      json:"created_at,omitempty"`
	LastUpdatedBy *User          `bson:"last_updated_by,omitempty" json:"last_updated_by,omitempty"`
	PreviewTeams  *[]PreviewTeam `bson:"preview_teams,omitempty"   json:"preview_teams,omitempty"`
	ScheduledAt   *time.Time     `bson:"scheduled_at,omitempty"    json:"scheduled_at,omitempty"`
	State         BundleState    `bson:"state"                     json:"state"`
	Title         string         `bson:"title"                     json:"title"`
	UpdatedAt     *time.Time     `bson:"updated_at,omitempty"      json:"updated_at,omitempty"`
	ManagedBy     ManagedBy      `bson:"managed_by"                json:"managed_by"`
	ETag          string         `bson:"e_tag"                     json:"-"`
}

Bundle represents the response body when retrieving a bundle

func CreateBundle

func CreateBundle(reader io.Reader, email string) (*Bundle, error)

CreateBundle creates a new Bundle from the provided reader

func (*Bundle) GenerateETag added in v1.4.0

func (b *Bundle) GenerateETag(bytes *[]byte) string

type BundleState added in v1.2.0

type BundleState string

BundleState enum type representing the state of the bundle

const (
	BundleStateDraft     BundleState = "DRAFT"
	BundleStateInReview  BundleState = "IN_REVIEW"
	BundleStateApproved  BundleState = "APPROVED"
	BundleStatePublished BundleState = "PUBLISHED"
)

Define the possible values for the BundleState enum

func (BundleState) IsValid added in v1.2.0

func (bs BundleState) IsValid() bool

IsValid validates that the BundleState is a valid enum value

func (BundleState) String added in v1.2.0

func (bs BundleState) String() string

String returns the string value of the BundleState

type BundleType added in v1.2.0

type BundleType string

BundleType enum type representing the type of the bundle

const (
	BundleTypeManual    BundleType = "MANUAL"
	BundleTypeScheduled BundleType = "SCHEDULED"
)

Define the possible values for the BundleType enum

func (BundleType) IsValid added in v1.2.0

func (bt BundleType) IsValid() bool

IsValid validates that the BundleType is a valid enum value

func (BundleType) String added in v1.4.0

func (bt BundleType) String() string

String returns the string value of the BundleType

type Bundles added in v1.2.0

type Bundles struct {
	Items *[]Bundle `bson:"items" json:"items"`
}

Bundles represents a list of bundles

type Code added in v1.2.0

type Code string

Code enum representing the error code

const (
	CodeInternalError      Code = "InternalError"
	CodeNotFound           Code = "NotFound"
	CodeBadRequest         Code = "BadRequest"
	CodeUnauthorised       Code = "Unauthorised"
	CodeForbidden          Code = "Forbidden"
	CodeConflict           Code = "Conflict"
	CodeMissingParameters  Code = "MissingParameters"
	CodeInvalidParameters  Code = "InvalidParameters"
	CodeJSONMarshalError   Code = "JSONMarshalError"
	CodeJSONUnmarshalError Code = "JSONUnmarshalError"
	CodeWriteResponseError Code = "WriteResponseError"
)

Define possible values for the Code enum

func (Code) IsValid added in v1.2.0

func (c Code) IsValid() bool

IsValid validates that the Code is a valid enum value

func (Code) String added in v1.2.0

func (c Code) String() string

String returns the string value of the Code

type ContentItem added in v1.2.0

type ContentItem struct {
	ID          string      `bson:"id"              json:"id"`
	BundleID    string      `bson:"bundle_id"       json:"bundle_id"`
	ContentType ContentType `bson:"content_type"    json:"content_type"`
	Metadata    Metadata    `bson:"metadata"        json:"metadata"`
	State       *State      `bson:"state,omitempty" json:"state,omitempty"`
	Links       Links       `bson:"links"           json:"links"`
}

ContentItem represents information about the datasets to be published as part of the bundle

func CreateContentItem added in v1.2.0

func CreateContentItem(reader io.Reader) (*ContentItem, error)

type ContentType added in v1.2.0

type ContentType string

ContentType enum represents the type of content

const (
	ContentTypeDataset ContentType = "DATASET"
)

Define the possible values for the contentType enum

func (ContentType) IsValid added in v1.2.0

func (ct ContentType) IsValid() bool

IsValid validates that the ContentType is a valid enum value

func (ContentType) String added in v1.3.0

func (ct ContentType) String() string

String returns the string value of the ContentType

type Contents added in v1.2.0

type Contents struct {
	PaginationFields
	Items []ContentItem `bson:"contents,omitempty" json:"contents,omitempty"`
}

Contents represents a list of contents related to a bundle

type Error added in v1.2.0

type Error struct {
	Code        *Code   `json:"code,omitempty"`
	Description string  `json:"description,omitempty"`
	Source      *Source `json:"source,omitempty"`
}

Error represents the details of a specific error

func CreateError added in v1.2.0

func CreateError(reader io.Reader) (*Error, error)

func CreateModelError added in v1.4.0

func CreateModelError(code Code, description string) *Error

func GetMatchingModelError added in v1.4.0

func GetMatchingModelError(err error) *Error

func ValidateBundle added in v1.2.0

func ValidateBundle(bundle *Bundle) []*Error

ValidateBundle checks that the Bundle has all mandatory fields and valid values

func ValidateContentItem added in v1.2.0

func ValidateContentItem(contentItem *ContentItem) []*Error

type ErrorList added in v1.2.0

type ErrorList struct {
	Errors []*Error `json:"errors"`
}

ErrorList represents a list of errors

type ErrorResult added in v1.3.0

type ErrorResult[TError Error] struct {
	Error          *TError
	HTTPStatusCode int
}

Struct to represent an API error, and the HTTP Status code to return

func CreateBadRequestErrorResult added in v1.4.0

func CreateBadRequestErrorResult[TError Error](err *TError) *ErrorResult[TError]

Create an error response with a 400 status code

func CreateErrorResult added in v1.3.0

func CreateErrorResult[TError Error](err *TError, httpStatusCode int) *ErrorResult[TError]

func CreateInternalErrorResult added in v1.4.0

func CreateInternalErrorResult[TError Error](err *TError) *ErrorResult[TError]

Create an error response with a 500 status code

func CreateNotFoundResult added in v1.3.0

func CreateNotFoundResult[TError Error](err *TError) *ErrorResult[TError]

Create an error response with a 404 status code

type Event added in v1.2.0

type Event struct {
	CreatedAt   *time.Time   `bson:"created_at,omitempty"   json:"created_at,omitempty"`
	RequestedBy *RequestedBy `bson:"requested_by,omitempty" json:"requested_by,omitempty"`
	Action      Action       `bson:"action"                 json:"action"`
	Resource    string       `bson:"resource"               json:"resource"`
	ContentItem *ContentItem `bson:"content_item,omitempty" json:"content_item,omitempty"`
	Bundle      *Bundle      `bson:"bundle,omitempty"       json:"bundle,omitempty"`
}

Event represents details of a specific change event forming part of the change and audit log for a bundle

func CreateEventModel added in v1.4.0

func CreateEventModel(id, email string, action Action, bundle *Bundle, contentItem *ContentItem) (*Event, error)

CreateEventModel creates an Event model for either a Bundle or a ContentItem

type EventsList added in v1.2.0

type EventsList struct {
	PaginationFields
	Items *[]Event `bson:"items,omitempty" json:"items,omitempty"`
}

EventsList represents the list of change events which form the change and audit log for a bundle

type Links struct {
	Edit    string `bson:"edit"    json:"edit"`
	Preview string `bson:"preview" json:"preview"`
}

Links represents the navigational links for onward actions related to the content item

type ManagedBy added in v1.2.0

type ManagedBy string

ManagedBy enum type representing the system that created and manages the bundle

const (
	ManagedByWagtail   ManagedBy = "WAGTAIL"
	ManagedByDataAdmin ManagedBy = "DATA-ADMIN"
)

Define the possible values for the ManagedBy enum

func (ManagedBy) IsValid added in v1.2.0

func (mb ManagedBy) IsValid() bool

IsValid validates that the ManagedBy is a valid enum value

func (ManagedBy) String added in v1.4.0

func (mb ManagedBy) String() string

String returns the string value of the ManagedBy

type Metadata added in v1.2.0

type Metadata struct {
	DatasetID string `bson:"dataset_id"      json:"dataset_id"`
	EditionID string `bson:"edition_id"      json:"edition_id"`
	Title     string `bson:"title,omitempty" json:"title,omitempty"`
	VersionID int    `bson:"version_id"      json:"version_id"`
}

Metadata represents the metadata for the content item

type PaginationFields added in v1.1.0

type PaginationFields struct {
	Count      int `json:"count"`
	Limit      int `json:"limit"`
	Offset     int `json:"offset"`
	TotalCount int `json:"total_count"`
}

PaginationFields represents the fields used for pagination in an API response

type PaginationResult added in v1.3.0

type PaginationResult[TItem any] struct {
	Items      []*TItem
	TotalCount int
}

type PaginationSuccessResult added in v1.3.0

type PaginationSuccessResult[TItem any] = SuccessResult[PaginationResult[TItem]]

type PreviewTeam added in v1.2.0

type PreviewTeam struct {
	ID string `bson:"id" json:"id"`
}

PreviewTeam represents a team who have permissions to view the dataset series in the bundle

type RequestedBy added in v1.2.0

type RequestedBy struct {
	ID    string `bson:"id"              json:"id"`
	Email string `bson:"email,omitempty" json:"email,omitempty"`
}

RequestedBy represents the user who made the request

type Role added in v1.12.0

type Role string
const (
	RoleDatasetsPreviewer Role = "datasets-previewer"
)

func (Role) String added in v1.12.0

func (r Role) String() string

type Source added in v1.2.0

type Source struct {
	Field     string `json:"field,omitempty"`
	Parameter string `json:"parameter,omitempty"`
	Header    string `json:"header,omitempty"`
}

Source represents the details of which field or parameter the error relates to. Used to return validation errors to 4xx requests. Only one of the properties below can be returned in any single error.

type State added in v1.2.0

type State string

State enum represents the state of the content item

const (
	StateApproved  State = "APPROVED"
	StatePublished State = "PUBLISHED"
)

Define the possible values for the state enum

func (State) IsValid added in v1.2.0

func (s State) IsValid() bool

IsValid validates that the State is a valid enum value

func (State) String added in v1.3.0

func (s State) String() string

String returns the string value of the State

type SuccessResult added in v1.3.0

type SuccessResult[TResult any] struct {
	Result         *TResult
	HTTPStatusCode int
}

Struct to represent a successful API result, and the HTTP status code to return

func CreateOkResult added in v1.3.0

func CreateOkResult[TResult any](result *TResult) *SuccessResult[TResult]

Create a success result with a 200 status

func CreatePaginationSuccessResult added in v1.3.0

func CreatePaginationSuccessResult[TItem any](items []*TItem, totalCount int) *SuccessResult[PaginationResult[TItem]]

func CreateSuccessResult added in v1.3.0

func CreateSuccessResult[TResult any](result *TResult, httpStatusCode int) *SuccessResult[TResult]

type UpdateStateRequest added in v1.4.0

type UpdateStateRequest struct {
	State BundleState
}

type User added in v1.2.0

type User struct {
	Email string `bson:"email" json:"email"`
}

User represents the user who created or updated the bundle

Jump to

Keyboard shortcuts

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