tsk-13: Retrieve scheduled message endpoint (#36)

Closes #13

Reviewed-on: phoenix/textsender-api#36
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-12 19:25:54 +00:00
committed by phoenix
parent a37f1627fc
commit 7f588cc80c
8 changed files with 184 additions and 5 deletions
+21 -3
View File
@@ -1,8 +1,11 @@
package handler
import "encoding/json"
import "log"
import "net/http"
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func ExtractFromRequest(r *http.Request, reqItem interface{}) error {
err := json.NewDecoder(r.Body).Decode(&reqItem)
@@ -21,3 +24,18 @@ func RespondWithJSON(w http.ResponseWriter, statusCode int, data interface{}) {
log.Printf("Error encoding JSON: %v", err)
}
}
// Gets the query parameter from the URL
func ParseQueryParams(r *http.Request, query string) (*string, error) {
queryParams := r.URL.Query()
if _, exists := queryParams[query]; exists {
value := queryParams.Get(query)
if len(value) == 0 {
return nil, fmt.Errorf("Value of query parameter is empty")
} else {
return &value, nil
}
} else {
return nil, fmt.Errorf("Could not find query %s", query)
}
}