sprechstunden-go/controllers/confirmRequestHandler.go

35 lines
1,021 B
Go

package controllers
import (
"log"
"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)
templateError := Templates.ExecuteTemplate(w, "requestNotFound.html", struct{}{})
if templateError != nil {
log.Printf("Error executing template requestNotFound.html: %s", templateError.Error())
}
return
}
err = b.requestRepo.Execute(request)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
templateError := Templates.ExecuteTemplate(w, "executeFailure.html", err.Error())
if templateError != nil {
log.Printf("Error executing template executeFailure.html: %s", templateError.Error())
}
return
}
templateError := Templates.ExecuteTemplate(w, "executeSuccess.html", struct{}{})
if templateError != nil {
log.Printf("Error executing template executeSuccess.html: %s", templateError.Error())
}
}