sprechstunden-go/controllers/confirmRequestHandler.go
2022-09-07 21:48:40 +02:00

31 lines
770 B
Go

package controllers
import (
"html/template"
"net/http"
)
func (b *BaseHandler) ConfirmRequestHandler(w http.ResponseWriter, req *http.Request) {
secret := req.FormValue("code")
request, err := b.requestRepo.FindBySecret(secret)
if err != nil {
w.WriteHeader(http.StatusNotFound)
tmpl, _ := template.ParseFiles("templates/requestNotFound.html")
tmpl.Execute(w, struct{}{})
}
err = b.requestRepo.Execute(request)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
tmpl, _ := template.ParseFiles("templates/executeFailure.html")
tmpl.Execute(w, err.Error())
return
}
tmpl, err := template.ParseFiles("templates/executeSuccess.html")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
tmpl.Execute(w, struct{}{})
}