Write test skeleton

This commit is contained in:
2024-12-28 17:58:01 +01:00
parent a22f3e5a71
commit f1a951ce81
4 changed files with 104 additions and 11 deletions

View File

@ -4,8 +4,7 @@ import (
api "code.dlmw.ch/dlmw/qv/internal"
"code.dlmw.ch/dlmw/qv/internal/validator"
"encoding/json"
"errors"
"github.com/go-playground/form/v4"
"io"
"net/http"
)
@ -43,19 +42,14 @@ func (app *application) unprocessableEntityError(w http.ResponseWriter, v valida
json.NewEncoder(w).Encode(response)
}
func (app *application) decodePostForm(r *http.Request, dst any) error {
err := r.ParseForm()
func (app *application) unmarshalRequest(r *http.Request, dst any) error {
body, err := io.ReadAll(r.Body)
if err != nil {
return err
}
err = app.formDecoder.Decode(dst, r.PostForm)
err = json.Unmarshal(body, &dst)
if err != nil {
var invalidDecoderError *form.InvalidDecoderError
if errors.As(err, &invalidDecoderError) {
panic(err)
}
return err
}