As with other domain service classes described earlier in this book, we'll create a folder called /path/to/repo/chapters/07/src/booksomeplace/domain. The filename is property.py, while the class is PropertyService, which extends Base:
# booksomeplace.domain.property
import pymongo
from pymongo.cursor import CursorType
from booksomeplace.domain.base import Base
from booksomeplace.entity.base import Name, Contact, Location
from booksomeplace.entity.property import Property, PropInfo, Review, RoomType
class PropertyService(Base) :
collectName = 'properties'
Next, we define a method called fetchByKey() that returns a single Property instance based on key lookup:
def fetchByKey(self, key) :
query = {'propertyKey':key}
result = self.collection.find_one(query)
if result :
return self.assemble(result)
else :
return None
After that, we define a method called fetchTop10() that...