httpchi

package
v0.0.0-...-1f78cfd Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package httpchi implements HTTP handlers for the API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggerRequestID

func LoggerRequestID(logger zerolog.Logger) func(next http.Handler) http.Handler

func NewRouter

func NewRouter(service Service, logger zerolog.Logger) http.Handler

func RegisterRoutes

func RegisterRoutes(r *chi.Mux, service Service)

func Run

func Run(service Service, logger zerolog.Logger, cfg config.AppCfg)

Types

type ErrResp

type ErrResp struct {
	Param string `json:"param,omitempty"`
	Value string `json:"value,omitempty"`
	Error string `json:"error"`
}

func NewErr

func NewErr(param, val, err string) ErrResp

func (ErrResp) Send

func (resp ErrResp) Send(w http.ResponseWriter, r *http.Request, status int)

type MsgResp

type MsgResp struct {
	Msg string `json:"message"`
}

func NewMsg

func NewMsg(msg string) MsgResp

func (MsgResp) Send

func (resp MsgResp) Send(w http.ResponseWriter, r *http.Request, status int)

type Service

type Service struct {
	DB tasktodo.Repo
}

func NewService

func NewService(db tasktodo.Repo) Service

func (Service) CreateTask

func (s Service) CreateTask(w http.ResponseWriter, r *http.Request)

CreateTask creates a new task.

@Summary		creates a new task
@Description	Creates a task with specified fields: title, description, due date, and completion status
@Tags			Tasks
@Accept			json
@Produce		json
@Param			taskRequest	body		tasktodo.Request	true	"Data of the new task"
@Success		201			{object}	tasktodo.Task		"Task successfully created"
@Failure		400			{object}	ErrResp				"Incorrect JSON or invalid date format"
@Failure		422			{object}	ErrResp				"Invalid JSON"
@Router			/task [post]

func (Service) DeleteTask

func (s Service) DeleteTask(w http.ResponseWriter, r *http.Request)

DeleteTask deletes a task by the specified ID.

@Summary		Deletes a task by ID
@Description	Deletes a task by the specified identifier
@Tags			Tasks
@Accept			json
@Produce		json
@Param			id	path		string	true	"Task ID"
@Success		200	{object}	MsgResp	"Task successfully deleted"
@Failure		404	{object}	MsgResp	"Task not found"
@Router			/task/{id} [delete]

func (Service) GetSingleTask

func (s Service) GetSingleTask(w http.ResponseWriter, r *http.Request)

GetSingleTask returns a task based on the specified ID.

@Summary		Gets a task by ID
@Description	Retrieves a task based on the provided identifier
@Tags			Tasks
@Accept			json
@Produce		json
@Param			id	path		string			true	"Task ID"
@Success		200	{object}	tasktodo.Task	"Task successfully retrieved"
@Failure		404	{object}	MsgResp			"Task not found"
@Router			/task/{id} [get]

func (Service) ListTasks

func (s Service) ListTasks(w http.ResponseWriter, r *http.Request)

ListTasks returns a list of tasks considering request parameters.

@Summary		Returns a list of tasks with filtering and pagination
@Description	Retrieves a list of tasks based on status, date, and page for pagination
@Tags			Tasks
@Accept			json
@Produce		json
@Param			status	query		string			false	"Task completion status (true/false)"
@Param			date	query		string			false	"Task date (format: YYYY-MM-DD)"
@Param			page	query		string			false	"Page number for pagination"
@Success		200		{object}	[]tasktodo.Task	"List of tasks"
@Failure		400		{object}	ErrResp			"Invalid request parameters"
@Failure		404		{object}	MsgResp			"Tasks not found"
@Router			/tasks [get]

func (Service) UpdateTask

func (s Service) UpdateTask(w http.ResponseWriter, r *http.Request)

UpdateTask updates a task by the specified ID.

@Summary		Updates a task by ID
@Description	Updates a task by the specified identifier
@Tags			Tasks
@Accept			json
@Produce		json
@Param			id		path		string				true	"Task ID"
@Param			taskUpd	body		tasktodo.Request	true	"Data for updating the task"
@Success		200		{object}	tasktodo.Task		"Task successfully updated"
@Failure		400		{object}	ErrResp				"Incorrect JSON or invalid date format"
@Failure		404		{object}	MsgResp				"Task not found"
@Failure		422		{object}	ErrResp				"Invalid JSON"
@Router			/task/{id} [put]

Jump to

Keyboard shortcuts

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