@@ -545,6 +545,7 @@ func (h *ApiHandler) GetEventsGeoJSON(gc *gin.Context) {
545545 ctx := gc .Request .Context ()
546546 apiRequest := grains_api .NewRequest (gc , "get-events-geojson" )
547547
548+ // Build SQL
548549 dateConditions , conditionsStr , limitClause , args , _ , err := h .buildEventFilters (gc )
549550 if err != nil {
550551 apiRequest .Error (http .StatusBadRequest , "" )
@@ -570,6 +571,7 @@ func (h *ApiHandler) GetEventsGeoJSON(gc *gin.Context) {
570571 }
571572 defer rows .Close ()
572573
574+ // Event scan type
573575 type EventResponse struct {
574576 EventDateId int `json:"event_date_id"`
575577 EventId int `json:"event_id"`
@@ -584,6 +586,16 @@ func (h *ApiHandler) GetEventsGeoJSON(gc *gin.Context) {
584586 StartTime * string `json:"start_time"`
585587 }
586588
589+ type VenueEvents struct {
590+ Name string `json:"name"`
591+ Lon * float64 `json:"lon"`
592+ Lat * float64 `json:"lat"`
593+ Events []EventResponse `json:"events"`
594+ EventCount int `json:"event_count"`
595+ }
596+
597+ venues := make (map [int ]* VenueEvents )
598+
587599 var events []EventResponse
588600
589601 for rows .Next () {
@@ -605,11 +617,33 @@ func (h *ApiHandler) GetEventsGeoJSON(gc *gin.Context) {
605617 apiRequest .InternalServerError ()
606618 return
607619 }
620+
608621 events = append (events , e )
622+
623+ // Skip events without a venue
624+ if e .VenueId == nil {
625+ continue
626+ }
627+
628+ if e .VenueId != nil {
629+ vId := * e .VenueId
630+ if _ , exists := venues [vId ]; ! exists {
631+ venues [vId ] = & VenueEvents {
632+ Name : derefString (e .VenueName , "" ),
633+ Lon : e .VenueLon ,
634+ Lat : e .VenueLat ,
635+ Events : []EventResponse {},
636+ // don't set EventCount yet
637+ }
638+ }
639+
640+ venues [vId ].Events = append (venues [vId ].Events , e )
641+ venues [vId ].EventCount = len (venues [vId ].Events )
642+ }
609643 }
610644
611645 if len (events ) == 0 {
612- apiRequest .NotFound ("no events found" )
646+ apiRequest .NoContent ("no events found" )
613647 return
614648 }
615649
@@ -625,11 +659,12 @@ func (h *ApiHandler) GetEventsGeoJSON(gc *gin.Context) {
625659 apiRequest .Success (
626660 http .StatusOK ,
627661 gin.H {
628- "events " : events ,
662+ "venues " : venues ,
629663 "last_event_start_at" : lastEventStartAt ,
630664 "last_event_date_id" : lastEventDateId ,
631665 },
632- "" )
666+ "" ,
667+ )
633668}
634669
635670func validateAllowedQueryParams (c * gin.Context , allowed map [string ]struct {}) error {
@@ -640,3 +675,11 @@ func validateAllowedQueryParams(c *gin.Context, allowed map[string]struct{}) err
640675 }
641676 return nil
642677}
678+
679+ // Helper for nil strings
680+ func derefString (s * string , fallback string ) string {
681+ if s != nil && * s != "" {
682+ return * s
683+ }
684+ return fallback
685+ }
0 commit comments