@@ -21,42 +21,44 @@ type eventType struct {
2121
2222// eventResponse is the JSON structure for each event
2323type eventResponse struct {
24- EventDateId int `json:"event_date_id"`
25- Id int `json:"id"` // event_id
26- Title string `json:"title"`
27- Subtitle * string `json:"subtitle"`
28- StartDate string `json:"start_date"`
29- StartTime string `json:"start_time,omitempty"`
30- EndDate * string `json:"end_date,omitempty"`
31- EndTime * string `json:"end_time,omitempty"`
32- EntryTime * string `json:"entry_time,omitempty"`
33- Duration * int `json:"duration,omitempty"`
34- AllDay * bool `json:"all_day,omitempty"`
35- TicketLink * string `json:"ticket_link,omitempty"`
36- SpaceId * int `json:"space_id,omitempty"`
37- SpaceName * string `json:"space_name,omitempty"`
38- SpaceAccessibilityFlags * string `json:"space_accessibility_flags,omitempty"`
39- VenueId * int `json:"venue_id,omitempty"`
40- VenueName * string `json:"venue_name,omitempty"`
41- VenueCity * string `json:"venue_city,omitempty"`
42- VenueStreet * string `json:"venue_street,omitempty"`
43- VenueHouse * string `json:"venue_house_number,omitempty"`
44- VenuePostal * string `json:"venue_postal_code,omitempty"`
45- VenueState * string `json:"venue_state,omitempty"`
46- VenueCountry * string `json:"venue_country,omitempty"`
47- VenueLat * float64 `json:"venue_lat,omitempty"`
48- VenueLon * float64 `json:"venue_lon,omitempty"`
49- ImageId * int `json:"image_id,omitempty"`
50- ImagePath * string `json:"image_path,omitempty"`
51- OrganizationId int `json:"organization_id"`
52- OrganizationName string `json:"organization_name"`
53- EventTypes []eventType `json:"event_types,omitempty"`
54- Languages []string `json:"languages"`
55- Tags []string `json:"tags"`
56- MinAge * int `json:"min_age"`
57- MaxAge * int `json:"max_age"`
58- VisitorInfoFlags * string `json:"visitor_info_flags,omitempty"`
59- ReleaseStatus * string `json:"release_status,omitempty"`
24+ EventDateId int `json:"event_date_id"`
25+ Id int `json:"id"` // event_id
26+ Title string `json:"title"`
27+ Subtitle * string `json:"subtitle"`
28+ StartDate string `json:"start_date"`
29+ StartTime string `json:"start_time,omitempty"`
30+ EndDate * string `json:"end_date,omitempty"`
31+ EndTime * string `json:"end_time,omitempty"`
32+ EntryTime * string `json:"entry_time,omitempty"`
33+ Duration * int `json:"duration,omitempty"`
34+ AllDay * bool `json:"all_day,omitempty"`
35+ TicketLink * string `json:"ticket_link,omitempty"`
36+ SpaceId * int `json:"space_id,omitempty"`
37+ SpaceName * string `json:"space_name,omitempty"`
38+ SpaceAccessibilityFlags * string `json:"space_accessibility_flags,omitempty"`
39+ VenueId * int `json:"venue_id,omitempty"`
40+ VenueName * string `json:"venue_name,omitempty"`
41+ VenueCity * string `json:"venue_city,omitempty"`
42+ VenueStreet * string `json:"venue_street,omitempty"`
43+ VenueHouse * string `json:"venue_house_number,omitempty"`
44+ VenuePostal * string `json:"venue_postal_code,omitempty"`
45+ VenueState * string `json:"venue_state,omitempty"`
46+ VenueCountry * string `json:"venue_country,omitempty"`
47+ VenueLat * float64 `json:"venue_lat,omitempty"`
48+ VenueLon * float64 `json:"venue_lon,omitempty"`
49+ ImageId * int `json:"image_id,omitempty"`
50+ ImagePath * string `json:"image_path,omitempty"`
51+ OrganizationId int `json:"organization_id"`
52+ OrganizationName string `json:"organization_name"`
53+ Categories []int `json:"categories,omitempty"`
54+ SecondaryEventCategoryId * int `json:"secondary_event_category_id,omitempty"`
55+ EventTypes []eventType `json:"event_types,omitempty"`
56+ Languages []string `json:"languages"`
57+ Tags []string `json:"tags"`
58+ MinAge * int `json:"min_age"`
59+ MaxAge * int `json:"max_age"`
60+ VisitorInfoFlags * string `json:"visitor_info_flags,omitempty"`
61+ ReleaseStatus * string `json:"release_status,omitempty"`
6062}
6163
6264// buildEventFilters parses all query parameters from the context
@@ -76,11 +78,11 @@ func (h *ApiHandler) buildEventFilters(gc *gin.Context) (
7678) {
7779
7880 allowed := map [string ]struct {}{
79- "past" : {}, "start" : {}, "end" : {}, "time" : {}, "search" : {},
81+ "category" : {}, " past" : {}, "start" : {}, "end" : {}, "time" : {}, "search" : {},
8082 "events" : {}, "venues" : {}, "spaces" : {}, "space_types" : {},
8183 "organizations" : {}, "countries" : {}, "postal_code" : {},
8284 "title" : {}, "city" : {}, "event_types" : {}, "tags" : {},
83- "accessibility" : {}, "visitor_infos" : {}, "age" : {},
85+ "accessibility" : {}, "visitor_infos" : {}, "age" : {}, "price" : {},
8486 "lon" : {}, "lat" : {}, "radius" : {}, "offset" : {}, "limit" : {},
8587 "last_event_start_at" : {}, "last_event_date_id" : {},
8688 "language" : {},
@@ -96,6 +98,7 @@ func (h *ApiHandler) buildEventFilters(gc *gin.Context) (
9698
9799 _ , hasPast := GetContextParam (gc , "past" )
98100 // languagesStr, _ := GetContextParam(gc, "language") // TODO: Implement language support!
101+ categoryStr , hasCategory := GetContextParam (gc , "category" )
99102 startStr , _ := GetContextParam (gc , "start" )
100103 endStr , _ := GetContextParam (gc , "end" )
101104 lastEventStartAt , _ := GetContextParam (gc , "last_event_start_at" )
@@ -116,12 +119,23 @@ func (h *ApiHandler) buildEventFilters(gc *gin.Context) (
116119 accessibilityFlagsStr , _ := GetContextParam (gc , "accessibility" )
117120 visitorInfosStr , _ := GetContextParam (gc , "visitor_infos" )
118121 ageStr , _ := GetContextParam (gc , "age" )
122+ priceStr , _ := GetContextParam (gc , "price" )
119123 lonStr , _ := GetContextParam (gc , "lon" )
120124 latStr , _ := GetContextParam (gc , "lat" )
121125 radiusStr , _ := GetContextParam (gc , "radius" )
122126 offsetStr , _ := GetContextParam (gc , "offset" )
123127 limitStr , _ := GetContextParam (gc , "limit" )
124128
129+ var errBuild error
130+
131+ if hasCategory {
132+ argIndex , errBuild = sql_utils .BuildColumnArrayOverlapCondition (
133+ categoryStr , "ep.categories" , argIndex , & conditions , & args )
134+ if errBuild != nil {
135+ return "" , "" , "" , nil , 0 , errBuild
136+ }
137+ }
138+
125139 // Date conditions
126140 dateConditionCount := 0
127141 if app .IsValidDateStr (startStr ) {
@@ -157,7 +171,6 @@ func (h *ApiHandler) buildEventFilters(gc *gin.Context) (
157171 }
158172
159173 // Other conditions
160- var errBuild error
161174 argIndex , errBuild = sql_utils .BuildTimeCondition (
162175 timeStr , "edp.start_time" , "time" , argIndex , & conditions , & args )
163176 if errBuild != nil {
@@ -207,6 +220,7 @@ func (h *ApiHandler) buildEventFilters(gc *gin.Context) (
207220 if errBuild != nil {
208221 return "" , "" , "" , nil , 0 , errBuild
209222 }
223+
210224 if eventIdsStr != "" {
211225 argIndex , errBuild = sql_utils .BuildColumnInIntCondition (
212226 eventIdsStr , "edp.event_id" , argIndex , & conditions , & args )
@@ -264,6 +278,13 @@ func (h *ApiHandler) buildEventFilters(gc *gin.Context) (
264278 return "" , "" , "" , nil , 0 , errBuild
265279 }
266280
281+ argIndex , errBuild = sql_utils .BuildPriceCondition (
282+ priceStr , "ep.price_type" , "ep.currency" , "ep.min_price" , "ep.max_price" , "price" , argIndex , & conditions , & args )
283+ debugf ("priceStr: %s" , priceStr )
284+ if errBuild != nil {
285+ return "" , "" , "" , nil , 0 , errBuild
286+ }
287+
267288 argIndex , errBuild = sql_utils .BuildBitmaskCondition (
268289 accessibilityFlagsStr , "edp.space_accessibility_flags" , "accessibility" , argIndex , & conditions , & args )
269290 if errBuild != nil {
@@ -331,13 +352,13 @@ func (h *ApiHandler) GetEvents(gc *gin.Context) {
331352 query = strings .Replace (query , "{{conditions}}" , conditionsStr , 1 )
332353 query = strings .Replace (query , "{{limit}}" , limitClause , 1 )
333354
334- /*
355+ if true {
335356 fmt .Println (query )
336357 fmt .Printf ("ARGS (%d):\n " , len (args ))
337358 for i , arg := range args {
338359 fmt .Printf (" $%d = %#v (type %T)\n " , i + 1 , arg , arg )
339360 }
340- */
361+ }
341362
342363 rows , err := h .DbPool .Query (ctx , query , args ... )
343364 if err != nil {
@@ -368,6 +389,7 @@ func (h *ApiHandler) GetEvents(gc *gin.Context) {
368389 & e .TicketLink ,
369390 & e .Title ,
370391 & e .Subtitle ,
392+ & e .Categories ,
371393 & typesJSON ,
372394 & e .Languages ,
373395 & e .Tags ,
@@ -420,7 +442,11 @@ func (h *ApiHandler) GetEvents(gc *gin.Context) {
420442 }
421443
422444 if len (events ) == 0 {
423- gc .JSON (http .StatusNotFound , gin.H {"events" : events })
445+ gc .JSON (http .StatusOK , gin.H {
446+ "events" : []eventResponse {},
447+ "last_event_start_at" : nil ,
448+ "last_event_date_id" : nil ,
449+ })
424450 return
425451 }
426452
0 commit comments