handler

package
v0.0.0-...-142f14e Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteJsonResponse

func WriteJsonResponse(ctx context.Context, w http.ResponseWriter, body any, statusCode int)

Write http response to http response writer

Types

type CreateSentence

type CreateSentence struct {
	//Interface to access service package's method
	Service SentenceCreater
	//Http request body validator
	Validator *validator.Validate
}

func (*CreateSentence) ServeHTTP

func (c *CreateSentence) ServeHTTP(w http.ResponseWriter, r *http.Request)

Http handler to create a new Sentence

type DeleteSentence

type DeleteSentence struct {
	//Interface to access service package's method
	Service SentenceDeleter
}

func (*DeleteSentence) ServeHTTP

func (d *DeleteSentence) ServeHTTP(w http.ResponseWriter, r *http.Request)

Http handler to delete a Sentence

type ErrorResponse

type ErrorResponse struct {
	//Content of error message
	Message string `json:"message"`
}

type FetchSentenceList

type FetchSentenceList struct {
	//Interface to access service package's method
	Service SentenceFetcher
}

func (*FetchSentenceList) ServeHTTP

func (fl *FetchSentenceList) ServeHTTP(w http.ResponseWriter, r *http.Request)

Http handler to fetch all sentences

type FetchSingleSentence

type FetchSingleSentence struct {
	//Interface to access service package's method
	Service SentenceFetcher
}

func (*FetchSingleSentence) ServeHTTP

func (fs *FetchSingleSentence) ServeHTTP(w http.ResponseWriter, r *http.Request)

Http handler to fetch a sentence by sentence id

type SentenceCreater

type SentenceCreater interface {
	CreateNewSentence(ctx context.Context, vocabularies []string, body string) (int64, error)
}

Create a sentence

type SentenceCreaterMock

type SentenceCreaterMock struct {
	// CreateNewSentenceFunc mocks the CreateNewSentence method.
	CreateNewSentenceFunc func(ctx context.Context, vocabularies []string, body string) (int64, error)
	// contains filtered or unexported fields
}

SentenceCreaterMock is a mock implementation of SentenceCreater.

func TestSomethingThatUsesSentenceCreater(t *testing.T) {

	// make and configure a mocked SentenceCreater
	mockedSentenceCreater := &SentenceCreaterMock{
		CreateNewSentenceFunc: func(ctx context.Context, vocabularies []string, body string) (int64, error) {
			panic("mock out the CreateNewSentence method")
		},
	}

	// use mockedSentenceCreater in code that requires SentenceCreater
	// and then make assertions.

}

func (*SentenceCreaterMock) CreateNewSentence

func (mock *SentenceCreaterMock) CreateNewSentence(ctx context.Context, vocabularies []string, body string) (int64, error)

CreateNewSentence calls CreateNewSentenceFunc.

func (*SentenceCreaterMock) CreateNewSentenceCalls

func (mock *SentenceCreaterMock) CreateNewSentenceCalls() []struct {
	Ctx          context.Context
	Vocabularies []string
	Body         string
}

CreateNewSentenceCalls gets all the calls that were made to CreateNewSentence. Check the length with:

len(mockedSentenceCreater.CreateNewSentenceCalls())

type SentenceDeleter

type SentenceDeleter interface {
	DeleteSentence(ctx context.Context, id string) (int64, error)
}

Delete a sentence by sentence id

type SentenceDeleterMock

type SentenceDeleterMock struct {
	// DeleteSentenceFunc mocks the DeleteSentence method.
	DeleteSentenceFunc func(ctx context.Context, id string) (int64, error)
	// contains filtered or unexported fields
}

SentenceDeleterMock is a mock implementation of SentenceDeleter.

func TestSomethingThatUsesSentenceDeleter(t *testing.T) {

	// make and configure a mocked SentenceDeleter
	mockedSentenceDeleter := &SentenceDeleterMock{
		DeleteSentenceFunc: func(ctx context.Context, id string) (int64, error) {
			panic("mock out the DeleteSentence method")
		},
	}

	// use mockedSentenceDeleter in code that requires SentenceDeleter
	// and then make assertions.

}

func (*SentenceDeleterMock) DeleteSentence

func (mock *SentenceDeleterMock) DeleteSentence(ctx context.Context, id string) (int64, error)

DeleteSentence calls DeleteSentenceFunc.

func (*SentenceDeleterMock) DeleteSentenceCalls

func (mock *SentenceDeleterMock) DeleteSentenceCalls() []struct {
	Ctx context.Context
	ID  string
}

DeleteSentenceCalls gets all the calls that were made to DeleteSentence. Check the length with:

len(mockedSentenceDeleter.DeleteSentenceCalls())

type SentenceFetcher

type SentenceFetcher interface {
	FetchSentenceList(ctx context.Context) ([]entity.Sentence, error)
	FetchSingleSentence(ctx context.Context, id string) (entity.Sentence, error)
}

Fetch all sentences or a specific sentence by sentence id

type SentenceFetcherMock

type SentenceFetcherMock struct {
	// FetchSentenceListFunc mocks the FetchSentenceList method.
	FetchSentenceListFunc func(ctx context.Context) ([]entity.Sentence, error)

	// FetchSingleSentenceFunc mocks the FetchSingleSentence method.
	FetchSingleSentenceFunc func(ctx context.Context, id string) (entity.Sentence, error)
	// contains filtered or unexported fields
}

SentenceFetcherMock is a mock implementation of SentenceFetcher.

func TestSomethingThatUsesSentenceFetcher(t *testing.T) {

	// make and configure a mocked SentenceFetcher
	mockedSentenceFetcher := &SentenceFetcherMock{
		FetchSentenceListFunc: func(ctx context.Context) ([]entity.Sentence, error) {
			panic("mock out the FetchSentenceList method")
		},
		FetchSingleSentenceFunc: func(ctx context.Context, id string) (entity.Sentence, error) {
			panic("mock out the FetchSingleSentence method")
		},
	}

	// use mockedSentenceFetcher in code that requires SentenceFetcher
	// and then make assertions.

}

func (*SentenceFetcherMock) FetchSentenceList

func (mock *SentenceFetcherMock) FetchSentenceList(ctx context.Context) ([]entity.Sentence, error)

FetchSentenceList calls FetchSentenceListFunc.

func (*SentenceFetcherMock) FetchSentenceListCalls

func (mock *SentenceFetcherMock) FetchSentenceListCalls() []struct {
	Ctx context.Context
}

FetchSentenceListCalls gets all the calls that were made to FetchSentenceList. Check the length with:

len(mockedSentenceFetcher.FetchSentenceListCalls())

func (*SentenceFetcherMock) FetchSingleSentence

func (mock *SentenceFetcherMock) FetchSingleSentence(ctx context.Context, id string) (entity.Sentence, error)

FetchSingleSentence calls FetchSingleSentenceFunc.

func (*SentenceFetcherMock) FetchSingleSentenceCalls

func (mock *SentenceFetcherMock) FetchSingleSentenceCalls() []struct {
	Ctx context.Context
	ID  string
}

FetchSingleSentenceCalls gets all the calls that were made to FetchSingleSentence. Check the length with:

len(mockedSentenceFetcher.FetchSingleSentenceCalls())

type SentenceUpdater

type SentenceUpdater interface {
	UpdateSentence(ctx context.Context, id string, body string) (int64, error)
}

Update a sentence by sentence id

type SentenceUpdaterMock

type SentenceUpdaterMock struct {
	// UpdateSentenceFunc mocks the UpdateSentence method.
	UpdateSentenceFunc func(ctx context.Context, id string, body string) (int64, error)
	// contains filtered or unexported fields
}

SentenceUpdaterMock is a mock implementation of SentenceUpdater.

func TestSomethingThatUsesSentenceUpdater(t *testing.T) {

	// make and configure a mocked SentenceUpdater
	mockedSentenceUpdater := &SentenceUpdaterMock{
		UpdateSentenceFunc: func(ctx context.Context, id string, body string) (int64, error) {
			panic("mock out the UpdateSentence method")
		},
	}

	// use mockedSentenceUpdater in code that requires SentenceUpdater
	// and then make assertions.

}

func (*SentenceUpdaterMock) UpdateSentence

func (mock *SentenceUpdaterMock) UpdateSentence(ctx context.Context, id string, body string) (int64, error)

UpdateSentence calls UpdateSentenceFunc.

func (*SentenceUpdaterMock) UpdateSentenceCalls

func (mock *SentenceUpdaterMock) UpdateSentenceCalls() []struct {
	Ctx  context.Context
	ID   string
	Body string
}

UpdateSentenceCalls gets all the calls that were made to UpdateSentence. Check the length with:

len(mockedSentenceUpdater.UpdateSentenceCalls())

type UpdateSentence

type UpdateSentence struct {
	//Interface to access service package's method
	Service SentenceUpdater
	//Http request body validator
	Validator *validator.Validate
}

func (*UpdateSentence) ServeHTTP

func (u *UpdateSentence) ServeHTTP(w http.ResponseWriter, r *http.Request)

Http handler to create a new Sentence

Jump to

Keyboard shortcuts

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