This commit is contained in:
Jabberwocky238
2026-07-29 06:51:43 -04:00
parent 68cda1972c
commit 319f5dd148
64 changed files with 4952 additions and 2186 deletions
+69
View File
@@ -0,0 +1,69 @@
package gitctl
import (
"context"
"encoding/json"
"strconv"
statectrl "simplegit/state/ctrl"
)
type backend struct {
manage *manageClient
db *dbReader
}
// dbReader preserves the TUI's existing query-facing API, but all operations
// now execute remotely through ManageService.Ctrl.
type dbReader struct{ manage *manageClient }
func newDBReader(manage *manageClient) *dbReader { return &dbReader{manage: manage} }
type repoRow = statectrl.RepoRow
type nsRow = statectrl.NSRow
type grantRow = statectrl.GrantRow
type sshKeyRow = statectrl.SSHKeyRow
func callCtrl[T any](r *dbReader, op string, args ...string) (T, error) {
var result T
data, err := r.manage.Ctrl(context.Background(), op, args...)
if err != nil {
return result, err
}
if err := json.Unmarshal(data, &result); err != nil {
return result, err
}
return result, nil
}
func (r *dbReader) listRepos() ([]repoRow, error) {
return callCtrl[[]repoRow](r, statectrl.OpListRepos)
}
func (r *dbReader) listUsers() ([]nsRow, error) {
return callCtrl[[]nsRow](r, statectrl.OpListNS)
}
func (r *dbReader) grantsForRepo(ns, name string) ([]grantRow, error) {
return callCtrl[[]grantRow](r, statectrl.OpGrantsForRepo, ns, name)
}
func (r *dbReader) grantsForNS(ns string) ([]grantRow, error) {
return callCtrl[[]grantRow](r, statectrl.OpGrantsForNS, ns)
}
func (r *dbReader) listAllGrants() ([]grantRow, error) {
return callCtrl[[]grantRow](r, statectrl.OpListGrants)
}
func (r *dbReader) grantsForKey(id int64) ([]grantRow, error) {
return callCtrl[[]grantRow](r, statectrl.OpGrantsForKey, strconv.FormatInt(id, 10))
}
func (r *dbReader) listSSHKeys() ([]sshKeyRow, error) {
return callCtrl[[]sshKeyRow](r, statectrl.OpListSSHKeys)
}
func (r *dbReader) sshKeyByID(id int64) (sshKeyRow, error) {
return callCtrl[sshKeyRow](r, statectrl.OpSSHKeyByID, strconv.FormatInt(id, 10))
}