I have the structures below. I use Golang 1.9.2.
// EventBoost describes the model of a EventBoost
type EventBoost struct {
ID string `bson:"_id" json:"_id" valid:"alphanum,printableascii"`
CampaignID string `bson:"_campaign_id" json:"_campaign_id" valid:"alphanum,printableascii"`
Name string `bson:"name" json:"name"`
Description string `bson:"description" json:"description"`
Level string `bson:"level" json:"level"`
EventID string `bson:"_event_id" json:"_event_id" valid:"alphanum,printableascii"`
StartDate time.Time `bson:"start_date" json:"start_date"`
EndDate time.Time `bson:"end_date" json:"end_date"`
IsPublished bool `bson:"is_published" json:"is_published"`
CreatedBy string `bson:"created_by" json:"created_by"`
CreatedAt time.Time `bson:"created_at" json:"created_at"`
ModifiedAt time.Time `bson:"modified_at" json:"modified_at"`
}
// LocationBoost describes the model of a LocationBoost
type LocationBoost struct {
ID string `bson:"_id" json:"_id" valid:"alphanum,printableascii"`
CampaignID string `bson:"_campaign_id" json:"_campaign_id" valid:"alphanum,printableascii"`
Name string `bson:"name" json:"name"`
Description string `bson:"description" json:"description"`
Level string `bson:"level" json:"level"`
LocationID string `bson:"_location_id" json:"_location_id" valid:"alphanum,printableascii"`
StartDate time.Time `bson:"start_date" json:"start_date"`
EndDate time.Time `bson:"end_date" json:"end_date"`
IsPublished bool `bson:"is_published" json:"is_published"`
CreatedBy string `bson:"created_by" json:"created_by"`
CreatedAt time.Time `bson:"created_at" json:"created_at"`
ModifiedAt time.Time `bson:"modified_at" json:"modified_at"`
}
// Campaign describes the model of a Campaign
type Campaign struct {
ID string `bson:"_id" json:"_id" valid:"alphanum,printableascii"`
Name string `bson:"name" json:"name"`
Description string `bson:"description" json:"description"`
EventBoostIDs []string `bson:"event_boost_ids" json:"event_boost_ids"`
LocationBoostIDs []string `bson:"location_boost_ids" json:"location_boost_ids"`
StartDate time.Time `bson:"start_date" json:"start_date"`
EndDate time.Time `bson:"end_date" json:"end_date"`
IsPublished bool `bson:"is_published" json:"is_published"`
CreatedBy string `bson:"created_by" json:"created_by"`
CreatedAt time.Time `bson:"created_at" json:"created_at"`
ModifiedAt time.Time `bson:"modified_at" json:"modified_at"`
}
A Campaign (understand a marketing campaign) is made of Events or Locations that can be boosted with a level (basic or premium). A campaign has a start and a end date, so do have the boosts.
The function GetEventLevel
has to return me the level of a given event.
// GetEventLevel of an event
func (dao *campaignDAO) GetEventLevel(eventID string) (string, error) {
}
If the event is boosted in an active campaign (isPublished
is true
), and the boost is active (isPublished
is true
) and the now date is between the start and end date of the boost, then my Event is boosted, so the function returns the level (basic or premium). Else, it returns "standard"
.
My question is : can I do this fully with Mongo ? Or do I need to perform some logic in the DAO with Golang ?
If I can do this with Mongo, what I hope, I have no idea how to do this. From what I understand, I would first need to lookup the events and the locations of the campaign, and then search in it with dates, but..