Recipe creation is complete! Some minor issues include the "eager-validation." It's better than nothing, but a bit harsh. Also, the redirection and linking to a view page would be nice. Furthermore, tags and images are not implemented yet. Will need that in the future!
31 lines
803 B
Go
31 lines
803 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
domain "github.com/haydenhargreaves/Potion/internal/domain/server"
|
|
)
|
|
|
|
const CREATE_SUCCESS_HTML = `
|
|
<p id="response" class="text-sm text-green-600 px-4 py-1 bg-green-100 rounded-full w-fit">
|
|
Success! Your new masterpiece was created!
|
|
</p>
|
|
`
|
|
|
|
const CREATE_ERROR_HTML = `
|
|
<p id="response" class="text-sm text-red-500 px-4 py-1 bg-red-100 rounded-full w-fit">
|
|
Uh oh! Something went wrong when creating your recipe. Please try again. %s
|
|
</p>
|
|
`
|
|
|
|
func CreateRecipe(ctx *gin.Context) {
|
|
deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
|
_, err := deps.RecipeService.CreateRecipe(ctx)
|
|
if err != nil {
|
|
ctx.String(http.StatusOK, CREATE_ERROR_HTML, err.Error())
|
|
return
|
|
}
|
|
ctx.String(http.StatusOK, CREATE_SUCCESS_HTML)
|
|
}
|