Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/controllers/debatevsbot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func JudgeDebate(c *gin.Context) {

// Update debate outcome
if err := db.UpdateDebateVsBotOutcome(email, result); err != nil {
log.Printf("Failed to update debate vs bot outcome for %s: %v", email, err)
}

// Get the latest debate information to extract proper details
Expand Down
11 changes: 4 additions & 7 deletions backend/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ func SaveDebateVsBot(debate models.DebateVsBot) error {
}

// UpdateDebateVsBotOutcome updates the outcome of the most recent bot debate for a user
func UpdateDebateVsBotOutcome(userId, outcome string) error {
filter := bson.M{"userId": userId}
func UpdateDebateVsBotOutcome(email, outcome string) error {
filter := bson.M{"email": email}
update := bson.M{"$set": bson.M{"outcome": outcome}}
_, err := DebateVsBotCollection.UpdateOne(context.Background(), filter, update, nil)
if err != nil {
return err
}
return nil
opts := options.FindOneAndUpdate().SetSort(bson.M{"createdAt": -1})
return DebateVsBotCollection.FindOneAndUpdate(context.Background(), filter, update, opts).Err()
}

// GetLatestDebateVsBot retrieves the most recent bot debate for a user
Expand Down