func getTaskHandler(c *gin.Context) {
	claims := jwt.ExtractClaims(c)
	u, err := models.GetUser(claims["login"].(string))
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	task, err := models.GetUserTask(c.Param("id"), u.Login)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusNotFound)
		return
	}
	if !u.CanViewTask(*task) {
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}
	c.JSON(http.StatusOK, task)
}
@Summary Get task
@Tags tasks
@Description Get a specific task
@Param   short_id	path	string	true	"short_id"
@Success 200	"OK"
@Failure 401	"Unauthorized"
@Failure 404	"Not found"
@Failure 406	"Not acceptable"
@Failure 500 "Server error" "Server error"
@Router /tasks/{short_id} [GET]
package api
import (
	"net/http"
	jwt "github.com/appleboy/gin-jwt/v2"
	"github.com/aureleoules/epitaf/models"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)
func handleTasks() {
	router.POST("/tasks", createTaskHandler)
	router.GET("/tasks/:id", getTaskHandler)
	router.GET("/tasks", getTasksHandler)
	router.PUT("/tasks/:id", editTaskHandler)
	router.DELETE("/tasks/:id", deleteTaskHandler)
	router.POST("/tasks/:id/complete", completeTaskHandler)
	router.DELETE("/tasks/:id/complete", unCompleteTaskHandler)
}
func completeTaskHandler(c *gin.Context) {
	claims := jwt.ExtractClaims(c)
	u, err := models.GetUser(claims["login"].(string))
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	task, err := models.GetUserTask(c.Param("id"), u.Login)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusNotFound)
		return
	}
	if task.Completed {
		c.AbortWithStatus(http.StatusNotAcceptable)
		return
	}
	if !u.CanViewTask(*task) {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}
	err = task.Mark(u.Login)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	c.Status(http.StatusOK)
}
func unCompleteTaskHandler(c *gin.Context) {
	claims := jwt.ExtractClaims(c)
	u, err := models.GetUser(claims["login"].(string))
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	task, err := models.GetUserTask(c.Param("id"), u.Login)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusNotFound)
		return
	}
	if !task.Completed {
		c.AbortWithStatus(http.StatusNotAcceptable)
		return
	}
	if !u.CanViewTask(*task) {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}
	err = task.Unmark(u.Login)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	c.Status(http.StatusOK)
}
func editTaskHandler(c *gin.Context) {
	claims := jwt.ExtractClaims(c)
	u, err := models.GetUser(claims["login"].(string))
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	task, err := models.GetUserTask(c.Param("id"), u.Login)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusNotFound)
		return
	}
	var t models.Task
	err = c.BindJSON(&t)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusNotAcceptable)
		return
	}
	if task.CreatedByLogin != u.Login && t.Visibility != "" && task.Visibility != t.Visibility {
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}
	if !u.CanEditTask(*task) {
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}
	update := t.PrepareUpdate(*task, *u)
	update.UpdatedByLogin = u.Login
	update.ShortID = task.ShortID
	err = update.Validate()
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusNotAcceptable)
		return
	}
	err = models.UpdateTask(update)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	zap.S().Info("User ", u.Name, " updated task ", update.ShortID)
	c.Status(http.StatusOK)
}
func deleteTaskHandler(c *gin.Context) {
	claims := jwt.ExtractClaims(c)
	u, err := models.GetUser(claims["login"].(string))
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	task, err := models.GetUserTask(c.Param("id"), u.Login)
	if err != nil {
		zap.S().Error(err)
		c.AbortWithStatus(http.StatusNotFound)
		return
	}
	if !u.CanDeleteTask(*task) {
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}
	err = models.DeleteTask(task.ShortID)
	if err != nil {
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	zap.S().Info("User ", u.Name, " deleted task ", task.ShortID)
	c.Status(http.StatusOK)
}