define(['./module'], function(app) {
    'use strict';

    var mapEvents = function(googleEvent) {
        return {
            title: googleEvent.summary,
            description: googleEvent.description,
            location: googleEvent.location,
            startDate: Date.parse(googleEvent.start.dateTime),
            endDate: Date.parse(googleEvent.end.dateTime),
            url: googleEvent.htmlLink
        }
    };

    var eventsRepository = function($http, $q) {
        this.getCommunityEvents = function(community, minDate, maxDate) {
            var patterns = community.patternsGoogleCalendar;
            if (patterns == undefined){
                patterns = [ community.key ];
            }
            var deferred = $q.defer();
            var asyncGoogleApiCalls = [];
            for(var index = 0; index < patterns.length; index++) {
                asyncGoogleApiCalls.push($http.get("https://www.googleapis.com/calendar/v3/calendars/ck2ruq6cqfch3t4gshbd6vdnd4@group.calendar.google.com/events?key=AIzaSyAHKI9T7fhK68b2eggUCHlu9eOwsdFUrhg&singleEvents=true"
                    + "&q=" + patterns[index]
                    + "&timeMin=" + minDate.toISOString()
                    + "&timeMax=" + maxDate.toISOString()));
            }

            $q.all(asyncGoogleApiCalls).then(function(result){
                var events = [];
                for(var index = 0; index < result.length; index++) {
                    events = events.concat(result[index].data.items.map(mapEvents));
                }
                deferred.resolve(events);
            });

            return deferred.promise;
        };
    };

    app.factory('eventsRepository', ['$http', '$q', function($http, $q) {
        return new eventsRepository($http, $q);
    }]);
});
@@ -110,16 +110,48 @@
 eturn %7B%0A
+            id: googleEvent.id,%0A
         
@@ -450,24 +450,347 @@
   %7D%0A    %7D;%0A%0A
+    var removeDuplicates = function(events) %7B%0A      var tmpEvents = %7B%7D;%0A      for (var i = 0, n = events.length; i %3C n; i++) %7B%0A        tmpEvents%5Bevents%5Bi%5D.id%5D = events%5Bi%5D;%0A      %7D%0A      var i = 0;%0A      events = %5B%5D;%0A      for(var id in tmpEvents) %7B%0A        events%5Bi++%5D = tmpEvents%5Bid%5D;%0A      %7D%0A      return events;%0A    %7D;%0A%0A
     var even
@@ -1914,23 +1914,41 @@
 resolve(
+removeDuplicates(
 events)
+)
 ;%0A      
@@ -2148,8 +2148,9 @@
 %7D%5D);%0A%7D);
+%0A

Remove duplicates when two pattern matches the same event