Commit e7f8c220 authored by Can Maihofer's avatar Can Maihofer
Browse files

good stuff

parent f7074cfb
Pipeline #1835 failed with stages
in 55 seconds
......@@ -101,6 +101,7 @@ func deleteRoom(res http.ResponseWriter, req *http.Request) {
// AttachRouter initialize Router
func (a roomRouter) AttachRouter(router *mux.Router) {
//todo addd single room route
r := router.PathPrefix("/rooms").Subrouter().StrictSlash(true)
// CREATE
......
......@@ -69,7 +69,7 @@ func (repo *Repository) CreateBuilding(building *model.Building) (*model.Buildin
return &result, nil
}
func (repo *Repository) UpdateBuilding( building *model.Building) (*mongo.UpdateResult, error) {
func (repo *Repository) UpdateBuilding(building *model.Building) (*mongo.UpdateResult, error) {
ctx, cancel := utils.CreateTimeoutCTX(time.Second * 10)
defer cancel()
res, err := repo.Col.ReplaceOne(ctx, bson.M{"_id": &building.ID}, &building)
......
......@@ -190,3 +190,20 @@ func (repo *Repository) DeleteRoom(roomID string) (room *model.Room, err error)
return repo.findByID(roomID)
}
func (repo *Repository) GetAllRooms() []*model.Room {
ctx, cancel := utils.CreateTimeoutCTX(5 * time.Second)
defer cancel()
cursor, err := repo.Col.Find(ctx, bson.M{})
if err != nil {
log.Fatal("[MONGODB] roomRepository", err)
}
var rooms []*model.Room
if err = cursor.All(ctx, &rooms); err != nil {
log.Fatal(err)
}
return rooms
}
package services
import (
"git.coco.study/fvitt/good2go/internal/model"
"testing"
"git.coco.study/fvitt/good2go/internal/model"
)
func TestBuildingService_CreateRoom(t *testing.T) {
......@@ -48,9 +49,9 @@ func TestBuildingService_GetRoom(t *testing.T) {
}
}
func TestBuildingService_GetRooms(t *testing.T) {
func TestBuildingService_GetAllRooms(t *testing.T) {
BuildDefBuilding()
roomsMap := BuildingService.GetRooms()
roomsMap := BuildingService.GetAllRooms()
if len(roomsMap) <= 0 {
t.Error("did not get any room, expected one")
}
......
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