handler

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpMethodNotAllowedHandler

func HttpMethodNotAllowedHandler(w http.ResponseWriter, r *http.Request)

func HttpRequestNotFound

func HttpRequestNotFound(w http.ResponseWriter, r *http.Request)

Types

type PostHandlerImpl

type PostHandlerImpl struct {
	PostService domain.PostService
}

func NewPostHandler

func NewPostHandler(postService domain.PostService) *PostHandlerImpl

func (*PostHandlerImpl) AddPostVoteHandler

func (p *PostHandlerImpl) AddPostVoteHandler(w http.ResponseWriter, r *http.Request)

AddPostVoteHandler godoc

@Summary		Add a vote to a post
@Description	Add a vote for a post by ID. authenticated required!
@Accept			json
@Produce		json
@Tags			Posts
@Security		BearerAuth
@Param			id			path		int						true	"Post ID"
@Param			voteBody	body		entities.VoteRequest	true	"value must 1 or -1"
@Success		200			{object}	helpers.VoteSuccessful
@Failure		400			{object}	helpers.BadRequest
@Failure		404			{object}	helpers.PostNotFound
@Failure		403			{object}	helpers.Forbidden
@Failure		500			{object}	helpers.InternalServerError
@Router			/post/{id}/vote [post]

func (*PostHandlerImpl) CreatePostHandler

func (p *PostHandlerImpl) CreatePostHandler(w http.ResponseWriter, r *http.Request)

CreatePostHandler godoc

@Summary		Create a new post
@Description	Create a new post with the provided data
@Accept			json
@Produce		json
@Tags			Posts
@Security		BearerAuth
@Param			postBody	body		entities.PostCreateUpdateRequest	true	"just send title and text. authenticated required!"
@Success		201			{object}	helpers.Post
@Failure		400			{object}	helpers.BadRequest
@Failure		500			{object}	helpers.InternalServerError
@Router			/post [post]

func (*PostHandlerImpl) DeletePostHandler

func (p *PostHandlerImpl) DeletePostHandler(w http.ResponseWriter, r *http.Request)

DeletePostHandler godoc

@Summary		Delete a post
@Description	Delete a post by ID. authenticated required!
@Accept			json
@Produce		json
@Tags			Posts
@Security		BearerAuth
@Param			id	path		int	true	"Post ID"
@Success		204	{object}	nil
@Failure		404	{object}	helpers.PostNotFound
@Failure		403	{object}	helpers.Forbidden
@Failure		500	{object}	helpers.InternalServerError
@Router			/post/{id} [delete]

func (*PostHandlerImpl) GetAllPostsHandler

func (p *PostHandlerImpl) GetAllPostsHandler(w http.ResponseWriter, r *http.Request)

GetAllPostsHandler godoc

@Summary		Get All Posts
@Description	this endpoint provide all posts. also (pagination, sort, order) is available.
@Accept			json
@Produce		json
@Tags			Posts
@Param			_	query		helpers.PostQueryParams	false	"Query Params"
@Success		200	{object}	helpers.AllPosts
@Success		400	{object}	helpers.BadRequest
@Failure		500	{object}	helpers.InternalServerError
@router			/post [get]

func (*PostHandlerImpl) GetPostHandler

func (p *PostHandlerImpl) GetPostHandler(w http.ResponseWriter, r *http.Request)

GetPostHandler godoc

@Summary		Get a single post
@Description	Get a sing post with id
@Accept			json
@Produce		json
@Tags			Posts
@Param			id	path		int	true	"Post ID"
@Success		200	{object}	helpers.Post
@Failure		404	{object}	helpers.PostNotFound
@Failure		500	{object}	helpers.InternalServerError
@router			/post/{id} [get]

func (*PostHandlerImpl) RemovePostVoteHandler

func (p *PostHandlerImpl) RemovePostVoteHandler(w http.ResponseWriter, r *http.Request)

RemovePostVoteHandler godoc

@Summary		Remove a vote from a post
@Description	Remove a vote for a post by ID. authenticated required!
@Accept			json
@Produce		json
@Tags			Posts
@Security		BearerAuth
@Param			id	path		int	true	"Post ID"
@Success		204	{object}	nil
@Failure		404	{object}	helpers.PostNotFound
@Failure		500	{object}	helpers.InternalServerError
@Router			/post/{id}/vote [delete]

func (*PostHandlerImpl) UpdatePostHandler

func (p *PostHandlerImpl) UpdatePostHandler(w http.ResponseWriter, r *http.Request)

UpdatePostHandler godoc

@Summary		Update an existing post
@Description	Update a post with the provided ID and data
@Accept			json
@Produce		json
@Tags			Posts
@Security		BearerAuth
@Param			id			path		int									true	"Post ID"
@Param			postBody	body		entities.PostCreateUpdateRequest	true	"just send title and text. authenticated required!"
@Success		200			{object}	helpers.Post
@Failure		400			{object}	helpers.BadRequest
@Failure		404			{object}	helpers.PostNotFound
@Failure		403			{object}	helpers.Forbidden
@Failure		500			{object}	helpers.InternalServerError
@Router			/post/{id} [put]

type UserHandlerImpl

type UserHandlerImpl struct {
	UserService domain.UserService
}

func NewUserHandler

func NewUserHandler(userService domain.UserService) *UserHandlerImpl

func (*UserHandlerImpl) LoginHandler

func (u *UserHandlerImpl) LoginHandler(w http.ResponseWriter, r *http.Request)

LoginHandler godoc

@Summary		Login
@Description	Login with register credential
@Accept			json
@Produce		json
@Tags			Auth
@Param			loginRequest	body		entities.UserAuthRequest	true	"make sure send a valid email and password must be grater than 8 character"
@Success		200				{object}	helpers.LoginOk
@Failure		400				{object}	helpers.BadRequest
@Failure		404				{object}	helpers.UserNotFound
@Failure		500				{object}	helpers.InternalServerError
@Router			/auth/login [post]

func (*UserHandlerImpl) LogoutHandler

func (u *UserHandlerImpl) LogoutHandler(w http.ResponseWriter, r *http.Request)

LogoutHandler godoc

@Summary		Logout
@Description	Logout and expire jwt token. authenticate required!
@Accept			json
@Produce		json
@Tags			Auth
@Security		BearerAuth
@Success		200	{object}	helpers.LogoutOk
@Failure		500	{object}	helpers.InternalServerError
@Router			/auth/logout [post]

func (*UserHandlerImpl) RegisterHandler

func (u *UserHandlerImpl) RegisterHandler(w http.ResponseWriter, r *http.Request)

RegisterHandler godoc

@Summary		Register
@Description	Register a new user
@Accept			json
@Produce		json
@Tags			Auth
@Param			registerRequest	body		entities.UserAuthRequest	true	"make sure send a valid email and password must be grater than 8 character"
@Success		201				{object}	helpers.UserCreated
@Failure		400				{object}	helpers.BadRequest
@Failure		409				{object}	helpers.UserExists
@Failure		500				{object}	helpers.InternalServerError
@Router			/auth/register [post]

Jump to

Keyboard shortcuts

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