Write test skeleton
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user