Proper context.Context usage

This commit is contained in:
Caleb Gardner
2024-10-24 00:00:08 -05:00
parent fcab9458ee
commit 6965917e76
19 changed files with 126 additions and 118 deletions
+2 -3
View File
@@ -1,7 +1,6 @@
package cdr
import (
"context"
"encoding/json"
"io"
"log"
@@ -56,7 +55,7 @@ func (b CDRBackend) UploadDie(w http.ResponseWriter, r *http.Request) {
if toUpload.Die["uuid"] != nil {
delete(toUpload.Die, "uuid")
}
_, err = b.db.Collection("dice").InsertOne(context.Background(), toUpload)
_, err = b.db.Collection("dice").InsertOne(r.Context(), toUpload)
if err != nil {
backend.ReturnError(w, http.StatusInternalServerError, "internal", "Server error")
log.Println("error inserting die:", err)
@@ -67,7 +66,7 @@ func (b CDRBackend) UploadDie(w http.ResponseWriter, r *http.Request) {
}
func (b CDRBackend) GetDie(w http.ResponseWriter, r *http.Request) {
res := b.db.Collection("dice").FindOne(context.Background(), bson.M{"_id": r.PathValue("dieID")})
res := b.db.Collection("dice").FindOne(r.Context(), bson.M{"_id": r.PathValue("dieID")})
if res.Err() == mongo.ErrNoDocuments {
backend.ReturnError(w, 404, "not found", "Die with the given id is not found")
return