2024-03-20 17:54:23 -07:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
2024-04-20 08:09:24 -07:00
|
|
|
"git.jamestombleson.com/jtom38/go-cook/internal/domain"
|
2024-04-05 17:50:29 -07:00
|
|
|
|
2024-03-20 17:54:23 -07:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (h *Handler) DemoHello(c echo.Context) error {
|
2024-03-31 17:48:44 -07:00
|
|
|
return c.JSON(http.StatusOK, domain.HelloWhoResponse{
|
2024-04-21 08:59:07 -07:00
|
|
|
BaseResponse: domain.BaseResponse{
|
|
|
|
Success: true,
|
|
|
|
Message: "Hello world!",
|
|
|
|
},
|
2024-03-23 08:26:49 -07:00
|
|
|
})
|
2024-03-20 17:54:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handler) HelloWho(c echo.Context) error {
|
2024-03-23 08:26:49 -07:00
|
|
|
name := c.Param("who")
|
2024-03-31 17:48:44 -07:00
|
|
|
return c.JSON(http.StatusOK, domain.HelloWhoResponse{
|
2024-04-21 08:59:07 -07:00
|
|
|
BaseResponse: domain.BaseResponse{
|
|
|
|
Success: true,
|
|
|
|
Message: fmt.Sprintf("Hello, %s", name),
|
|
|
|
},
|
2024-03-23 08:26:49 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handler) HelloBody(c echo.Context) error {
|
2024-03-31 17:48:44 -07:00
|
|
|
request := domain.HelloBodyRequest{}
|
2024-03-23 08:26:49 -07:00
|
|
|
err := (&echo.DefaultBinder{}).BindBody(c, &request)
|
|
|
|
if err != nil {
|
2024-04-21 08:59:07 -07:00
|
|
|
return h.InternalServerErrorResponse(c, err.Error())
|
2024-03-23 08:26:49 -07:00
|
|
|
}
|
2024-03-27 21:55:25 -07:00
|
|
|
|
2024-03-31 17:48:44 -07:00
|
|
|
return c.JSON(http.StatusOK, domain.HelloWhoResponse{
|
2024-04-21 08:59:07 -07:00
|
|
|
BaseResponse: domain.BaseResponse{
|
|
|
|
Success: true,
|
|
|
|
Message: fmt.Sprintf("Hello, %s", request.Name),
|
|
|
|
},
|
2024-03-23 08:26:49 -07:00
|
|
|
})
|
2024-03-20 17:54:23 -07:00
|
|
|
}
|
2024-03-26 17:54:22 -07:00
|
|
|
|
2024-03-27 21:55:25 -07:00
|
|
|
func (h *Handler) ProtectedRoute(c echo.Context) error {
|
2024-03-29 14:49:57 -07:00
|
|
|
token, err := h.getJwtToken(c)
|
|
|
|
if err != nil {
|
2024-03-31 17:48:44 -07:00
|
|
|
h.ReturnUnauthorizedResponse(c, err.Error())
|
|
|
|
}
|
|
|
|
|
2024-04-05 17:50:29 -07:00
|
|
|
err = token.IsValid(domain.ScopeRecipeRead)
|
2024-03-31 17:48:44 -07:00
|
|
|
if err != nil {
|
|
|
|
h.ReturnUnauthorizedResponse(c, ErrJwtScopeMissing)
|
2024-03-29 14:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, token)
|
2024-03-27 21:55:25 -07:00
|
|
|
}
|