This commit is contained in:
2026-03-15 20:24:29 -04:00
parent c84bc2522e
commit d40f8fc375
20 changed files with 2316 additions and 1240 deletions

View File

@@ -5,9 +5,10 @@ import (
"net/http"
"net/url"
"strconv"
"time"
)
// writeJSON writes a JSON response
// writeJSON writes a JSON response (deprecated - used by tests only)
func writeJSON(w http.ResponseWriter, status int, data any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
@@ -16,7 +17,7 @@ func writeJSON(w http.ResponseWriter, status int, data any) {
}
}
// writeJSONError writes a JSON error response
// writeJSONError writes a JSON error response (deprecated - used by tests only)
func writeJSONError(w http.ResponseWriter, status int, message string) {
writeJSON(w, status, ErrorResponse{
Code: status,
@@ -24,14 +25,14 @@ func writeJSONError(w http.ResponseWriter, status int, message string) {
})
}
// QueryParams represents parsed query parameters
// QueryParams represents parsed query parameters (deprecated - used by tests only)
type QueryParams struct {
Page int64
Limit int64
Page int64
Limit int64
Search *string
}
// parseQueryParams parses URL query parameters
// parseQueryParams parses URL query parameters (deprecated - used by tests only)
func parseQueryParams(query url.Values, defaultLimit int64) QueryParams {
page, _ := strconv.ParseInt(query.Get("page"), 10, 64)
if page == 0 {
@@ -56,4 +57,13 @@ func parseQueryParams(query url.Values, defaultLimit int64) QueryParams {
// ptrOf returns a pointer to the given value
func ptrOf[T any](v T) *T {
return &v
}
// parseTime parses a string to time.Time
func parseTime(s string) time.Time {
t, _ := time.Parse(time.RFC3339, s)
if t.IsZero() {
t, _ = time.Parse("2006-01-02T15:04:05", s)
}
return t
}