summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2015-02-03 17:17:14 -0200
committerDuda Dornelles <ddornell@thoughtworks.com>2015-02-03 17:17:14 -0200
commit543e43ce85bb5d8863dbbf2a458af92d21b018cf (patch)
tree9f2abc8b4a388c48a3e8a537a009c34c12966dd1 /service
parentab571c6985a4ef68bade13c2bb2e42a2f014e994 (diff)
Moving mails_resouce render_GET logic to mail_service
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/services/mail_service.py9
-rw-r--r--service/pixelated/config/app_factory.py3
-rw-r--r--service/pixelated/resources/mails_resource.py5
-rw-r--r--service/test/support/integration/app_test_client.py4
4 files changed, 11 insertions, 10 deletions
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py
index cb844ddf..ab0b16bd 100644
--- a/service/pixelated/adapter/services/mail_service.py
+++ b/service/pixelated/adapter/services/mail_service.py
@@ -18,17 +18,20 @@
class MailService:
__slots__ = ['leap_session', 'account', 'mailbox_name']
- def __init__(self, mailboxes, mail_sender, tag_service, soledad_querier):
+ def __init__(self, mailboxes, mail_sender, tag_service, soledad_querier, search_engine):
self.tag_service = tag_service
self.mailboxes = mailboxes
self.querier = soledad_querier
+ self.search_engine = search_engine
self.mail_sender = mail_sender
def all_mails(self):
return self.querier.all_mails()
- def mails(self, ids):
- return self.querier.mails(ids)
+ def mails(self, query, window_size, page):
+ mail_ids, total = self.search_engine.search(query, window_size, page)
+
+ return self.querier.mails(mail_ids), total
def update_tags(self, mail_id, new_tags):
reserved_words = self.tag_service.extract_reserved(new_tags)
diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py
index f2810e08..9937c65b 100644
--- a/service/pixelated/config/app_factory.py
+++ b/service/pixelated/config/app_factory.py
@@ -105,7 +105,7 @@ def init_app(app, leap_home, leap_session):
pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier)
draft_service = DraftService(pixelated_mailboxes)
- mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, tag_service, soledad_querier)
+ mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, tag_service, soledad_querier, search_engine)
MailboxIndexerListener.SEARCH_ENGINE = search_engine
InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email()
@@ -148,7 +148,6 @@ def _ssl_options(args):
acceptableCiphers=acceptable)
return options
-
def listen_with_ssl(app, args):
reactor.listenSSL(args.port, Site(app.resource), _ssl_options(args), interface=args.host)
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index 4280d7ec..41d1d702 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -91,9 +91,8 @@ class MailsResource(Resource):
self._register_smtp_error_handler()
def render_GET(self, request):
- mail_ids, total = self._search_engine.search(request.args.get('q')[0], request.args.get('w')[0],
- request.args.get('p')[0])
- mails = self._mail_service.mails(mail_ids)
+ query, window_size, page = request.args.get('q')[0], request.args.get('w')[0], request.args.get('p')[0]
+ mails, total = self._mail_service.mails(query, window_size, page)
response = {
"stats": {
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 8d8d0d1f..45f81cc1 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -67,9 +67,9 @@ class AppTestClient:
self.mail_sender = Mock()
self.tag_service = TagService()
self.draft_service = DraftService(self.mailboxes)
- self.mail_service = MailService(self.mailboxes, self.mail_sender, self.tag_service,
- self.soledad_querier)
self.search_engine = SearchEngine(self.soledad_querier, agent_home=soledad_test_folder)
+ self.mail_service = MailService(self.mailboxes, self.mail_sender, self.tag_service,
+ self.soledad_querier, self.search_engine)
self.search_engine.index_mails(self.mail_service.all_mails())
self.app.resource = RootResource()