Create logic and endpoint for confirming report location

This commit is contained in:
Eli Ribble 2026-03-04 00:22:46 +00:00
parent b0fce4f363
commit c7dd53b6eb
No known key found for this signature in database
6 changed files with 63 additions and 18 deletions

View file

@ -5,9 +5,12 @@ import (
"net/http" "net/http"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http" nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/gorilla/schema"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
var decoder = schema.NewDecoder()
type handlerFunctionGet[T any] func(context.Context, *http.Request) (*Response[T], *nhttp.ErrorWithStatus) type handlerFunctionGet[T any] func(context.Context, *http.Request) (*Response[T], *nhttp.ErrorWithStatus)
func MakeGet[T any](f handlerFunctionGet[T]) http.HandlerFunc { func MakeGet[T any](f handlerFunctionGet[T]) http.HandlerFunc {
@ -25,3 +28,30 @@ func MakeGet[T any](f handlerFunctionGet[T]) http.HandlerFunc {
}) })
} }
} }
type handlerFunctionPost[T any] func(context.Context, *http.Request, T) (string, *nhttp.ErrorWithStatus)
func MakePost[T any](f handlerFunctionPost[T]) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
RespondError(w, "Failed to parse form", err, http.StatusBadRequest)
return
}
var content T
err = decoder.Decode(&content, r.PostForm)
if err != nil {
RespondError(w, "Failed to decode form", err, http.StatusBadRequest)
return
}
ctx := r.Context()
path, e := f(ctx, r, content)
if e != nil {
http.Error(w, e.Error(), e.Status)
return
}
http.Redirect(w, r, path, http.StatusFound)
}
}

View file

@ -62,12 +62,14 @@
<!-- Action Buttons --> <!-- Action Buttons -->
<div class="action-buttons"> <div class="action-buttons">
<a <form
href="{{ call .URL.RMO.Mailer.Evidence .C.PublicID }}" action="{{ call .URL.RMO.Mailer.Confirm .C.PublicID }}"
class="btn btn-success flex-grow-1" method="POST"
> >
<button type="submit" class="btn btn-success flex-grow-1">
<i class="bi bi-check-circle me-2"></i> Correct <i class="bi bi-check-circle me-2"></i> Correct
</a> </button>
</form>
<a <a
href="{{ call .URL.RMO.Mailer.Update .C.PublicID }}" href="{{ call .URL.RMO.Mailer.Update .C.PublicID }}"
class="btn btn-outline-primary flex-grow-1" class="btn btn-outline-primary flex-grow-1"

View file

@ -69,6 +69,7 @@ func newContentURLRMO() contentURLRMO {
} }
type contentURLRMOMailer struct { type contentURLRMOMailer struct {
AppointmentConfirmed urlWithParams
Confirm urlWithParams Confirm urlWithParams
Contribute urlWithParams Contribute urlWithParams
Evidence urlWithParams Evidence urlWithParams
@ -79,6 +80,7 @@ type contentURLRMOMailer struct {
func newContentURLRMOMailer() contentURLRMOMailer { func newContentURLRMOMailer() contentURLRMOMailer {
return contentURLRMOMailer{ return contentURLRMOMailer{
AppointmentConfirmed: makeURLWithParams(config.MakeURLReport, "/mailer/%s/appointment-confirmed"),
Confirm: makeURLWithParams(config.MakeURLReport, "/mailer/%s/confirm"), Confirm: makeURLWithParams(config.MakeURLReport, "/mailer/%s/confirm"),
Contribute: makeURLWithParams(config.MakeURLReport, "/mailer/%s/contribute"), Contribute: makeURLWithParams(config.MakeURLReport, "/mailer/%s/contribute"),
Evidence: makeURLWithParams(config.MakeURLReport, "/mailer/%s/evidence"), Evidence: makeURLWithParams(config.MakeURLReport, "/mailer/%s/evidence"),

View file

@ -134,3 +134,14 @@ func getMailerUpdate(ctx context.Context, r *http.Request) (*html.Response[conte
}, },
), nil ), nil
} }
type formMailerConfirm struct{}
func postMailerConfirm(ctx context.Context, r *http.Request, form formMailerConfirm) (string, *nhttp.ErrorWithStatus) {
log.Info().Msg("Fake confirm location")
public_id := chi.URLParam(r, "public_id")
if public_id == "" {
return "", nhttp.NewErrorStatus(http.StatusBadRequest, "No 'public_id' in the url params")
}
return config.MakeURLReport("/mailer/%s/evidence", public_id), nil
}

View file

@ -33,7 +33,7 @@ func Router() chi.Router {
r.Get("/email/unsubscribe/report/{report_id}", getEmailReportUnsubscribe) r.Get("/email/unsubscribe/report/{report_id}", getEmailReportUnsubscribe)
r.Get("/image/{uuid}", getImageByUUID) r.Get("/image/{uuid}", getImageByUUID)
r.Get("/mailer/{public_id}", html.MakeGet(getMailer)) r.Get("/mailer/{public_id}", html.MakeGet(getMailer))
r.Get("/mailer/{public_id}/confirm", html.MakeGet(getMailerConfirm)) r.Post("/mailer/{public_id}/confirm", html.MakePost(postMailerConfirm))
r.Get("/mailer/{public_id}/contribute", html.MakeGet(getMailerContribute)) r.Get("/mailer/{public_id}/contribute", html.MakeGet(getMailerContribute))
r.Get("/mailer/{public_id}/evidence", html.MakeGet(getMailerEvidence)) r.Get("/mailer/{public_id}/evidence", html.MakeGet(getMailerEvidence))
r.Get("/mailer/{public_id}/schedule", html.MakeGet(getMailerSchedule)) r.Get("/mailer/{public_id}/schedule", html.MakeGet(getMailerSchedule))