Add migration scripts, activity handler, and registry components for equipment, materials, and people
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"workorders/internal/model"
|
||||
)
|
||||
|
||||
type ActivityHandler struct{ db *sqlx.DB }
|
||||
|
||||
func NewActivityHandler(db *sqlx.DB) *ActivityHandler { return &ActivityHandler{db: db} }
|
||||
|
||||
func (h *ActivityHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
woID, err := intParam(r, "id")
|
||||
if err != nil {
|
||||
respondError(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
var rows []model.AuditEntry
|
||||
err = h.db.Select(&rows, `
|
||||
SELECT
|
||||
a.id,
|
||||
a.action,
|
||||
ISNULL(a.old_value,'') AS old_value,
|
||||
ISNULL(a.new_value,'') AS new_value,
|
||||
ISNULL(u.display_name, ISNULL(u.username, CAST(a.performed_by AS NVARCHAR(100)))) AS performed_by,
|
||||
a.performed_at
|
||||
FROM wo_audit_log a
|
||||
LEFT JOIN users u ON u.id = a.performed_by
|
||||
WHERE a.wo_id = @p1
|
||||
ORDER BY a.performed_at DESC`,
|
||||
woID)
|
||||
if err != nil {
|
||||
respondError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
if rows == nil {
|
||||
rows = []model.AuditEntry{}
|
||||
}
|
||||
respond(w, http.StatusOK, rows)
|
||||
}
|
||||
Reference in New Issue
Block a user