Commit 9d533c6c authored by Max Richter's avatar Max Richter
Browse files

feat(mongodb): 🗃 created basic and simple room repository

parent 314a375c
Pipeline #1766 passed with stages
in 1 minute and 36 seconds
package mongo
import (
"context"
"log"
"git.coco.study/fvitt/good2go/internal/model"
"go.mongodb.org/mongo-driver/mongo"
"gopkg.in/mgo.v2/bson"
)
type roomRepository struct {
c *mongo.Collection
ctx context.Context
}
var (
RoomRepository = &roomRepository{}
)
func (repo *roomRepository) insertOne(document interface{}) {
repo.c.InsertOne(repo.ctx, document)
}
func (repo *roomRepository) updateOne(document interface{}) {
repo.c.UpdateOne(repo.ctx, document, document)
}
func (repo *roomRepository) CreateRoom(r *model.Room) {
repo.insertOne(r)
}
func (repo *roomRepository) UpdateRoom(r *model.Room) {
repo.updateOne(r)
}
func (repo *roomRepository) GetAllRooms() []model.Room {
cursor, err := repo.c.Find(repo.ctx, bson.M{})
if err != nil {
log.Fatal(err)
}
var rooms []model.Room
if err = cursor.All(repo.ctx, &rooms); err != nil {
log.Fatal(err)
}
return rooms
}
func (repo *roomRepository) ConnectTo(ctx context.Context, c *mongo.Collection) {
repo.c = c
repo.ctx = ctx
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment