Skip to content

Commit

Permalink
Added WLED support to venues
Browse files Browse the repository at this point in the history
  • Loading branch information
thordy committed Jun 13, 2024
1 parent f5fcd6d commit 7c7845e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Endpoint for getting badge statistics
- Added Darts Per Leg `DPL` metric to tournament
- Count badges for all leg types
- WLED support for venues
- Lots of new badges

#### Changed
Expand Down
26 changes: 17 additions & 9 deletions data/venue.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func AddVenue(venue models.Venue) error {
return err
}

_, err = tx.Exec(`INSERT INTO venue_configuration (venue_id, has_dual_monitor, has_led_lights, has_smartboard, smartboard_uuid, smartboard_button_number)
VALUES (?, ?, ?, ?, ?, ?)`, venueID, venue.Config.HasDualMonitor, venue.Config.HasLEDLights, venue.Config.HasSmartboard,
venue.Config.SmartboardUUID, venue.Config.SmartboardButtonNumber)
_, err = tx.Exec(`INSERT INTO venue_configuration (venue_id, has_dual_monitor, has_led_lights, has_wled_lights, has_smartboard, \
smartboard_uuid, smartboard_button_number) VALUES (?, ?, ?, ?, ?, ?)`, venueID, venue.Config.HasDualMonitor, venue.Config.HasLEDLights,
venue.Config.HasWLEDLights, venue.Config.HasSmartboard, venue.Config.SmartboardUUID, venue.Config.SmartboardButtonNumber)
if err != nil {
tx.Rollback()
return err
Expand All @@ -51,8 +51,9 @@ func UpdateVenue(venueID int, venue models.Venue) error {
tx.Rollback()
return err
}
_, err = tx.Exec(`UPDATE venue_configuration SET has_dual_monitor = ?, has_led_lights = ?, has_smartboard = ?, smartboard_uuid = ?, smartboard_button_number = ? WHERE venue_id = ?`,
venue.Config.HasDualMonitor, venue.Config.HasLEDLights, venue.Config.HasSmartboard,
_, err = tx.Exec(`UPDATE venue_configuration SET has_dual_monitor = ?, has_led_lights = ?, has_wled_lights = ?,
has_smartboard = ?, smartboard_uuid = ?, smartboard_button_number = ? WHERE venue_id = ?`,
venue.Config.HasDualMonitor, venue.Config.HasLEDLights, &venue.Config.HasWLEDLights, venue.Config.HasSmartboard,
venue.Config.SmartboardUUID, venue.Config.SmartboardButtonNumber, venueID)
if err != nil {
tx.Rollback()
Expand Down Expand Up @@ -85,14 +86,17 @@ func GetVenues() ([]*models.Venue, error) {
return nil, err
}

rows, err = models.DB.Query("SELECT venue_id, has_dual_monitor, has_led_lights, has_smartboard, smartboard_uuid, smartboard_button_number FROM venue_configuration")
rows, err = models.DB.Query(`
SELECT venue_id, has_dual_monitor, has_led_lights, has_wled_lights, has_smartboard, smartboard_uuid, smartboard_button_number
FROM venue_configuration`)
if err != nil {
return nil, err
}
configs := make(map[int]*models.VenueConfig)
for rows.Next() {
config := new(models.VenueConfig)
err := rows.Scan(&config.VenueID, &config.HasDualMonitor, &config.HasLEDLights, &config.HasSmartboard, &config.SmartboardUUID, &config.SmartboardButtonNumber)
err := rows.Scan(&config.VenueID, &config.HasDualMonitor, &config.HasLEDLights, &config.HasWLEDLights, &config.HasSmartboard,
&config.SmartboardUUID, &config.SmartboardButtonNumber)
if err != nil {
return nil, err
}
Expand All @@ -116,15 +120,19 @@ func GetVenue(id int) (*models.Venue, error) {
venue.Config, err = GetVenueConfiguration(id)
if err != nil {
log.Printf("Unable to get venue configuration for %d", id)
return nil, err
}
return venue, nil
}

// GetVenueConfiguration will return the configuration for a venue with the given id
func GetVenueConfiguration(id int) (*models.VenueConfig, error) {
config := new(models.VenueConfig)
err := models.DB.QueryRow("SELECT venue_id, has_dual_monitor, has_led_lights, has_smartboard, smartboard_uuid, smartboard_button_number FROM venue_configuration WHERE venue_id = ?",
id).Scan(&config.VenueID, &config.HasDualMonitor, &config.HasLEDLights, &config.HasSmartboard, &config.SmartboardUUID, &config.SmartboardButtonNumber)
err := models.DB.QueryRow(`
SELECT venue_id, has_dual_monitor, has_led_lights, has_wled_lights, has_smartboard, smartboard_uuid, smartboard_button_number
FROM venue_configuration WHERE venue_id = ?`,
id).Scan(&config.VenueID, &config.HasDualMonitor, &config.HasLEDLights, &config.HasWLEDLights, &config.HasSmartboard, &config.SmartboardUUID,
&config.SmartboardButtonNumber)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions models/venue.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type VenueConfig struct {
VenueID int `json:"id"`
HasDualMonitor bool `json:"has_dual_monitor"`
HasLEDLights bool `json:"has_led_lights"`
HasWLEDLights bool `json:"has_wled_lights"`
HasSmartboard bool `json:"has_smartboard"`
SmartboardUUID null.String `json:"smartboard_uuid,omitempty"`
SmartboardButtonNumber null.Int `json:"smartboard_button_number,omitempty"`
Expand Down

0 comments on commit 7c7845e

Please sign in to comment.