dictionary

package
v0.0.0-...-c8e808c Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrKeyDictionaryError error key placeholder [R-001]
	ErrKeyDictionaryError string = "DictionaryError"

	// ErrKeyWordWithIdNotFound returned when unable to find word with matching Id [R-002]
	ErrKeyWordWithIdNotFound string = "WordWithIdNotFound"

	// ErrKeyWordWithNameNotFound returned when unable to find word with matching name [R-003]
	ErrKeyWordWithNameNotFound string = "WordWithNameNotFound"

	// ErrKeyWordAlreadyExists returned when the word can be found in repository [R-004]
	ErrKeyWordAlreadyExists string = "WordAlreadyExists"

	// ErrKeyInvalidWordId returned when an error occurs when carrying out an action around validating or getting
	// a word Id [R-005]
	ErrKeyInvalidWordId string = "InvalidWordId"

	// ErrKeyInvalidWordBody returned when error occurs while decoding word request body [R-006]
	ErrKeyInvalidWordBody string = "InvalidCreateWordBody"

	// ErrKeyInvalidQueryParam returned when error occurs while validating query params on request [R-007]
	ErrKeyInvalidQueryParam string = "InvalidQueryParam"
)
View Source
const (
	// ApiDictionaryPrefix base Uri prefix for all dictionary routes
	ApiDictionaryPrefix = common.ApiV1UriPrefix

	// ApiWordsVariable Uri variable used to get actions words
	ApiWordsVariable = "/words"
)
View Source
const DictionaryWordUriVariableId = "wordId"

Variables

View Source
var (
	// ApiDictionaryWordIdVariable Uri variable used to get dictionary Id out of Uri
	ApiDictionaryWordIdVariable = fmt.Sprintf("/{%s}", DictionaryWordUriVariableId)

	// ApiDictionarySpecificWordIdUriPath the Uri path for actioning a specific word
	ApiDictionarySpecificWordIdUriPath = fmt.Sprintf("%s%s", ApiWordsVariable, ApiDictionaryWordIdVariable)
)

Functions

func AttachRoutes

func AttachRoutes(request *AttachRoutesRequest)

AttachRoutes attaches dictionary handler to corresponding routes on router

Types

type AttachRoutesRequest

type AttachRoutesRequest struct {
	// Router main router being served by Api
	Router *router.Router

	// Handler valid dictionary handler
	Handler dictionaryHandler
}

AttachRoutesRequest holds everything needed to attach dictionary routes to router

type CreateWordRequest

type CreateWordRequest struct {

	// Name the word the user wishes to add to service
	Name string `json:"name" validate:"required,min=3"`
}

CreateWordRequest holds everything needed to create word on platform

type CreateWordResponse

type CreateWordResponse struct {

	// Word holds created, including its Id
	Word *Word `json:"word"`
}

CreateWordResponse holds the response for when new word is added to the platform

type DeleteWordRequest

type DeleteWordRequest struct {
	// Id the word's UUId
	Id string `validate:"uuid4"`
}

DeleteWordRequest holds everything needed for deleting a word request

type GetWordByIdRequest

type GetWordByIdRequest struct {
	// Id the word indentifier
	Id string `validate:"uuid4"`
}

GetWordByIdRequest holds everything needed for getting word based on Id

type GetWordByIdResponse

type GetWordByIdResponse struct {
	// Word holds the word that matches the passed id
	Word *Word `json:"word"`
}

GetWordByIdResponse holds the word that matches the on Id requested

type GetWordsRequest

type GetWordsRequest struct {
}

GetWordsRequest holds all the data needed to get all words request

type GetWordsResponse

type GetWordsResponse struct {
	// Words is the collection of words on the platform
	Words []Word `json:"words"`
}

GetWordsResponse holds all the data requested in the get all words request

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler manages dictionary requests

func NewHandler

func NewHandler(service dictionaryService, validator dictionaryValidator, embeddedContent fs.FS, embeddedContentFilePathPrefix string) *Handler

NewHandler returns dictionary handler

func (*Handler) CreateWord

func (h *Handler) CreateWord(w http.ResponseWriter, r *http.Request)

CreateWord returns reponse from word creation request

func (*Handler) DeleteWord

func (h *Handler) DeleteWord(w http.ResponseWriter, r *http.Request)

DeleteWord returns reponse after handling word delete request

func (*Handler) GetWordById

func (h *Handler) GetWordById(w http.ResponseWriter, r *http.Request)

GetWordById returns response for request looking for a specific word

func (*Handler) GetWords

func (h *Handler) GetWords(w http.ResponseWriter, r *http.Request)

GetWords returns response for request querying all the words

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service holds and manages dictionary business logic

func NewService

func NewService(dictionaryRespository dictionaryRespository) *Service

NewService created dictionary service

func (*Service) CreateWord

func (s *Service) CreateWord(ctx context.Context, r *CreateWordRequest) (*CreateWordResponse, error)

CreateWord attempt to create the word in the repository

func (*Service) DeleteWordById

func (s *Service) DeleteWordById(ctx context.Context, r *DeleteWordRequest) error

DeleteWordById attempts to delete the word with matching Id in repository

func (*Service) GetWordById

func (s *Service) GetWordById(ctx context.Context, r *GetWordByIdRequest) (*GetWordByIdResponse, error)

GetWordById returns word with matching Id from repository

func (*Service) GetWords

func (s *Service) GetWords(ctx context.Context, r *GetWordsRequest) (*GetWordsResponse, error)

GetWords returns the words from the repository

type Word

type Word struct {
	// Id the unique identifier of the word
	Id string `json:"id"`

	// Name the word itself
	Name string `json:"name"`

	// CreateAt the time the word was created
	CreatedAt string `json:"created_at,omitempty"`
}

func (*Word) GetEntityType

func (w *Word) GetEntityType() reflect.Type

func (*Word) GetEntityTypeName

func (w *Word) GetEntityTypeName() string

func (*Word) SetCreatedAtTimeToNow

func (w *Word) SetCreatedAtTimeToNow() *Word

SetCreatedAtTimeToNow sets the createdAt time to now (UTC)

Jump to

Keyboard shortcuts

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