In this approach, the complex logic shown previously in the calling program is transferred to the domain service class in a custom method called salesReportByCountry() instead. As with the logic shown previously, first, we initialize the variables:
def salesReportByCountry(self, year) :
from bson.regex import Regex
pattern = '^' + str(year)
regex = Regex(pattern)
query = dict({'dateOfPurchase':{'$regex':regex}})
proj = dict({'dateOfPurchase':1,'extendedPrice':1, \
'country':1,'_id':0})
order = [('country', 1),('dateOfPurchase', 1)]
results = {}
We then implement exactly the same logic shown in the calling program prior:
for doc in self.genericFetch(query, proj, order) :
country = doc['country']
dop = doc['dateOfPurchase'...