handlers

package
v0.0.0-...-02249b2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	UserService UserService
}

Handler is a struct for injected services

func (*Handler) Create

func (h *Handler) Create(c *gin.Context)

Create godoc @Summary Create user @Description Add user to database @Tags user @Accept json @Produce json @Param user body createPayload true "Add user" @Success 201 {object} model.User @Failure 400 {object} rerrors.Error "Validation error" @Failure 409 {object} rerrors.Error "Unique Violation" @Failure 500 {object} rerrors.Error "Internal Server Error" @Router /users [post]

func (*Handler) Delete

func (h *Handler) Delete(c *gin.Context)

Delete godoc @Summary Delete user @Description Delete user @Tags user @ID string @Accept json @Produce json @Param id path string true "User ID" @Success 204 @Failure 404 {object} rerrors.Error "User Not Found" @Router /users/{id} [delete]

func (*Handler) GetAll

func (h *Handler) GetAll(c *gin.Context)

GetAll godoc @Summary Get all users @Description Fetch all users from database. Can filter by name. @Tags user @Accept json @Produce json @Param name query string false "search by name" @Success 200 {object} []model.User @Success 204 @Failure 500 {object} rerrors.Error "Internal Server Error" @Router /users [get]

func (*Handler) GetByID

func (h *Handler) GetByID(c *gin.Context)

GetByID godoc @Summary Get a single user by ID @Description Get a single user by ID @Tags user @ID string @Accept json @Produce json @Param id path string true "User ID" @Success 200 {object} model.User @Failure 400 {object} rerrors.Error "Bad Request. Invalid ID" @Failure 404 {object} rerrors.Error "User Not Found" @Router /users/{id} [get]

func (*Handler) Update

func (h *Handler) Update(c *gin.Context)

Update godoc @Summary Update user @Description Update user @Tags user @ID string @Accept json @Produce json @Param id path string true "User ID" @Param user body updatePayload false "Update user" @Success 200 {object} model.User @Failure 400 {object} rerrors.Error "Validation error" @Failure 409 {object} rerrors.Error "Unique Violation" @Failure 500 {object} rerrors.Error "Internal Server Error" @Router /users/{id} [put]

type UserService

type UserService interface {
	GetAll(ctx context.Context, name string) ([]model.User, error)
	GetByID(ctx context.Context, id string) (*model.User, error)
	Create(ctx context.Context, u *model.User) (*model.User, error)
	Update(ctx context.Context, id string, u *model.User) (*model.User, error)
	Delete(ctx context.Context, id string) error
}

UserService represents the user service implementation

Jump to

Keyboard shortcuts

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