Create logic and endpoint for confirming report location
This commit is contained in:
parent
b0fce4f363
commit
c7dd53b6eb
6 changed files with 63 additions and 18 deletions
|
|
@ -5,9 +5,12 @@ import (
|
|||
"net/http"
|
||||
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/gorilla/schema"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var decoder = schema.NewDecoder()
|
||||
|
||||
type handlerFunctionGet[T any] func(context.Context, *http.Request) (*Response[T], *nhttp.ErrorWithStatus)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,12 +62,14 @@
|
|||
|
||||
<!-- Action Buttons -->
|
||||
<div class="action-buttons">
|
||||
<a
|
||||
href="{{ call .URL.RMO.Mailer.Evidence .C.PublicID }}"
|
||||
class="btn btn-success flex-grow-1"
|
||||
<form
|
||||
action="{{ call .URL.RMO.Mailer.Confirm .C.PublicID }}"
|
||||
method="POST"
|
||||
>
|
||||
<i class="bi bi-check-circle me-2"></i> Correct
|
||||
</a>
|
||||
<button type="submit" class="btn btn-success flex-grow-1">
|
||||
<i class="bi bi-check-circle me-2"></i> Correct
|
||||
</button>
|
||||
</form>
|
||||
<a
|
||||
href="{{ call .URL.RMO.Mailer.Update .C.PublicID }}"
|
||||
class="btn btn-outline-primary flex-grow-1"
|
||||
|
|
|
|||
26
html/url.go
26
html/url.go
|
|
@ -69,22 +69,24 @@ func newContentURLRMO() contentURLRMO {
|
|||
}
|
||||
|
||||
type contentURLRMOMailer struct {
|
||||
Confirm urlWithParams
|
||||
Contribute urlWithParams
|
||||
Evidence urlWithParams
|
||||
Root urlWithParams
|
||||
Schedule urlWithParams
|
||||
Update urlWithParams
|
||||
AppointmentConfirmed urlWithParams
|
||||
Confirm urlWithParams
|
||||
Contribute urlWithParams
|
||||
Evidence urlWithParams
|
||||
Root urlWithParams
|
||||
Schedule urlWithParams
|
||||
Update urlWithParams
|
||||
}
|
||||
|
||||
func newContentURLRMOMailer() contentURLRMOMailer {
|
||||
return contentURLRMOMailer{
|
||||
Confirm: makeURLWithParams(config.MakeURLReport, "/mailer/%s/confirm"),
|
||||
Contribute: makeURLWithParams(config.MakeURLReport, "/mailer/%s/contribute"),
|
||||
Evidence: makeURLWithParams(config.MakeURLReport, "/mailer/%s/evidence"),
|
||||
Root: makeURLWithParams(config.MakeURLReport, "/mailer/%s"),
|
||||
Schedule: makeURLWithParams(config.MakeURLReport, "/mailer/%s/schedule"),
|
||||
Update: makeURLWithParams(config.MakeURLReport, "/mailer/%s/update"),
|
||||
AppointmentConfirmed: makeURLWithParams(config.MakeURLReport, "/mailer/%s/appointment-confirmed"),
|
||||
Confirm: makeURLWithParams(config.MakeURLReport, "/mailer/%s/confirm"),
|
||||
Contribute: makeURLWithParams(config.MakeURLReport, "/mailer/%s/contribute"),
|
||||
Evidence: makeURLWithParams(config.MakeURLReport, "/mailer/%s/evidence"),
|
||||
Root: makeURLWithParams(config.MakeURLReport, "/mailer/%s"),
|
||||
Schedule: makeURLWithParams(config.MakeURLReport, "/mailer/%s/schedule"),
|
||||
Update: makeURLWithParams(config.MakeURLReport, "/mailer/%s/update"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue