bookDetails have ID

This commit is contained in:
SowinskiBraeden committed 2022-11-24 14:21:10 -08:00
1 parent 6bfb49512d
commit 6103b6d502
4 files changed
+8

No files matched your search

+4
View File
@@ -3,6 +3,7 @@ package handlers
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
@@ -12,6 +13,7 @@ import (
"github.com/SowinskiBraeden/SulliCartShare/config"
"github.com/SowinskiBraeden/SulliCartShare/models"
"github.com/gorilla/mux"
"github.com/thanhpk/randstr"
)
func (c Cow) BookingHandler(w http.ResponseWriter, r *http.Request) {
@@ -39,6 +41,8 @@ func (c Cow) BookingHandler(w http.ResponseWriter, r *http.Request) {
return
}
bookingDetails.ID = fmt.Sprintf("%s.%s", cowID, randstr.Hex(16))
dbResp, err := c.DB.UpdateOne(ctx, bson.M{"_id": cID}, bson.M{"$push": bson.M{"Cow.Bookings": bookingDetails}})
if err != nil {
config.ErrorStatus("the booking could not be added to the cow", http.StatusNotFound, w, err)