Commit f7074cfb authored by Can Maihofer's avatar Can Maihofer

pls goooat

parent a7531eae
Pipeline #1833 failed with stages
in 53 seconds
......@@ -33,6 +33,7 @@ func Init() {
// Register all the Routers
h.BuildingRouter.AttachRouter(r)
h.AppointmentRouter.AttachRouter(r)
h.RoomRouter.AttachRouter(r)
h.HomeRouter.AttachRouter(r)
// Create a new server
......
......@@ -16,7 +16,7 @@ type roomRouter struct{}
var (
// RoomRouter Handles requests to /room
RoomRouter = &buildingRouter{}
RoomRouter = &roomRouter{}
)
func createRoom(res http.ResponseWriter, req *http.Request) {
......
......@@ -51,7 +51,6 @@ func CreateSampleData() {
Number: 420,
Capacity: 69,
})
}
}
......@@ -69,10 +69,10 @@ func (repo *Repository) CreateBuilding(building *model.Building) (*model.Buildin
return &result, nil
}
func (repo *Repository) UpdateBuilding(id interface{}, 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": id}, &building)
res, err := repo.Col.ReplaceOne(ctx, bson.M{"_id": &building.ID}, &building)
if err != nil {
return nil, err
}
......
......@@ -190,20 +190,3 @@ 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
}
......@@ -14,6 +14,8 @@ services:
mongo:
image: mongo:latest
container_name: mongo
ports:
- 27017:27017
volumes:
- dbdata:/data/db
environment:
......
......@@ -47,9 +47,10 @@ func (b *buildingService) CreateRoom(buildingID string, room *model.Room) (*mode
room, err = building.CreateRoom(room.Number, room.Capacity)
// Save to db
dbRoom, err := r.RoomRepo.CreateRoom(room)
r.BuildingRepo.UpdateBuilding(building)
// dbRoom, err := r.RoomRepo.CreateRoom(room)
return dbRoom, err
return room, err
}
func (b *buildingService) GetRoom(roomID string) (room *model.Room, err error) {
......
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