package handlers import ( "fmt" "net/http" "github.com/gin-gonic/gin" domain "github.com/haydenhargreaves/Potion/internal/domain/server" ) const CREATE_SUCCESS_HTML = `

Success! Your new masterpiece was created!

` const CREATE_ERROR_HTML = `

Uh oh! Something went wrong when creating your recipe. Please try again. %s

` func CreateRecipe(ctx *gin.Context) { deps := ctx.MustGet("deps").(*domain.InjectedDependencies) recipe, err := deps.RecipeService.CreateRecipe(ctx) if err != nil { ctx.String(http.StatusOK, CREATE_ERROR_HTML, err.Error()) return } // Send HTMX redirection url := fmt.Sprintf(domain.WEB_RECIPE, recipe.Id) ctx.Header("HX-Redirect", url) ctx.Status(http.StatusCreated) }