Last active
February 4, 2019 01:57
-
-
Save wemgl/c059aae8e7c05b2a242d6981c1b0d744 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var t todo | |
idDoc := bson.D{{"_id", objectIDS}} | |
err = db.Collection(collName).FindOne(ctx, idDoc).Decode(&t) | |
if err != nil { | |
return "", fmt.Errorf("updateTask: couldn't decode task from db: %v", err) | |
} | |
var task string | |
fmt.Println("old task:", t.Task) | |
fmt.Print("updated task: ") | |
for input.Scan() { | |
if err := input.Err(); err != nil { | |
return "", fmt.Errorf("updateTask: couldn't read task from command line: %v", err) | |
} | |
task = input.Text() | |
if len(strings.Trim(task, " ")) == 0 { | |
return "", errors.New("updateTask: can't update a to-do item with no task") | |
} | |
t.Task = task | |
break | |
} | |
_, err = db.Collection(collName).UpdateOne( | |
ctx, | |
idDoc, | |
bson.D{ | |
{"$set", bson.D{{"task", t.Task}}}, | |
{"$currentDate", bson.D{{"modifiedAt", true}}}, | |
}, | |
) | |
if err != nil { | |
return "", fmt.Errorf("updateTask: task for to-do list couldn't be created: %v", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment