Commit a7531eae authored by Max Richter's avatar Max Richter
Browse files

refactor(mongodb): change createSampleData func

parent 3e3895a5
Pipeline #1829 failed with stages
in 55 seconds
......@@ -6,6 +6,7 @@ import (
ownMongo "git.coco.study/fvitt/good2go/database/mongo"
"git.coco.study/fvitt/good2go/internal/model"
services "git.coco.study/fvitt/good2go/internal/services"
mongo "go.mongodb.org/mongo-driver/mongo"
)
......@@ -19,42 +20,38 @@ func Disconnect() {
func CreateSampleData() {
//"08:00", "10h", []string{"mon", "tue", "wed", "thu", "fri", "sat"}
// Add Building
building := &model.Building{}
building.New("08:00", "10h", []string{"mon", "tue", "wed", "thu", "fri", "sat"})
building, err := ownMongo.BuildingRepo.CreateBuilding(building)
// Get all buildings
buildings, err := ownMongo.BuildingRepo.GetAllBuildings()
if err != nil {
log.Fatal(err)
}
log.Print("building", building)
// Add a room to the building
building.CreateRoom(320, 10)
// // Add a second room to the building
// _, err = services.BuildingService.CreateRoom(building.ID.String(), &model.Room{
// Number: 420,
// Capacity: 69,
// })
// if err != nil {
// log.Fatal(err)
// }
// // Add sample Appointments
// a1, _ := model.Appointment{}.New("27-11-2016 10:00", "2h")
// _, err = services.AppointmentService.AddAppointment(a1)
// if err != nil {
// log.Fatal(err)
// }
// a2, _ := model.Appointment{}.New("27-11-2016 13:00", "2h")
// _, err = services.AppointmentService.AddAppointment(a2)
// if err != nil {
// log.Fatal(err)
// }
var building *model.Building
// Only create sample data if no sample data exists
if len(buildings) == 0 {
// Add Building
building = &model.Building{}
building, err := services.BuildingService.CreateBuilding(building.New("08:00", "10h", []string{"mon", "tue", "wed", "thu", "fri", "sat"}))
if err != nil {
log.Fatal(err)
log.Print(building)
}
} else {
building = buildings[0]
}
rooms := building.GetRooms()
log.Print("INIT", rooms, len(rooms))
if len(rooms) == 0 {
services.BuildingService.CreateRoom(building.ID.Hex(), &model.Room{
Number: 420,
Capacity: 69,
})
}
}
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