Skip to content

Commit

Permalink
fix(model): fixes bson tag of name causing ambiguity in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhaev26 committed Dec 1, 2023
1 parent 5c74cb1 commit 8f41bb8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/api/basketball/database/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ var Collection *mongo.Collection
// Initiator function which runs automatically at the start of application
// This function connects to the DB and returns collection instances which is used for DB actions.
func init() {
const connectionString = "xyz"
const connectionString = "mongodb+srv://linux-skg:1TuX01zH2y3tjUFV@sports.vj9j4tb.mongodb.net/?retryWrites=true&w=majoritymongodb+srv://linux-skg:1TuX01zH2y3tjUFV@sports.vj9j4tb.mongodb.net/?retryWrites=true&w=majority"
const databaseName = "basketball"
const collection1_Name = "in-match-scoring"
const collection1_Name = "teams"

clientOptions := options.Client().ApplyURI(connectionString)
client, err := mongo.Connect(context.TODO(), clientOptions)
Expand Down
2 changes: 1 addition & 1 deletion src/api/basketball/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func UploadTeamPlayer(player playerModel.Player) *mongo.InsertOneResult {
inserted, err := basketballdb.Collection.InsertOne(context.TODO(), player)

if err != nil {
log.Fatal("Error occured while inserting in db @helper/UploadTeamPlayer")
log.Fatal("Error occured while inserting in db @helper/UploadTeamPlayer",err)
}

fmt.Println("Registration Done :", inserted)
Expand Down
11 changes: 8 additions & 3 deletions src/api/basketball/model/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
)

//BSON IS IMPORTANT !

// Player data structure (Acting as ORM ) for Basketball Players.

/*
Bson tags are essential for linking struct literals to the corresponding database fields.
They serve as a mapping mechanism between Go structs and the underlying database representation.
They provide a clear association between struct fields and their counterparts in the database. This mapping ensures proper serialization
and deserialization of data when interacting with databases.
*/
type Player struct {
Name string `json:"name,omitempty"`
Name string `json:"name,omitempty" bson:"name,omitempty"`
ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
ImageLink string `json:"imageLink,omitempty" bson:"imageLink,omitempty"`
Position string `json:"pos,omitempty" bson:"pos,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions src/api/basketball/routes/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ func Router() *mux.Router {
r.HandleFunc("/get-teamwise-players", controller.GetTeamWisePlayers).Methods("GET")
r.HandleFunc("/upload-player", controller.UploadTeamPlayer).Methods("POST")
r.HandleFunc("/update-player", controller.UpdateTeamPlayer).Methods("POST")
// r.HandleFunc("/get ")
return r
}

0 comments on commit 8f41bb8

Please sign in to comment.