mirror of
https://github.com/zoriya/vex.git
synced 2026-06-04 19:05:55 +00:00
Use current user in add feed route
This commit is contained in:
+7
-6
@@ -4,21 +4,22 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type AddFeedDto struct {
|
type AddFeedDto struct {
|
||||||
Link string `json:"link" validate:"required,url"`
|
Link string `json:"link" validate:"required,url"`
|
||||||
Tags []string `json:"tags" validate:"required"`
|
Tags []string `json:"tags" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) AddFeed(c echo.Context) error {
|
func (h *Handler) AddFeed(c echo.Context) error {
|
||||||
user := uuid.New()
|
user, err := GetCurrentUserId(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var req AddFeedDto
|
var req AddFeedDto
|
||||||
err := c.Bind(&req)
|
err = c.Bind(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
@@ -34,6 +35,6 @@ func (h *Handler) AddFeed(c echo.Context) error {
|
|||||||
return c.JSON(201, feed)
|
return c.JSON(201, feed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) RegisterFeedsRoutes(echo *echo.Echo, restricted *echo.Group) {
|
func (h *Handler) RegisterFeedsRoutes(echo *echo.Echo, r *echo.Group) {
|
||||||
restricted.POST("/feeds", h.AddFeed)
|
r.POST("/feeds", h.AddFeed)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user