rememberer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 15 Imported by: 0

README

Rememberer

An example of how an internal package can be implemented.

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	// ApiRemembererPrefix base URI prefix for all rememberer routes
	ApiRemembererPrefix = common.ApiV1UriPrefix + "/rememberer"

	// ApiWordsVariable URI variable used to get actions words
	ApiWordsVariable = "/words"
)
View Source
const RemembererWordURIVariableId = "wordId"

Variables

View Source
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

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 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

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