models

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 5 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content added in v0.4.0

type Content struct {
	State               string            `bson:"state,omitempty"                 json:"state,omitempty"`
	Spotlight           *[]TypeLinkObject `bson:"spotlight,omitempty"             json:"spotlight,omitempty"`
	Articles            *[]TypeLinkObject `bson:"articles,omitempty"              json:"articles,omitempty"`
	Bulletins           *[]TypeLinkObject `bson:"bulletins,omitempty"             json:"bulletins,omitempty"`
	Methodologies       *[]TypeLinkObject `bson:"methodologies,omitempty"         json:"methodologies,omitempty"`
	MethodologyArticles *[]TypeLinkObject `bson:"methodology_articles,omitempty"  json:"methodology_articles,omitempty"`
	StaticDatasets      *[]TypeLinkObject `bson:"static_datasets,omitempty"       json:"static_datasets,omitempty"`
	Timeseries          *[]TypeLinkObject `bson:"timeseries,omitempty"            json:"timeseries,omitempty"`
}

Content represents content schema as it is stored in mongoDB and is used for marshaling and unmarshaling json representation for API ID is a duplicate of ID in TopicResponse, to facilitate each subdocument being a full-formed response in its own right depending upon request being in publish or web and also authentication.

func (*Content) StateTransitionAllowed added in v0.4.0

func (t *Content) StateTransitionAllowed(target string) bool

StateTransitionAllowed checks if the content can transition from its current state to the provided target state

func (*Content) Validate added in v0.4.0

func (t *Content) Validate() error

Validate checks that a content struct complies with the state constraints, if provided. TODO may want to add more in future

func (*Content) ValidateTransitionFrom added in v0.4.0

func (t *Content) ValidateTransitionFrom(existing *Content) error

ValidateTransitionFrom checks that this content state can be validly transitioned from the existing state

type ContentItem added in v0.4.0

type ContentItem struct {
	Title string        `json:"title,omitempty"`
	Type  string        `json:"type,omitempty"`
	Links *ContentLinks `json:"links,omitempty"`
	State string        `json:"state,omitempty"`
}

ContentItem is an individual content item

type ContentLinks struct {
	Self  *LinkObject `json:"self,omitempty"`
	Topic *LinkObject `json:"topic,omitempty"`
}

ContentLinks are content links

type ContentResponse added in v0.4.0

type ContentResponse struct {
	ID      string   `bson:"id,omitempty"       json:"id,omitempty"`
	Next    *Content `bson:"next,omitempty"     json:"next,omitempty"`
	Current *Content `bson:"current,omitempty"  json:"current,omitempty"`
}

ContentResponse represents an evolving content with the current content and the updated content. This is for mongo storage / retrieval. The 'Next' is what gets updated throughout the publishing journey, and then the 'publish' step copies the 'Next' over the 'Current' document, so that 'Current' is whats always returned in the web view. ID is a duplicate of ID in TopicResponseStore.

type ContentResponseAPI added in v0.4.0

type ContentResponseAPI struct {
	Count      int            `json:"count"`
	Offset     int            `json:"offset_index"`
	Limit      int            `json:"limit"`
	TotalCount int            `json:"total_count"`
	Items      *[]ContentItem `json:"items"`
}

ContentResponseAPI used for returning the Current OR Next & Current document(s) in REST API response

func (*ContentResponseAPI) AppendLinkInfo added in v0.4.0

func (contentList *ContentResponseAPI) AppendLinkInfo(typeName string, itemLink *[]TypeLinkObject, id, state string)

AppendLinkInfo appends to list more links sorted by HRef

type LinkObject

type LinkObject struct {
	HRef string `bson:"href,omitempty"  json:"href,omitempty"`
	ID   string `bson:"id,omitempty"    json:"id,omitempty"`
}

LinkObject represents a generic structure for all links

type Navigation struct {
	Description string                 `json:"description"`
	Links       *TopicLinks            `json:"links,omitempty"`
	Items       *[]TopicNonReferential `json:"items,omitempty"`
}

Navigation is used to get high level list of topics and subtopics with links and description for site navigation.

type PrivateContentResponseAPI added in v0.4.0

type PrivateContentResponseAPI struct {
	Next    *ContentResponseAPI `json:"next,omitempty"`
	Current *ContentResponseAPI `json:"current,omitempty"`
}

PrivateContentResponseAPI represents an evolving content with the current content and the updated content. This is for the REST API response. The 'Next' is what gets updated throughout the publishing journey, and then the 'publish' step copies the 'Next' over the 'Current' document, so that 'Current' is whats always returned in the web view.

type PrivateSubtopics

type PrivateSubtopics struct {
	Count        int              `bson:"count,omitempty"        json:"count"`
	Limit        int              `bson:"limit,omitempty"        json:"limit"`
	Offset       int              `bson:"offset_index,omitempty" json:"offset_index"`
	TotalCount   int              `bson:"total_count,omitempty"  json:"total_count"`
	PrivateItems *[]TopicResponse `bson:"items,omitempty"        json:"items"`
}

PrivateSubtopics used for returning both Next and Current document(s) in REST API response

type PublicSubtopics

type PublicSubtopics struct {
	Count       int      `bson:"count,omitempty"        json:"count"`
	Limit       int      `bson:"limit,omitempty"        json:"limit"`
	Offset      int      `bson:"offset_index,omitempty" json:"offset_index"`
	TotalCount  int      `bson:"total_count,omitempty"  json:"total_count"`
	PublicItems *[]Topic `bson:"items,omitempty"        json:"items"`
}

PublicSubtopics used for returning just the Current document(s) in REST API response

type State

type State int

State - iota enum of possible topic states

const (
	// these from dp-image-api :
	StateCreated State = iota // this is 'in_progress'
	StatePublished
	StateCompleted
)

Possible values for a State of a topic. It can only be one of the following:

func ParseState

func ParseState(stateStr string) (State, error)

ParseState returns a state from its string representation

func (State) String

func (s State) String() string

String returns the string representation of a state

func (State) TransitionAllowed

func (s State) TransitionAllowed(next State) bool

TransitionAllowed returns true only if the transition from the current state and the provided next is allowed

type Topic

type Topic struct {
	ID          string      `bson:"id,omitempty"             json:"id,omitempty"`
	Description string      `bson:"description,omitempty"    json:"description,omitempty"`
	Keywords    *[]string   `bson:"keywords,omitempty"       json:"keywords,omitempty"`
	LastUpdated *time.Time  `bson:"last_updated"             json:"-"`
	Links       *TopicLinks `bson:"links,omitempty"          json:"links,omitempty"`
	ReleaseDate *time.Time  `bson:"release_date,omitempty"   json:"release_date,omitempty"`
	State       string      `bson:"state,omitempty"          json:"state,omitempty"`
	SubtopicIds *[]string   `bson:"subtopics_ids,omitempty"  json:"subtopics_ids,omitempty"`
	Title       string      `bson:"title,omitempty"          json:"title,omitempty"`
}

Topic represents topic schema as it is stored in mongoDB and is used for marshaling and unmarshaling json representation for API ID is a duplicate of ID in TopicResponse, to facilitate each subdocument being a full-formed response in its own right depending upon request being in publish or web and also authentication. Subtopics contains TopicResonse ID(s).

func (*Topic) StateTransitionAllowed

func (t *Topic) StateTransitionAllowed(target string) bool

StateTransitionAllowed checks if the topic can transition from its current state to the provided target state

func (*Topic) Validate

func (t *Topic) Validate() error

Validate checks that a topic struct complies with the state constraints, if provided. TODO may want to add more in future

func (*Topic) ValidateTransitionFrom

func (t *Topic) ValidateTransitionFrom(existing *Topic) error

ValidateTransitionFrom checks that this topic state can be validly transitioned from the existing state

type TopicLinks struct {
	Content   *LinkObject `bson:"content,omitempty"    json:"content,omitempty"`
	Self      *LinkObject `bson:"self,omitempty"       json:"self,omitempty"`
	Subtopics *LinkObject `bson:"subtopics,omitempty"  json:"subtopics,omitempty"`
}

TopicLinks represents a list of specific links related to the topic resource

type TopicNonReferential added in v0.8.0

type TopicNonReferential struct {
	Description   string                 `json:"description,omitempty"`
	Label         string                 `json:"label"`
	Links         *TopicLinks            `json:"links,omitempty"`
	Name          string                 `json:"name"`
	SubtopicItems *[]TopicNonReferential `json:"subtopics,omitempty"`
	Title         string                 `json:"title"`
	URI           string                 `json:"uri"`
}

TopicNonReferential is used to create a single comprehensive list of topics and subtopics.

type TopicRelease added in v0.14.0

type TopicRelease struct {
	ReleaseDate string `json:"release_date"`
}

TopicRelease represents the incoming request structure containing release content

func ReadReleaseDate added in v0.14.0

func ReadReleaseDate(r io.Reader) (*TopicRelease, error)

ReadReleaseDate manages the creation of a release date object from a reader

func (*TopicRelease) Validate added in v0.14.0

func (tr *TopicRelease) Validate() (*time.Time, error)

Validate checks the topic release object has a valid timestamp that will abide by standard protocol RFC3339

type TopicResponse

type TopicResponse struct {
	ID      string `bson:"id,omitempty"       json:"id,omitempty"`
	Current *Topic `bson:"current,omitempty"  json:"current,omitempty"`
	Next    *Topic `bson:"next,omitempty"     json:"next,omitempty"`
}

TopicResponse represents an evolving topic with the current topic and the updated topic The 'Next' is what gets updated throughout the publishing journey, and then the 'publish' step copies the 'Next' over the 'Current' document, so that 'Current' is whats always returned in the web view.

type TopicUpdate added in v0.17.0

type TopicUpdate struct {
	Description string    `bson:"description"              json:"description"`
	Keywords    *[]string `bson:"keywords,omitempty"       json:"keywords,omitempty"`
	ReleaseDate string    `bson:"release_date"             json:"release_date"`
	State       string    `bson:"state"                    json:"state"`
	SubtopicIds *[]string `bson:"subtopics_ids,omitempty"  json:"subtopics_ids,omitempty"`
	Title       string    `bson:"title"                    json:"title"`
}

TopicUpdate represents the incoming request structure containing a topic update

func ReadTopicUpdate added in v0.17.0

func ReadTopicUpdate(r io.Reader) (*TopicUpdate, error)

func (*TopicUpdate) ValidateUpdate added in v0.17.0

func (t *TopicUpdate) ValidateUpdate() error

Validate checks that a topic update struct complies with the state / release date constraints

type TypeLinkObject added in v0.4.0

type TypeLinkObject struct {
	HRef  string `bson:"href,omitempty"   json:"href,omitempty"`
	Title string `bson:"title,omitempty"  json:"title,omitempty"`
}

TypeLinkObject represents a generic structure for all type links

Jump to

Keyboard shortcuts

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