Full project rename per m's call. Single atomic commit because the codebase rename is a coupled change — go module path, env vars, DB default, Docker artefact names, and on-disk mDock paths all flip together. - go.mod: module mgit.msbls.de/m/mcables → mgit.msbls.de/m/cablegui - cmd/mcables → cmd/cablegui (git mv) - All Go imports rewritten to the new module path - Env vars: MCABLES_ADDR/MCABLES_DB → CABLEGUI_ADDR/CABLEGUI_DB - DB default path: data/mcables.db → data/cablegui.db - Dockerfile + docker-compose.yml: image, container_name, env vars, bind-mount /home/m/stacks/mcables → /home/m/stacks/cablegui, secrets /home/m/secrets/mcables → /home/m/secrets/cablegui - Makefile: bin target + run/build commands point at cmd/cablegui - .gitignore + .dockerignore: /mcables → /cablegui - README, docs/design.md, CLAUDE.md: prose + paths + image name - web/static/index.html: <title> + brand - web/static/main.js + web/web.go: header comment - internal/exporter: Scene.Source "mcables" → "cablegui" - internal/server/export.go: error-detail secrets path - internal/db/migrations/*.sql: header comments (mCables vN → CableGUI vN) Memory group_id kept as "mcables" to preserve existing memory continuity. Documented as historical in CLAUDE.md. go build ./... clean; go test -race ./... green
116 lines
3.3 KiB
Go
116 lines
3.3 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"mgit.msbls.de/m/cablegui/internal/db"
|
|
)
|
|
|
|
type connReqCreate struct {
|
|
FromDeviceID int64 `json:"from_device_id"`
|
|
ToDeviceID int64 `json:"to_device_id"`
|
|
PreferredCableTypeID *int64 `json:"preferred_cable_type_id,omitempty"`
|
|
MustConnect *bool `json:"must_connect,omitempty"`
|
|
Notes string `json:"notes,omitempty"`
|
|
}
|
|
|
|
// connReqPatch uses RawMessage for preferred_cable_type_id so the wire
|
|
// tri-state ({} / null / int) is preserved.
|
|
type connReqPatch struct {
|
|
PreferredCableTypeID json.RawMessage `json:"preferred_cable_type_id,omitempty"`
|
|
MustConnect *bool `json:"must_connect,omitempty"`
|
|
Notes *string `json:"notes,omitempty"`
|
|
}
|
|
|
|
func (h *handlers) listConnectionRequirements(w http.ResponseWriter, r *http.Request) {
|
|
pid, ok := parseInt64Path(r, "pid")
|
|
if !ok {
|
|
writeError(w, db.ErrInvalidInput, "pid must be a positive integer")
|
|
return
|
|
}
|
|
rs, err := h.store.ListConnectionRequirements(pid)
|
|
if err != nil {
|
|
writeError(w, err, nil)
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, rs)
|
|
}
|
|
|
|
func (h *handlers) createConnectionRequirement(w http.ResponseWriter, r *http.Request) {
|
|
pid, ok := parseInt64Path(r, "pid")
|
|
if !ok {
|
|
writeError(w, db.ErrInvalidInput, "pid must be a positive integer")
|
|
return
|
|
}
|
|
var body connReqCreate
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
writeError(w, errors.Join(db.ErrInvalidInput, err), nil)
|
|
return
|
|
}
|
|
cr, err := h.store.CreateConnectionRequirement(pid, db.ConnectionRequirementCreate{
|
|
FromDeviceID: body.FromDeviceID,
|
|
ToDeviceID: body.ToDeviceID,
|
|
PreferredCableTypeID: body.PreferredCableTypeID,
|
|
MustConnect: body.MustConnect,
|
|
Notes: body.Notes,
|
|
})
|
|
if err != nil {
|
|
writeError(w, err, nil)
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusCreated, cr)
|
|
}
|
|
|
|
func (h *handlers) patchConnectionRequirement(w http.ResponseWriter, r *http.Request) {
|
|
pid, ok := parseInt64Path(r, "pid")
|
|
if !ok {
|
|
writeError(w, db.ErrInvalidInput, "pid must be a positive integer")
|
|
return
|
|
}
|
|
id, ok := parseInt64Path(r, "id")
|
|
if !ok {
|
|
writeError(w, db.ErrInvalidInput, "id must be a positive integer")
|
|
return
|
|
}
|
|
var body connReqPatch
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
writeError(w, errors.Join(db.ErrInvalidInput, err), nil)
|
|
return
|
|
}
|
|
ctRef, err := parseFrameRef(body.PreferredCableTypeID)
|
|
if err != nil {
|
|
writeError(w, errors.Join(db.ErrInvalidInput, err), "preferred_cable_type_id must be an integer or null")
|
|
return
|
|
}
|
|
cr, err := h.store.UpdateConnectionRequirement(pid, id, db.ConnectionRequirementUpdate{
|
|
PreferredCableTypeID: ctRef,
|
|
MustConnect: body.MustConnect,
|
|
Notes: body.Notes,
|
|
})
|
|
if err != nil {
|
|
writeError(w, err, nil)
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, cr)
|
|
}
|
|
|
|
func (h *handlers) deleteConnectionRequirement(w http.ResponseWriter, r *http.Request) {
|
|
pid, ok := parseInt64Path(r, "pid")
|
|
if !ok {
|
|
writeError(w, db.ErrInvalidInput, "pid must be a positive integer")
|
|
return
|
|
}
|
|
id, ok := parseInt64Path(r, "id")
|
|
if !ok {
|
|
writeError(w, db.ErrInvalidInput, "id must be a positive integer")
|
|
return
|
|
}
|
|
if err := h.store.DeleteConnectionRequirement(pid, id); err != nil {
|
|
writeError(w, err, nil)
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}
|