Documentation ¶
Index ¶
- Constants
- Variables
- func AttachRoutes(request *AttachRoutesRequest)
- type AttachRoutesRequest
- type CreateWordRequest
- type CreateWordResponse
- type DeleteWordRequest
- type GetWordByIdRequest
- type GetWordByIdResponse
- type GetWordsRequest
- type GetWordsResponse
- type Handler
- type Service
- func (s *Service) CreateWord(ctx context.Context, r *CreateWordRequest) (*CreateWordResponse, error)
- func (s *Service) DeleteWordById(ctx context.Context, r *DeleteWordRequest) error
- func (s *Service) GetWordById(ctx context.Context, r *GetWordByIdRequest) (*GetWordByIdResponse, error)
- func (s *Service) GetWords(ctx context.Context, r *GetWordsRequest) (*GetWordsResponse, error)
- type Word
Constants ¶
const ( // ErrKeyRemembererError error key placeholder [R-001] ErrKeyRemembererError string = "RemembererError" // 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" )
const ( // ApiRemembererPrefix base URI prefix for all rememberer routes ApiRemembererPrefix = common.ApiV1UriPrefix + "/rememberer" // ApiWordsVariable URI variable used to get actions words ApiWordsVariable = "/words" )
const RemembererWordURIVariableId = "wordId"
Variables ¶
var ( // ApiRemembererWordIdVariable URI variable used to get rememberer Id out of URI ApiRemembererWordIdVariable = fmt.Sprintf("/{%s}", RemembererWordURIVariableId) // ApiRemembererSpecificWordIdUriPath the URI path for actioning a specific word ApiRemembererSpecificWordIdUriPath = fmt.Sprintf("%s%s", ApiWordsVariable, ApiRemembererWordIdVariable) )
Functions ¶
func AttachRoutes ¶
func AttachRoutes(request *AttachRoutesRequest)
AttachRoutes attaches rememberer handler to corresponding routes on router
Types ¶
type AttachRoutesRequest ¶
type AttachRoutesRequest struct { // Router main router being served by Api Router *router.Router // Handler valid rememberer handler Handler remembererHandler }
AttachRoutesRequest holds everything needed to attach rememberer 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 rememberer requests
func NewHandler ¶
func NewHandler(service remembererService, validator remembererValidator, embeddedContent fs.FS) *Handler
NewHandler returns rememberer 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
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service holds and manages rememberer business logic
func NewService ¶
func NewService(remembererRespository remembererRespository) *Service
NewService created rememberer 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) SetCreatedAtTimeToNow ¶
SetCreatedAtTimeToNow sets the createdAt time to now (UTC)