handler

package
v0.0.0-...-d4e755f Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type Handler

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

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) AddPost

func (h *Handler) AddPost(c echo.Context) error

AddPost godoc @Summary Add a new post @Description Add a new post with the input payload @Tags posts @Accept json @Produce json @Param post body postData true "Post Data" @Success 200 {object} models.Post @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /posts [post]

func (*Handler) DeletePost

func (h *Handler) DeletePost(c echo.Context) error

DeletePost godoc @Summary Delete a post by ID @Description Delete a single post by its ID @Tags posts @Accept json @Produce json @Param id path int true "Post ID" @Success 204 @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /posts/{id} [delete]

func (*Handler) GetAllPosts

func (h *Handler) GetAllPosts(c echo.Context) error

GetAllPosts godoc @Summary Get all posts @Description Get a list of all posts @Tags posts @Accept json @Produce json @Success 200 {array} models.Post @Failure 500 {object} ErrorResponse @Router /posts [get]

func (*Handler) GetPost

func (h *Handler) GetPost(c echo.Context) error

GetPost godoc @Summary Get a post by ID @Description Get a single post by its ID @Tags posts @Accept json @Produce json @Param id path int true "Post ID" @Success 200 {object} models.Post @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /posts/{id} [get]

func (*Handler) Home

func (h *Handler) Home(c echo.Context) error

func (*Handler) UpdatePost

func (h *Handler) UpdatePost(c echo.Context) error

UpdatePost godoc @Summary Update a post @Description Update a post with the given id @Tags posts @Accept json @Produce json @Param id path int true "Post ID" @Param post body postData true "Post Data" @Success 200 {object} models.Post @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /posts/{id} [put]

type Service

type Service interface {
	AddPost(models.Post) (models.Post, error)
	GetAllPosts() ([]models.Post, error)
	UpdatePost(models.Post) (models.Post, error)
	GetPost(id int) (models.Post, error)
	DeletePost(id int) error
}

Jump to

Keyboard shortcuts

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