diff options
author | Julien Dessaux | 2025-02-23 22:06:46 +0100 |
---|---|---|
committer | Julien Dessaux | 2025-02-23 22:06:46 +0100 |
commit | a83296b79ac7eb851a44600fb7ccf6c1a200e2bc (patch) | |
tree | 25d69d9c8a0b4905761d6089acacc454fecf55dd /pkg/webui/states.go | |
parent | chore(tfstated): change database state id and version id formats to uuidv7 (diff) | |
download | tfstated-a83296b79ac7eb851a44600fb7ccf6c1a200e2bc.tar.gz tfstated-a83296b79ac7eb851a44600fb7ccf6c1a200e2bc.tar.bz2 tfstated-a83296b79ac7eb851a44600fb7ccf6c1a200e2bc.zip |
[webui] refactored states and versions routes
Diffstat (limited to 'pkg/webui/states.go')
-rw-r--r-- | pkg/webui/states.go | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/pkg/webui/states.go b/pkg/webui/states.go index c68b2c9..64b7967 100644 --- a/pkg/webui/states.go +++ b/pkg/webui/states.go @@ -10,6 +10,7 @@ import ( "git.adyxax.org/adyxax/tfstated/pkg/database" "git.adyxax.org/adyxax/tfstated/pkg/model" + "go.n16f.net/uuid" ) type StatesPage struct { @@ -22,6 +23,7 @@ type StatesPage struct { } var statesTemplates = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/states.html")) +var statesIdTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/statesId.html")) func handleStatesGET(db *database.DB) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -86,7 +88,48 @@ func handleStatesPOST(db *database.DB) http.Handler { }) return } - destination := path.Join("/version", version.Id.String()) + destination := path.Join("/versions", version.Id.String()) http.Redirect(w, r, destination, http.StatusFound) }) } + +func handleStatesIdGET(db *database.DB) http.Handler { + type StatesData struct { + Page *Page + State *model.State + Usernames map[string]string + Versions []model.Version + } + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var stateId uuid.UUID + if err := stateId.Parse(r.PathValue("id")); err != nil { + errorResponse(w, http.StatusBadRequest, err) + return + } + state, err := db.LoadStateById(stateId) + if err != nil { + errorResponse(w, http.StatusInternalServerError, err) + return + } + versions, err := db.LoadVersionsByState(state) + if err != nil { + errorResponse(w, http.StatusInternalServerError, err) + return + } + usernames, err := db.LoadAccountUsernames() + if err != nil { + errorResponse(w, http.StatusInternalServerError, err) + return + } + render(w, statesIdTemplate, http.StatusOK, StatesData{ + Page: makePage(r, &Page{ + Precedent: "/states", + Section: "states", + Title: state.Path, + }), + State: state, + Usernames: usernames, + Versions: versions, + }) + }) +} |