2024-05-24 17:44:24 +00:00
|
|
|
package presenters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CreateRequest[T any](r *http.Request) (*T, error) {
|
|
|
|
defer r.Body.Close()
|
|
|
|
|
|
|
|
data, err := io.ReadAll(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error read request body. %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var request T
|
|
|
|
|
|
|
|
if err := json.Unmarshal(data, &request); err != nil {
|
|
|
|
return nil, fmt.Errorf("error unmarshal join request. %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &request, nil
|
|
|
|
}
|
2024-05-25 20:38:47 +00:00
|
|
|
|
|
|
|
type ok struct {
|
2024-05-27 18:08:19 +00:00
|
|
|
Ok bool `json:"ok"`
|
2024-05-25 20:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ResponseOK() ([]byte, error) {
|
|
|
|
return json.Marshal(&ok{Ok: true})
|
|
|
|
}
|