-
Notifications
You must be signed in to change notification settings - Fork 0
/
seats.go
45 lines (37 loc) · 990 Bytes
/
seats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package app
import (
"fmt"
"github.com/lanets/floorplanets/backend/models"
)
func (app *App) CreateSeat(floorplanID uint, label string, x, y int) (*models.Seat, error) {
// Get the corresponding floorplan
floorplan, err := app.GetFloorplan(int(floorplanID))
if err != nil {
return nil, err
}
if floorplan == nil {
return nil, fmt.Errorf("Could not find floorplan with id '%d'", floorplanID)
}
// Create the seat
seat := &models.Seat{
FloorplanID: floorplan.ID,
Label: label,
X: x,
Y: y,
}
err = app.Database.Create(seat).Error
if err != nil {
return nil, err
}
return seat, nil
}
func (app *App) GetSeat(id int) (*models.Seat, error) {
var seat models.Seat
if app.Database.First(&seat, id).RecordNotFound() {
return nil, app.Database.Error
}
return &seat, app.Database.Error
}
func (app *App) LoadFloorplanSeats(floorplan *models.Floorplan) error {
return app.Database.Model(floorplan).Related(&floorplan.Seats).Error
}