bookDetails have ID
This commit is contained in:
4 files changed
+8
No files matched your search
@@ -3,6 +3,7 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ import (
|
|||||||
"github.com/SowinskiBraeden/SulliCartShare/config"
|
"github.com/SowinskiBraeden/SulliCartShare/config"
|
||||||
"github.com/SowinskiBraeden/SulliCartShare/models"
|
"github.com/SowinskiBraeden/SulliCartShare/models"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/thanhpk/randstr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c Cow) BookingHandler(w http.ResponseWriter, r *http.Request) {
|
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
|
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}})
|
dbResp, err := c.DB.UpdateOne(ctx, bson.M{"_id": cID}, bson.M{"$push": bson.M{"Cow.Bookings": bookingDetails}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
config.ErrorStatus("the booking could not be added to the cow", http.StatusNotFound, w, err)
|
config.ErrorStatus("the booking could not be added to the cow", http.StatusNotFound, w, err)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ require (
|
|||||||
github.com/go-playground/validator/v10 v10.11.1
|
github.com/go-playground/validator/v10 v10.11.1
|
||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/joho/godotenv v1.4.0
|
github.com/joho/godotenv v1.4.0
|
||||||
|
github.com/thanhpk/randstr v1.0.4
|
||||||
go.mongodb.org/mongo-driver v1.10.2
|
go.mongodb.org/mongo-driver v1.10.2
|
||||||
go.uber.org/zap v1.23.0
|
go.uber.org/zap v1.23.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
|
github.com/thanhpk/randstr v1.0.4 h1:IN78qu/bR+My+gHCvMEXhR/i5oriVHcTB/BJJIRTsNo=
|
||||||
|
github.com/thanhpk/randstr v1.0.4/go.mod h1:M/H2P1eNLZzlDwAzpkkkUvoyNNMbzRGhESZuEQk3r0U=
|
||||||
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
||||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type Cow struct {
|
|||||||
|
|
||||||
// BookDetails holds the checkout details
|
// BookDetails holds the checkout details
|
||||||
type BookDetails struct {
|
type BookDetails struct {
|
||||||
|
ID string `json:"id" bson:"ID"` // Generated ID -> cow_id.random_str
|
||||||
Author string `json:"author" bson:"Author"` // User who booked
|
Author string `json:"author" bson:"Author"` // User who booked
|
||||||
Devices []string `json:"devices" bson:"Devices"` // Array of device ID's
|
Devices []string `json:"devices" bson:"Devices"` // Array of device ID's
|
||||||
Block string `json:"block" bson:"Block"` // Block that is booked
|
Block string `json:"block" bson:"Block"` // Block that is booked
|
||||||
|
|||||||
Reference in new issue
Block a user