From cf6202b608e61719efb69db5184f28bc0c0d278e Mon Sep 17 00:00:00 2001 From: Everest Date: Mon, 29 Jan 2024 00:18:39 -0300 Subject: [PATCH] fix filter function --- pkg/event/service_event.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/event/service_event.go b/pkg/event/service_event.go index f760013..e941de6 100644 --- a/pkg/event/service_event.go +++ b/pkg/event/service_event.go @@ -39,7 +39,14 @@ func (e *EventService) Get( limit = 50 } now := time.Now() - base := e.db.Joins("User"). + base := e.db. + Select("events.*, array_agg(tags.tag) as tags, array_agg(venues.*) as venues"). + Group("events.id, events.title, events.banner, events.description, events.href, events.type_of, events.begin_date, events.end_date, events.user_id, events.created_at, events.updated_at, events.deleted_at, \"User\".id"). + Joins("User"). + Joins("JOIN events_tags ON events_tags.event_id = events.id"). + Joins("JOIN tags ON tags.id = events_tags.tag_id"). + Joins("JOIN events_venues ON events_venues.event_id = events.id"). + Joins("JOIN venues ON venues.id = events_venues.venue_id"). Preload("Attendees"). Preload("Tags", func(db *gorm.DB) *gorm.DB { if len(tags) > 0 { @@ -59,6 +66,12 @@ func (e *EventService) Get( if lo.IsNotEmpty(name) { base.Where("name like ?", name) } + if lo.IsNotEmpty(city) { + base.Where("venues.city = ?", city) + } + if len(tags) > 0 { + base.Where("tags.tag in ?", tags) + } if len(typeOf) > 0 { base.Where("? in ANY(typeOf)", typeOf) }