This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getKioskEvent(kioskID, eventID uint, db *gorm.DB) (KioskEvent, error) { | |
| kioskEvent := KioskEvent{} | |
| result := db.Preload("Checkins").Where(&KioskEvent{KioskID: kioskID, EventID: eventID}).First(&kioskEvent) | |
| return kioskEvent, result.Error | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Checkin struct { | |
| gorm.Model | |
| EventID uint | |
| KioskID uint | |
| CheckinDatetime time.Time | |
| Name string | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type KioskEvent struct { | |
| Checkins []Checkin `gorm:"foreignKey:KioskID,EventID;References:KioskID,EventID"` | |
| KioskID uint `gorm:"primaryKey"` | |
| EventID uint `gorm:"primarykey"` | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| databaseChangeLog: | |
| - changeSet: | |
| - id: 4-create-checkins-table | |
| author: [email protected] | |
| changes: | |
| - createTable: | |
| tableName: checkins | |
| remarks: Where checkins are recorded. | |
| schemaName: checkin | |
| columns: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getEvent(eventID uint, db *gorm.DB) (Event, error) { | |
| event := Event{ Model: gorm.Model{ID: eventID}} | |
| result := db.Preload("Kiosks").First(&event) | |
| return event, result.Error | |
| } | |
| func getKiosk( kioskID uint, db *gorm.DB) (Kiosk, error) { | |
| kiosk := Kiosk{ Model: gorm.Model{ID: kioskID}} | |
| result := db.Preload("Events").First(&kiosk) | |
| return kiosk, result.Error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func linkKioskAndEvent(kioskID, eventID uint, db *gorm.DB) error { | |
| kioskEvent := KioskEvent{ | |
| KioskID: kioskID, | |
| EventID: eventID, | |
| } | |
| result := db.Create(&kioskEvent) | |
| return result.Error | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func createKiosk(db *gorm.DB, name string) error { | |
| kiosk := Kiosk{ | |
| Name: name, | |
| } | |
| result := db.Create(&kiosk) | |
| return result.Error | |
| } | |
| func createEvent(db *gorm.DB, name string) error { | |
| event := Event{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package join | |
| import "gorm.io/gorm" | |
| type Event struct { | |
| gorm.Model | |
| Kiosks []Kiosk `gorm:"many2many:kiosk_events"` | |
| Name string | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| databaseChangeLog: | |
| - changeSet: | |
| - id: 3-create-join-table | |
| author: [email protected] | |
| changes: | |
| - createTable: | |
| tableName: kiosk_events | |
| remarks: A join table between kiosks and events | |
| schemaName: checkin | |
| columns: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| databaseChangeLog: | |
| - changeSet: | |
| - id: 2-create-events-and-kiosks-table | |
| author: [email protected] | |
| changes: | |
| - createTable: | |
| tableName: events | |
| schemaName: checkin | |
| columns: | |
| - column: |
NewerOlder