htmgo/sandbox/partials/patient/create.go

39 lines
856 B
Go
Raw Normal View History

2024-09-11 21:08:35 +00:00
package patient
import (
2024-09-17 17:13:22 +00:00
"github.com/labstack/echo/v4"
2024-09-14 00:05:55 +00:00
"github.com/maddalax/htmgo/framework/h"
2024-09-13 21:33:50 +00:00
"starter-template/features/patient"
"starter-template/partials/sheet"
2024-09-11 21:08:35 +00:00
)
2024-09-17 17:13:22 +00:00
func Create(ctx echo.Context) *h.Partial {
2024-09-11 21:08:35 +00:00
name := ctx.FormValue("name")
reason := ctx.FormValue("reason-for-visit")
location := ctx.FormValue("location-name")
err := patient.NewService(ctx).Create(patient.CreatePatientRequest{
Name: name,
ReasonForVisit: reason,
LocationName: location,
2024-09-11 21:08:35 +00:00
})
if err != nil {
ctx.Status(500)
return h.NewPartialWithHeaders(h.NewHeaders(""),
h.Div(
h.Text("Error creating patient"),
h.Class("text-red-500"),
),
)
}
2024-09-12 02:06:34 +00:00
headers := h.CombineHeaders(h.PushQsHeader(ctx, "adding", ""), &map[string]string{
2024-09-21 16:52:56 +00:00
"HX-HxTrigger": "patient-added",
2024-09-12 02:06:34 +00:00
})
2024-09-11 21:08:35 +00:00
2024-09-12 02:06:34 +00:00
return h.NewPartialWithHeaders(
headers,
sheet.Close(ctx))
2024-09-11 21:08:35 +00:00
}