From 543e43ce85bb5d8863dbbf2a458af92d21b018cf Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Tue, 3 Feb 2015 17:17:14 -0200 Subject: Moving mails_resouce render_GET logic to mail_service --- service/pixelated/adapter/services/mail_service.py | 9 ++++++--- service/pixelated/config/app_factory.py | 3 +-- service/pixelated/resources/mails_resource.py | 5 ++--- service/test/support/integration/app_test_client.py | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) (limited to 'service') 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() -- cgit v1.2.3