use new interactive db connection

This commit is contained in:
Robin Olsen
2026-03-10 12:08:19 +01:00
parent 1ed655ff32
commit 5c6afc9b69
2 changed files with 7 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ import (
) )
var ( var (
DevFlag bool
InterfaceType string InterfaceType string
Task string Task string
) )

View File

@@ -8,9 +8,8 @@ import (
) )
var SubmitCmd = &cobra.Command{ var SubmitCmd = &cobra.Command{
Use: "submit <mongo-password>", Use: "submit",
Short: "Submit your survey responses", Short: "Submit your survey responses",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
app := AppFromContext(cmd.Context()) app := AppFromContext(cmd.Context())
@@ -18,19 +17,14 @@ var SubmitCmd = &cobra.Command{
return fmt.Errorf("application context not initialized") return fmt.Errorf("application context not initialized")
} }
if len(args) == 0 { db, err := storage.NewMongoStorageInteractive(app.Config.MongoURI)
cmd.Println("No MongoDB password provided, survey responses will not be submitted.")
return nil
}
mongoPassword := args[0]
mongoClient, err := storage.NewMongoStorage(app.Config.MongoURI, "participant", mongoPassword)
if err != nil { if err != nil {
return fmt.Errorf("failed to connect to MongoDB: %w", err) return fmt.Errorf("failed to connect to database: %w", err)
} }
defer mongoClient.Close()
if err := mongoClient.SubmitSurveyResponsesCmd(cmd.Context()); err != nil { defer db.Close()
if err := db.SubmitSurveyResponsesCmd(cmd.Context()); err != nil {
return fmt.Errorf("failed to submit survey responses: %w", err) return fmt.Errorf("failed to submit survey responses: %w", err)
} }