Skip to content

Commit

Permalink
Get not processed lcoations
Browse files Browse the repository at this point in the history
  • Loading branch information
petyos committed May 16, 2024
1 parent a8e491d commit ff921bb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ type Storage interface {
FindCalendars(id string) (*[]model.UnitCalendar, error)

InitializeLegacyLocations() error
//not used
FindLegacyLocations() (model.LegacyLocationsListType, error)

FindLegacyEventItems(context storage.TransactionContext) ([]model.LegacyEventItem, error)
Expand Down
29 changes: 29 additions & 0 deletions core/logic_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,14 @@ func (e eventsLogic) processLocations(allWebtoolsEvents []model.WebToolsEvent) (

e.logger.Infof("there are %d locations for processing", len(forProcessingLocations))

//get the locations which are not processed
notProccesed, err := e.getNotProcessedLocations(forProcessingLocations)
if err != nil {
return nil, err
}

e.logger.Infof("there are %d locations to be processed as not proccesed", len(notProccesed))

/*locationEventMap := make(map[string]map[string]string)
for _, event := range allWebtoolsEvents {
Expand Down Expand Up @@ -789,6 +797,27 @@ func (e eventsLogic) getLocationsForProcessing(allWebtoolsEvents []model.WebTool
return res, nil
}

func (e eventsLogic) getNotProcessedLocations(locationsForProcessing []string) ([]string, error) {
allProcessed, err := e.app.storage.FindLegacyLocations()
if err != nil {
return nil, err
}

processedMap := make(map[string]bool) // map to keep track of processed events
for _, item := range allProcessed {
processedMap[item.Name] = true
}

var notProcessedEvents []string
for _, loc := range locationsForProcessing {
if _, processed := processedMap[loc]; !processed {
notProcessedEvents = append(notProcessedEvents, loc)
}
}

return notProcessedEvents, nil
}

func recurenceIDtoInt(s string) (*int, error) {
// Parse string to int
parsedInt, err := strconv.Atoi(s)
Expand Down
2 changes: 1 addition & 1 deletion driven/storage/adapter_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (a *Adapter) InitializeLegacyLocations() error {
func (a *Adapter) FindLegacyLocations() (model.LegacyLocationsListType, error) {

var list model.LegacyLocationsListType
err := a.db.legacyEvents.FindWithContext(a.context, bson.D{}, &list, options.Find().SetSort(bson.D{{Key: "name", Value: 1}}))
err := a.db.legacyLocations.FindWithContext(a.context, bson.D{}, &list, options.Find().SetSort(bson.D{{Key: "name", Value: 1}}))
if err != nil {
return nil, errors.WrapErrorAction(logutils.ActionFind, model.TypeEventLocations, nil, err)
}
Expand Down

0 comments on commit ff921bb

Please sign in to comment.