handlers

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Bearer               = "Bearer "
	RelatedPagesTemplate = "related-list-pages"
)

Constants...

Variables

This section is empty.

Functions

func ValidateTopicHierarchy added in v0.59.0

func ValidateTopicHierarchy(ctx context.Context, segments []string, cacheList cache.List) (*cache.Topic, error)

ValidateTopicHierarchy validate the segments i.e. check that they all exist in the cache, check that the hierarchy is correct and return the last item as the selectedTopic

Types

type AggregationConfig added in v1.0.0

type AggregationConfig struct {
	TemplateName                       string
	URLQueryParams                     url.Values
	UseTopicsPath                      bool
	UseURIsRequest                     bool
	NLPWeightingEnabled                bool
	ValidateParams                     func(context.Context, *config.Config, url.Values, string, *cache.Topic) (data.SearchURLParams, []core.ErrorItem)
	CreatePageModel                    func(*config.Config, *http.Request, core.Page, data.SearchURLParams, []data.Category, []data.Topic, *searchModels.SearchResponse, string, zebedeeCli.HomepageContent, string, *models.Navigation, string, cache.Topic, []core.ErrorItem, zebedeeCli.PageData, []zebedeeCli.Breadcrumb) model.SearchPage
	GetSearchAndCategoriesCountQueries func(data.SearchURLParams, *cache.Topic, string, string) (url.Values, url.Values)
}

func NewAggregationConfig added in v1.0.0

func NewAggregationConfig(template string) AggregationConfig

NewAggregationConfig creates a new instance of AggregationConfig with the specified template name

func NewAggregationWithTopicsConfig added in v1.0.0

func NewAggregationWithTopicsConfig(template string) AggregationConfig

func NewFindDatasetConfig added in v1.0.0

func NewFindDatasetConfig(req *http.Request) AggregationConfig

func NewPreviousReleasesConfig added in v1.0.0

func NewPreviousReleasesConfig(req http.Request) AggregationConfig

func NewRelatedDataConfig added in v1.0.0

func NewRelatedDataConfig(req http.Request) AggregationConfig

func NewSearchConfig added in v1.0.0

func NewSearchConfig(nlpWeightingEnabled bool) AggregationConfig

type ClientError

type ClientError interface {
	Code() int
}

ClientError is an interface that can be used to retrieve the status code if a client has errored

type RenderClient added in v0.2.0

type RenderClient interface {
	BuildPage(w io.Writer, pageModel interface{}, templateName string)
	NewBasePageModel() coreModel.Page
}

RenderClient is an interface with methods for require for rendering a template

type RenderClientMock added in v0.2.0

type RenderClientMock struct {
	// BuildPageFunc mocks the BuildPage method.
	BuildPageFunc func(w io.Writer, pageModel interface{}, templateName string)

	// NewBasePageModelFunc mocks the NewBasePageModel method.
	NewBasePageModelFunc func() core.Page
	// contains filtered or unexported fields
}

RenderClientMock is a mock implementation of RenderClient.

func TestSomethingThatUsesRenderClient(t *testing.T) {

	// make and configure a mocked RenderClient
	mockedRenderClient := &RenderClientMock{
		BuildPageFunc: func(w io.Writer, pageModel interface{}, templateName string)  {
			panic("mock out the BuildPage method")
		},
		NewBasePageModelFunc: func() core.Page {
			panic("mock out the NewBasePageModel method")
		},
	}

	// use mockedRenderClient in code that requires RenderClient
	// and then make assertions.

}

func (*RenderClientMock) BuildPage added in v0.11.0

func (mock *RenderClientMock) BuildPage(w io.Writer, pageModel interface{}, templateName string)

BuildPage calls BuildPageFunc.

func (*RenderClientMock) BuildPageCalls added in v0.11.0

func (mock *RenderClientMock) BuildPageCalls() []struct {
	W            io.Writer
	PageModel    interface{}
	TemplateName string
}

BuildPageCalls gets all the calls that were made to BuildPage. Check the length with:

len(mockedRenderClient.BuildPageCalls())

func (*RenderClientMock) NewBasePageModel added in v0.11.0

func (mock *RenderClientMock) NewBasePageModel() core.Page

NewBasePageModel calls NewBasePageModelFunc.

func (*RenderClientMock) NewBasePageModelCalls added in v0.11.0

func (mock *RenderClientMock) NewBasePageModelCalls() []struct {
}

NewBasePageModelCalls gets all the calls that were made to NewBasePageModel. Check the length with:

len(mockedRenderClient.NewBasePageModelCalls())

type SearchClient added in v0.2.0

type SearchClient interface {
	GetSearch(ctx context.Context, options searchSDK.Options) (*searchModels.SearchResponse, searchError.Error)
	PostSearchURIs(ctx context.Context, options searchSDK.Options, urisRequest searchAPI.URIsRequest) (*searchModels.SearchResponse, searchError.Error)
}

SearchClient is an interface with methods required for a search client

type SearchClientError added in v0.44.0

type SearchClientError interface {
	Status() int
}

Search API returns a SearchClientError interface, which differs from ZebedeeClient

type SearchClientMock added in v0.2.0

type SearchClientMock struct {
	// GetSearchFunc mocks the GetSearch method.
	GetSearchFunc func(ctx context.Context, options searchSDK.Options) (*searchModels.SearchResponse, searchError.Error)

	// PostSearchURIsFunc mocks the PostSearchURIs method.
	PostSearchURIsFunc func(ctx context.Context, options searchSDK.Options, urisRequest searchAPI.URIsRequest) (*searchModels.SearchResponse, searchError.Error)
	// contains filtered or unexported fields
}

SearchClientMock is a mock implementation of SearchClient.

func TestSomethingThatUsesSearchClient(t *testing.T) {

	// make and configure a mocked SearchClient
	mockedSearchClient := &SearchClientMock{
		GetSearchFunc: func(ctx context.Context, options searchSDK.Options) (*searchModels.SearchResponse, searchError.Error) {
			panic("mock out the GetSearch method")
		},
		PostSearchURIsFunc: func(ctx context.Context, options searchSDK.Options, urisRequest searchAPI.URIsRequest) (*searchModels.SearchResponse, searchError.Error) {
			panic("mock out the PostSearchURIs method")
		},
	}

	// use mockedSearchClient in code that requires SearchClient
	// and then make assertions.

}

func (*SearchClientMock) GetSearch added in v0.2.0

GetSearch calls GetSearchFunc.

func (*SearchClientMock) GetSearchCalls added in v0.2.0

func (mock *SearchClientMock) GetSearchCalls() []struct {
	Ctx     context.Context
	Options searchSDK.Options
}

GetSearchCalls gets all the calls that were made to GetSearch. Check the length with:

len(mockedSearchClient.GetSearchCalls())

func (*SearchClientMock) PostSearchURIs added in v0.67.0

PostSearchURIs calls PostSearchURIsFunc.

func (*SearchClientMock) PostSearchURIsCalls added in v0.67.0

func (mock *SearchClientMock) PostSearchURIsCalls() []struct {
	Ctx         context.Context
	Options     searchSDK.Options
	UrisRequest searchAPI.URIsRequest
}

PostSearchURIsCalls gets all the calls that were made to PostSearchURIs. Check the length with:

len(mockedSearchClient.PostSearchURIsCalls())

type SearchHandler added in v1.0.0

type SearchHandler struct {
	Renderer                    RenderClient
	SearchClient                SearchClient
	TopicClient                 TopicClient
	ZebedeeClient               ZebedeeClient
	EnableAggregationPages      bool
	EnableTopicAggregationPages bool
	CacheList                   cache.List
}

SearchHandler represents the handlers for search functionality

func NewSearchHandler added in v1.0.0

func NewSearchHandler(rc RenderClient, sc SearchClient, tc TopicClient, zc ZebedeeClient, cfg *config.Config, cl cache.List) *SearchHandler

NewSearchHandler creates a new instance of SearchHandler

func (*SearchHandler) DataAggregation added in v1.0.0

func (sh *SearchHandler) DataAggregation(cfg *config.Config, template string) http.HandlerFunc

DataAggregation handler

func (*SearchHandler) DataAggregationWithTopics added in v1.0.0

func (sh *SearchHandler) DataAggregationWithTopics(cfg *config.Config, template string) http.HandlerFunc

DataAggregationWithTopics for data aggregation routes with topic/subtopics

func (*SearchHandler) FindDataset added in v1.0.0

func (sh *SearchHandler) FindDataset(cfg *config.Config) http.HandlerFunc

func (*SearchHandler) PreviousReleases added in v1.0.0

func (sh *SearchHandler) PreviousReleases(cfg *config.Config) http.HandlerFunc

PreviousReleases handler

func (*SearchHandler) RelatedData added in v1.0.0

func (sh *SearchHandler) RelatedData(cfg *config.Config) http.HandlerFunc

RelatedData handler

func (*SearchHandler) Search added in v1.0.0

func (sh *SearchHandler) Search(cfg *config.Config) http.HandlerFunc

Search handler

type TopicClient added in v0.53.0

type TopicClient interface {
	GetNavigationPublic(ctx context.Context, reqHeaders topicSDK.Headers, options topicSDK.Options) (*topicModels.Navigation, topicError.Error)
	GetRootTopicsPrivate(ctx context.Context, reqHeaders topicSDK.Headers) (*topicModels.PrivateSubtopics, topicError.Error)
	GetRootTopicsPublic(ctx context.Context, reqHeaders topicSDK.Headers) (*topicModels.PublicSubtopics, topicError.Error)
	GetSubtopicsPrivate(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.PrivateSubtopics, topicError.Error)
	GetSubtopicsPublic(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.PublicSubtopics, topicError.Error)
	GetTopicPrivate(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.TopicResponse, topicError.Error)
	GetTopicPublic(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.Topic, topicError.Error)
}

TopicClient is an interface with methods required for a zebedee client

type TopicClientMock added in v0.53.0

type TopicClientMock struct {
	// GetNavigationPublicFunc mocks the GetNavigationPublic method.
	GetNavigationPublicFunc func(ctx context.Context, reqHeaders topicSDK.Headers, options topicSDK.Options) (*topicModels.Navigation, topicError.Error)

	// GetRootTopicsPrivateFunc mocks the GetRootTopicsPrivate method.
	GetRootTopicsPrivateFunc func(ctx context.Context, reqHeaders topicSDK.Headers) (*topicModels.PrivateSubtopics, topicError.Error)

	// GetRootTopicsPublicFunc mocks the GetRootTopicsPublic method.
	GetRootTopicsPublicFunc func(ctx context.Context, reqHeaders topicSDK.Headers) (*topicModels.PublicSubtopics, topicError.Error)

	// GetSubtopicsPrivateFunc mocks the GetSubtopicsPrivate method.
	GetSubtopicsPrivateFunc func(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.PrivateSubtopics, topicError.Error)

	// GetSubtopicsPublicFunc mocks the GetSubtopicsPublic method.
	GetSubtopicsPublicFunc func(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.PublicSubtopics, topicError.Error)

	// GetTopicPrivateFunc mocks the GetTopicPrivate method.
	GetTopicPrivateFunc func(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.TopicResponse, topicError.Error)

	// GetTopicPublicFunc mocks the GetTopicPublic method.
	GetTopicPublicFunc func(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.Topic, topicError.Error)
	// contains filtered or unexported fields
}

TopicClientMock is a mock implementation of TopicClient.

func TestSomethingThatUsesTopicClient(t *testing.T) {

	// make and configure a mocked TopicClient
	mockedTopicClient := &TopicClientMock{
		GetNavigationPublicFunc: func(ctx context.Context, reqHeaders topicSDK.Headers, options topicSDK.Options) (*topicModels.Navigation, topicError.Error) {
			panic("mock out the GetNavigationPublic method")
		},
		GetRootTopicsPrivateFunc: func(ctx context.Context, reqHeaders topicSDK.Headers) (*topicModels.PrivateSubtopics, topicError.Error) {
			panic("mock out the GetRootTopicsPrivate method")
		},
		GetRootTopicsPublicFunc: func(ctx context.Context, reqHeaders topicSDK.Headers) (*topicModels.PublicSubtopics, topicError.Error) {
			panic("mock out the GetRootTopicsPublic method")
		},
		GetSubtopicsPrivateFunc: func(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.PrivateSubtopics, topicError.Error) {
			panic("mock out the GetSubtopicsPrivate method")
		},
		GetSubtopicsPublicFunc: func(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.PublicSubtopics, topicError.Error) {
			panic("mock out the GetSubtopicsPublic method")
		},
		GetTopicPrivateFunc: func(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.TopicResponse, topicError.Error) {
			panic("mock out the GetTopicPrivate method")
		},
		GetTopicPublicFunc: func(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.Topic, topicError.Error) {
			panic("mock out the GetTopicPublic method")
		},
	}

	// use mockedTopicClient in code that requires TopicClient
	// and then make assertions.

}

func (*TopicClientMock) GetNavigationPublic added in v0.53.0

func (mock *TopicClientMock) GetNavigationPublic(ctx context.Context, reqHeaders topicSDK.Headers, options topicSDK.Options) (*topicModels.Navigation, topicError.Error)

GetNavigationPublic calls GetNavigationPublicFunc.

func (*TopicClientMock) GetNavigationPublicCalls added in v0.53.0

func (mock *TopicClientMock) GetNavigationPublicCalls() []struct {
	Ctx        context.Context
	ReqHeaders topicSDK.Headers
	Options    topicSDK.Options
}

GetNavigationPublicCalls gets all the calls that were made to GetNavigationPublic. Check the length with:

len(mockedTopicClient.GetNavigationPublicCalls())

func (*TopicClientMock) GetRootTopicsPrivate added in v0.53.0

func (mock *TopicClientMock) GetRootTopicsPrivate(ctx context.Context, reqHeaders topicSDK.Headers) (*topicModels.PrivateSubtopics, topicError.Error)

GetRootTopicsPrivate calls GetRootTopicsPrivateFunc.

func (*TopicClientMock) GetRootTopicsPrivateCalls added in v0.53.0

func (mock *TopicClientMock) GetRootTopicsPrivateCalls() []struct {
	Ctx        context.Context
	ReqHeaders topicSDK.Headers
}

GetRootTopicsPrivateCalls gets all the calls that were made to GetRootTopicsPrivate. Check the length with:

len(mockedTopicClient.GetRootTopicsPrivateCalls())

func (*TopicClientMock) GetRootTopicsPublic added in v0.53.0

func (mock *TopicClientMock) GetRootTopicsPublic(ctx context.Context, reqHeaders topicSDK.Headers) (*topicModels.PublicSubtopics, topicError.Error)

GetRootTopicsPublic calls GetRootTopicsPublicFunc.

func (*TopicClientMock) GetRootTopicsPublicCalls added in v0.53.0

func (mock *TopicClientMock) GetRootTopicsPublicCalls() []struct {
	Ctx        context.Context
	ReqHeaders topicSDK.Headers
}

GetRootTopicsPublicCalls gets all the calls that were made to GetRootTopicsPublic. Check the length with:

len(mockedTopicClient.GetRootTopicsPublicCalls())

func (*TopicClientMock) GetSubtopicsPrivate added in v0.53.0

func (mock *TopicClientMock) GetSubtopicsPrivate(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.PrivateSubtopics, topicError.Error)

GetSubtopicsPrivate calls GetSubtopicsPrivateFunc.

func (*TopicClientMock) GetSubtopicsPrivateCalls added in v0.53.0

func (mock *TopicClientMock) GetSubtopicsPrivateCalls() []struct {
	Ctx        context.Context
	ReqHeaders topicSDK.Headers
	ID         string
}

GetSubtopicsPrivateCalls gets all the calls that were made to GetSubtopicsPrivate. Check the length with:

len(mockedTopicClient.GetSubtopicsPrivateCalls())

func (*TopicClientMock) GetSubtopicsPublic added in v0.53.0

func (mock *TopicClientMock) GetSubtopicsPublic(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.PublicSubtopics, topicError.Error)

GetSubtopicsPublic calls GetSubtopicsPublicFunc.

func (*TopicClientMock) GetSubtopicsPublicCalls added in v0.53.0

func (mock *TopicClientMock) GetSubtopicsPublicCalls() []struct {
	Ctx        context.Context
	ReqHeaders topicSDK.Headers
	ID         string
}

GetSubtopicsPublicCalls gets all the calls that were made to GetSubtopicsPublic. Check the length with:

len(mockedTopicClient.GetSubtopicsPublicCalls())

func (*TopicClientMock) GetTopicPrivate added in v0.53.0

func (mock *TopicClientMock) GetTopicPrivate(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.TopicResponse, topicError.Error)

GetTopicPrivate calls GetTopicPrivateFunc.

func (*TopicClientMock) GetTopicPrivateCalls added in v0.53.0

func (mock *TopicClientMock) GetTopicPrivateCalls() []struct {
	Ctx        context.Context
	ReqHeaders topicSDK.Headers
	ID         string
}

GetTopicPrivateCalls gets all the calls that were made to GetTopicPrivate. Check the length with:

len(mockedTopicClient.GetTopicPrivateCalls())

func (*TopicClientMock) GetTopicPublic added in v0.53.0

func (mock *TopicClientMock) GetTopicPublic(ctx context.Context, reqHeaders topicSDK.Headers, id string) (*topicModels.Topic, topicError.Error)

GetTopicPublic calls GetTopicPublicFunc.

func (*TopicClientMock) GetTopicPublicCalls added in v0.53.0

func (mock *TopicClientMock) GetTopicPublicCalls() []struct {
	Ctx        context.Context
	ReqHeaders topicSDK.Headers
	ID         string
}

GetTopicPublicCalls gets all the calls that were made to GetTopicPublic. Check the length with:

len(mockedTopicClient.GetTopicPublicCalls())

type ZebedeeClient added in v0.26.0

type ZebedeeClient interface {
	GetHomepageContent(ctx context.Context, userAuthToken, collectionID, lang, path string) (m zebedee.HomepageContent, err error)
	GetPageData(ctx context.Context, userAuthToken, collectionID, lang, path string) (m zebedee.PageData, err error)
	GetBreadcrumb(ctx context.Context, userAccessToken, collectionID, lang, uri string) (bc []zebedee.Breadcrumb, err error)
}

ZebedeeClient is an interface with methods required for a zebedee client

type ZebedeeClientMock added in v0.26.0

type ZebedeeClientMock struct {
	// GetBreadcrumbFunc mocks the GetBreadcrumb method.
	GetBreadcrumbFunc func(ctx context.Context, userAccessToken string, collectionID string, lang string, uri string) ([]zebedeeCli.Breadcrumb, error)

	// GetHomepageContentFunc mocks the GetHomepageContent method.
	GetHomepageContentFunc func(ctx context.Context, userAuthToken string, collectionID string, lang string, path string) (zebedeeCli.HomepageContent, error)

	// GetPageDataFunc mocks the GetPageData method.
	GetPageDataFunc func(ctx context.Context, userAuthToken string, collectionID string, lang string, path string) (zebedeeCli.PageData, error)
	// contains filtered or unexported fields
}

ZebedeeClientMock is a mock implementation of ZebedeeClient.

func TestSomethingThatUsesZebedeeClient(t *testing.T) {

	// make and configure a mocked ZebedeeClient
	mockedZebedeeClient := &ZebedeeClientMock{
		GetBreadcrumbFunc: func(ctx context.Context, userAccessToken string, collectionID string, lang string, uri string) ([]zebedeeCli.Breadcrumb, error) {
			panic("mock out the GetBreadcrumb method")
		},
		GetHomepageContentFunc: func(ctx context.Context, userAuthToken string, collectionID string, lang string, path string) (zebedeeCli.HomepageContent, error) {
			panic("mock out the GetHomepageContent method")
		},
		GetPageDataFunc: func(ctx context.Context, userAuthToken string, collectionID string, lang string, path string) (zebedeeCli.PageData, error) {
			panic("mock out the GetPageData method")
		},
	}

	// use mockedZebedeeClient in code that requires ZebedeeClient
	// and then make assertions.

}

func (*ZebedeeClientMock) GetBreadcrumb added in v0.65.0

func (mock *ZebedeeClientMock) GetBreadcrumb(ctx context.Context, userAccessToken string, collectionID string, lang string, uri string) ([]zebedeeCli.Breadcrumb, error)

GetBreadcrumb calls GetBreadcrumbFunc.

func (*ZebedeeClientMock) GetBreadcrumbCalls added in v0.65.0

func (mock *ZebedeeClientMock) GetBreadcrumbCalls() []struct {
	Ctx             context.Context
	UserAccessToken string
	CollectionID    string
	Lang            string
	URI             string
}

GetBreadcrumbCalls gets all the calls that were made to GetBreadcrumb. Check the length with:

len(mockedZebedeeClient.GetBreadcrumbCalls())

func (*ZebedeeClientMock) GetHomepageContent added in v0.26.0

func (mock *ZebedeeClientMock) GetHomepageContent(ctx context.Context, userAuthToken string, collectionID string, lang string, path string) (zebedeeCli.HomepageContent, error)

GetHomepageContent calls GetHomepageContentFunc.

func (*ZebedeeClientMock) GetHomepageContentCalls added in v0.26.0

func (mock *ZebedeeClientMock) GetHomepageContentCalls() []struct {
	Ctx           context.Context
	UserAuthToken string
	CollectionID  string
	Lang          string
	Path          string
}

GetHomepageContentCalls gets all the calls that were made to GetHomepageContent. Check the length with:

len(mockedZebedeeClient.GetHomepageContentCalls())

func (*ZebedeeClientMock) GetPageData added in v0.64.0

func (mock *ZebedeeClientMock) GetPageData(ctx context.Context, userAuthToken string, collectionID string, lang string, path string) (zebedeeCli.PageData, error)

GetPageData calls GetPageDataFunc.

func (*ZebedeeClientMock) GetPageDataCalls added in v0.64.0

func (mock *ZebedeeClientMock) GetPageDataCalls() []struct {
	Ctx           context.Context
	UserAuthToken string
	CollectionID  string
	Lang          string
	Path          string
}

GetPageDataCalls gets all the calls that were made to GetPageData. Check the length with:

len(mockedZebedeeClient.GetPageDataCalls())

Jump to

Keyboard shortcuts

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