Initialize work order management system with database schema, API handlers, web client, and Docker configuration.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"workorders/internal/model"
|
||||
)
|
||||
|
||||
func respond(w http.ResponseWriter, code int, data any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
json.NewEncoder(w).Encode(map[string]any{"data": data})
|
||||
}
|
||||
|
||||
func respondError(w http.ResponseWriter, code int, msg string) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
fmt.Fprintf(w, `{"error":%q}`, msg)
|
||||
}
|
||||
|
||||
func intParam(r *http.Request, key string) (int, error) {
|
||||
return strconv.Atoi(chi.URLParam(r, key))
|
||||
}
|
||||
|
||||
func decode(r *http.Request, v any) error {
|
||||
return json.NewDecoder(r.Body).Decode(v)
|
||||
}
|
||||
|
||||
func userFromCtx(r *http.Request) model.UserClaims {
|
||||
u, _ := r.Context().Value(model.CtxUserKey).(model.UserClaims)
|
||||
return u
|
||||
}
|
||||
Reference in New Issue
Block a user