Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Fabian Vitt
good2go
Commits
a7531eae
Commit
a7531eae
authored
Jun 04, 2020
by
Max Richter
Browse files
refactor(mongodb): change createSampleData func
parent
3e3895a5
Pipeline
#1829
failed with stages
in 55 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
database/init.go
View file @
a7531eae
...
...
@@ -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
,
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment