From d4efc62df1480eb33a154daa031a1e5de9ab46f7 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Wed, 16 Nov 2022 21:54:05 -0800 Subject: [PATCH] Add client-side code to ask for feedback when uninstalling --- backend/server/server.go | 10 ++-------- client/cmd/uninstall.go | 18 +++++++++++++++++- client/lib/goldens/testUninstall-uninstall | 3 ++- shared/data.go | 6 ++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/backend/server/server.go b/backend/server/server.go index 9090389..2e77fa4 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -42,12 +42,6 @@ type UsageData struct { Version string `json:"version"` } -type Feedback struct { - UserId string `json:"user_id" gorm:"not null"` - Date time.Time `json:"date" gorm:"not null"` - Feedback string `json:"feedback"` -} - func getRequiredQueryParam(r *http.Request, queryParam string) string { val := r.URL.Query().Get(queryParam) if val == "" { @@ -404,7 +398,7 @@ func OpenDB() (*gorm.DB, error) { db.AutoMigrate(&UsageData{}) db.AutoMigrate(&shared.DumpRequest{}) db.AutoMigrate(&shared.DeletionRequest{}) - db.AutoMigrate(&Feedback{}) + db.AutoMigrate(&shared.Feedback{}) db.Exec("PRAGMA journal_mode = WAL") return db, nil } @@ -620,7 +614,7 @@ func feedbackHandler(w http.ResponseWriter, r *http.Request) { if err != nil { panic(err) } - var feedback Feedback + var feedback shared.Feedback err = json.Unmarshal(data, &feedback) if err != nil { panic(fmt.Sprintf("feedbackHandler: body=%#v, err=%v", data, err)) diff --git a/client/cmd/uninstall.go b/client/cmd/uninstall.go index bc5118b..628ace4 100644 --- a/client/cmd/uninstall.go +++ b/client/cmd/uninstall.go @@ -2,12 +2,16 @@ package cmd import ( "bufio" + "encoding/json" "fmt" "os" "strings" + "time" + "github.com/ddworken/hishtory/client/data" "github.com/ddworken/hishtory/client/hctx" "github.com/ddworken/hishtory/client/lib" + "github.com/ddworken/hishtory/shared" "github.com/spf13/cobra" ) @@ -15,6 +19,7 @@ var uninstallCmd = &cobra.Command{ Use: "uninstall", Short: "Completely uninstall hiSHtory and remove your shell history", Run: func(cmd *cobra.Command, args []string) { + ctx := hctx.MakeContext() fmt.Printf("Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]") reader := bufio.NewReader(os.Stdin) resp, err := reader.ReadString('\n') @@ -23,7 +28,18 @@ var uninstallCmd = &cobra.Command{ fmt.Printf("Aborting uninstall per user response of %#v\n", strings.TrimSpace(resp)) return } - lib.CheckFatalError(lib.Uninstall(hctx.MakeContext())) + fmt.Printf("Do you have any feedback on why you're uninstallying hiSHtory? Type any feedback and then hit enter.\nFeedback: ") + feedbackTxt, err := reader.ReadString('\n') + lib.CheckFatalError(err) + feedback := shared.Feedback{ + Date: time.Now(), + Feedback: feedbackTxt, + UserId: data.UserId(hctx.GetConf(ctx).UserSecret), + } + reqBody, err := json.Marshal(feedback) + lib.CheckFatalError(err) + _, _ = lib.ApiPost("/api/v1/feedback", "application/json", reqBody) + lib.CheckFatalError(lib.Uninstall(ctx)) }, } diff --git a/client/lib/goldens/testUninstall-uninstall b/client/lib/goldens/testUninstall-uninstall index c748814..fe18eed 100644 --- a/client/lib/goldens/testUninstall-uninstall +++ b/client/lib/goldens/testUninstall-uninstall @@ -1 +1,2 @@ -Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]Successfully uninstalled hishtory, please restart your terminal... +Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]Do you have any feedback on why you're uninstallying hiSHtory? Type any feedback and then hit enter. +Feedback: Successfully uninstalled hishtory, please restart your terminal... diff --git a/shared/data.go b/shared/data.go index 0af2b03..4a7d120 100644 --- a/shared/data.go +++ b/shared/data.go @@ -85,3 +85,9 @@ func (m *MessageIdentifiers) Scan(value interface{}) error { func (m MessageIdentifiers) Value() (driver.Value, error) { return json.Marshal(m) } + +type Feedback struct { + UserId string `json:"user_id" gorm:"not null"` + Date time.Time `json:"date" gorm:"not null"` + Feedback string `json:"feedback"` +}