37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
"workorders/internal/model"
|
|
)
|
|
|
|
type RegistryHandler struct{ db *sqlx.DB }
|
|
|
|
func NewRegistryHandler(db *sqlx.DB) *RegistryHandler { return &RegistryHandler{db: db} }
|
|
|
|
func (h *RegistryHandler) People(w http.ResponseWriter, r *http.Request) {
|
|
var rows []model.RegistryPerson
|
|
h.db.Select(&rows, `SELECT id,name,role,email,phone FROM resource_people WHERE active=1 ORDER BY name`)
|
|
respond(w, http.StatusOK, rows)
|
|
}
|
|
|
|
func (h *RegistryHandler) Vehicles(w http.ResponseWriter, r *http.Request) {
|
|
var rows []model.RegistryVehicle
|
|
h.db.Select(&rows, `SELECT id,unit_number,description,vehicle_type FROM resource_vehicles WHERE active=1 ORDER BY unit_number`)
|
|
respond(w, http.StatusOK, rows)
|
|
}
|
|
|
|
func (h *RegistryHandler) Equipment(w http.ResponseWriter, r *http.Request) {
|
|
var rows []model.RegistryEquipment
|
|
h.db.Select(&rows, `SELECT id,name,asset_tag,category FROM resource_equipment WHERE active=1 ORDER BY name`)
|
|
respond(w, http.StatusOK, rows)
|
|
}
|
|
|
|
func (h *RegistryHandler) Materials(w http.ResponseWriter, r *http.Request) {
|
|
var rows []model.RegistryMaterial
|
|
h.db.Select(&rows, `SELECT id,name,unit,part_number FROM resource_materials WHERE active=1 ORDER BY name`)
|
|
respond(w, http.StatusOK, rows)
|
|
}
|