Parse the request body to get the PhoneNumber and Input text

This commit is contained in:
Alfred Kamanda 2024-09-11 15:40:49 +03:00
parent 7438531900
commit 44015b1c76
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -2,8 +2,8 @@ package http
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"git.defalsify.org/vise.git/db"
"git.defalsify.org/vise.git/engine"
@ -25,20 +25,31 @@ type DefaultRequestParser struct {
}
func(rp *DefaultRequestParser) GetSessionId(rq *http.Request) (string, error) {
v := rq.Header.Get("X-Vise-Session")
if v == "" {
return "", fmt.Errorf("no session found")
if err := rq.ParseForm(); err != nil {
return "", fmt.Errorf("failed to parse form data: %v", err)
}
return v, nil
phoneNumber := rq.FormValue("phoneNumber")
if phoneNumber == "" {
return "", fmt.Errorf("no phone number found")
}
return phoneNumber, nil
}
func(rp *DefaultRequestParser) GetInput(rq *http.Request) ([]byte, error) {
defer rq.Body.Close()
v, err := ioutil.ReadAll(rq.Body)
if err != nil {
return nil, err
if err := rq.ParseForm(); err != nil {
return nil, fmt.Errorf("failed to parse form data: %v", err)
}
return v, nil
text := rq.FormValue("text")
parts := strings.Split(text, "*")
if len(parts) == 0 {
return nil, fmt.Errorf("no input found")
}
return []byte(parts[len(parts)-1]), nil
}
type SessionHandler struct {