Files
LazyPM/internal/commands/survey/submit.go
Robin Olsen 72a2e8acf5 Metrics and logs - MongoDB Submission (#43)
Adds MongoDB-backed submission for survey statistics/metrics and introduces MongoDB ObjectID-based participant/task identifiers to support upserts and linking metrics to a participant.

It introduces breaking changes to the exsisting json stat and metric files. Delete the old ones

Changes:

Add internal/storage/MongoStorage and wire pm survey submit / pm start to submit local .pm/*.json files to MongoDB.
Extend stats/metrics models to include MongoDB _id / participant_id fields and add participant ID propagation into task metrics.
Update app initialization to generate ObjectIDs for new participants and expose GetParticipantID() via StatsService.
2026-03-10 14:09:31 +01:00

40 lines
980 B
Go

package survey
import (
"fmt"
"github.com/LazyBachelor/LazyPM/internal/storage"
"github.com/spf13/cobra"
)
var SubmitCmd = &cobra.Command{
Use: "submit",
Short: "Submit your survey responses",
RunE: func(cmd *cobra.Command, args []string) error {
app := AppFromContext(cmd.Context())
if app == nil {
return fmt.Errorf("application context not initialized")
}
if app.Config.DbUri == "" {
cmd.Println("No database URI provided in environment, survey responses will not be submitted.")
return nil
}
db, err := storage.NewMongoStorageInteractive(cmd.Context(), app.Config.DbUri)
if err != nil {
return fmt.Errorf("failed to connect to database: %w", err)
}
defer db.Close()
if err := db.SubmitSurveyResponsesCmd(cmd.Context(), app.Config.AppDir); err != nil {
return fmt.Errorf("failed to submit survey responses: %w", err)
}
cmd.Println("Successfully submitted survey responses and metrics to the database")
return nil
},
}