From de2434bda1058bdde6b03b412417fece3ea8547a Mon Sep 17 00:00:00 2001 From: dud3 Date: Mon, 24 Nov 2014 20:50:08 +0000 Subject: [PATCH] [TASK|FUNCTION|IMPROVE] Save Keywords page Change - Access the email server throgh http API Resolves: #34 Related: #35 Releases: 2.1.x --- app/config/mail.php | 2 +- app/config/services.php | 2 +- app/controllers/ListController.php | 37 ++++++++-- .../EloquentKeywordsRepository.php | 17 +++-- app/repositories/EloquentListRepository.php | 70 ++++++++++++++----- .../EloquentListRepositoryInterface.php | 17 ++--- app/repositories/EmailsRepository.php | 13 +++- app/routes.php | 5 +- app/start/global.php | 5 +- app/views/__modals__/keywords_list/create.php | 2 +- composer.json | 3 +- public/scripts/app.js | 2 +- .../scripts/controllers/keyWordsListCtrl.js | 69 +++++++++++++++++- public/scripts/factories/keyWordsListSvc.js | 4 +- 14 files changed, 193 insertions(+), 55 deletions(-) diff --git a/app/config/mail.php b/app/config/mail.php index 843d43b..98ef4b4 100644 --- a/app/config/mail.php +++ b/app/config/mail.php @@ -15,7 +15,7 @@ | */ - 'driver' => 'smtp', + 'driver' => 'mandrill', /* |-------------------------------------------------------------------------- diff --git a/app/config/services.php b/app/config/services.php index c8aba2a..f7c5f03 100644 --- a/app/config/services.php +++ b/app/config/services.php @@ -20,7 +20,7 @@ ), 'mandrill' => array( - 'secret' => '', + 'secret' => 'Y43YmTMvJAFJTg8OFKJFBA', ), 'stripe' => array( diff --git a/app/controllers/ListController.php b/app/controllers/ListController.php index 361c44f..4a89090 100644 --- a/app/controllers/ListController.php +++ b/app/controllers/ListController.php @@ -12,26 +12,36 @@ class ListController extends internalCtrl { public $user; - public $ketwords; + public $lists; + public $keywords; + public $emails; /** * [__construct description] */ - public function __construct(EloquentKeywordsRepositoryInterface $keywords) { + public function __construct(EloquentListRepositoryInterface $lists, EloquentKeywordsRepositoryInterface $keywords, EloquentEmailsRepository $emails) { + $this->lists = $lists; $this->keywords = $keywords; + $this->emails = $emails; } /** - * [view_emails description] + * view keywords list. * @return [type] [description] */ public function view_k_list() { - $view = View::make('list.keywords'); - return $view; + } + /** + * view emails list. + * @return [type] [description] + */ + public function view_e_list() { + $view = View::make('list.emails'); + return $view; } /** @@ -42,4 +52,21 @@ public function get_all_keywords() { return Response::json(['keywords' => $this->keywords->get_all()], 200); } + /** + * Create keywords list + * @return [array] [array of objects] + */ + public function create_keywords_list() { + + $input = Input::all(); + $ret = $this->lists->create_keywords_list($input); + + if(!$ret->error) { + $ret = Response::json(["ketwordsList" => $ret], 200); + } else { + $ret = Response::json([$ret->error], 401); + } + + } + } diff --git a/app/repositories/EloquentKeywordsRepository.php b/app/repositories/EloquentKeywordsRepository.php index 91d85b3..c2448b6 100644 --- a/app/repositories/EloquentKeywordsRepository.php +++ b/app/repositories/EloquentKeywordsRepository.php @@ -66,6 +66,8 @@ public function get_by_id($id = null) { */ public function store($data = null) { + $ret = []; + try { if($data != null) { @@ -74,7 +76,8 @@ public function store($data = null) { if(self::validate($data)) { - return keywords_list::create($data); + $ret = keywords_list::create($data); + return $ret; } else { throw new RuntimeException("Error Processing Request", 1); @@ -114,15 +117,11 @@ public function update($data = null) { if(!empty($data)) { - if(self::validate($data)) { - - $k = keywords_list::fill($data); - $k->save(); - return $k; - } else { - throw new RuntimeException("Error Processing Request", 1); - } + $k = keywords_list::fill($data); + $k->save(); + $k->error = false; + return $k; } else { throw new RuntimeException("Error, The array can not be empty", 0.2); diff --git a/app/repositories/EloquentListRepository.php b/app/repositories/EloquentListRepository.php index 6ddbb13..4dce78f 100644 --- a/app/repositories/EloquentListRepository.php +++ b/app/repositories/EloquentListRepository.php @@ -5,17 +5,19 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; - class EloquentListRepository implements EloquentListRepositoryInterface { - protected $main_sql = null; protected $list_type; + protected $keywords; + protected $emails; + /** * Main Constructor. */ - public function __construct() { - + public function __construct(EloquentKeywordsRepositoryInterface $keywords, EloquentEmailsRepository $emails) { + $this->keywords = $keywords; + $this->emails = $emails; } /** @@ -29,44 +31,74 @@ public function __call_list($type) { switch ($this->list_type) { - case 'get_list_by_keyword': - $this->get_list_by_keyword(); + case 'get_email_list': + $this->get_email_list(); break; - case 'get_list_by_email': - $this->get_list_by_email(); + case 'get_keyword_list': + $this->get_keyword_list(); break; } } - /** - * Main query gues here + * Get list by keywords. * @return [type] [description] */ - public function mainQuery() { - + public function get_email_list() { + return $this->keywords->get_all(); } - /** - * Get list by keywords. + * Get list by emails. * @return [type] [description] */ - public function get_list_by_keyword() { + public function get_keyword_list() { } - /** - * Get list by emails. + * Create Keyword list. * @return [type] [description] */ - public function get_list_by_email() { + public function create_keywords_list($data) { - } + $ret = []; + try { + + if($data != null) { + + if(!empty($data)) { + + $keywords = $this->keywords->store($data["keywords"]); + $recipients = $this->emails->store($data["recipients"]); + + $ret = ["id" => $keywords['id'], "keywords" => $keywords["keywords"], "email" => $recipients["emails"]]; + return $ret; + + } else { + throw new RuntimeException("Error, The array can not be empty", 0.2); + + } + + } else { + throw new RuntimeException("Errorm The array can not be null", 0.1); + } + + } catch(RuntimeException $e) { + + $error = new stdClass(); + $error->message = $e->getMessage(); + $error->code = $e->getCode(); + $error->error = true; + + return $error; + + } + + } } \ No newline at end of file diff --git a/app/repositories/EloquentListRepositoryInterface.php b/app/repositories/EloquentListRepositoryInterface.php index 784d989..70ff1d6 100644 --- a/app/repositories/EloquentListRepositoryInterface.php +++ b/app/repositories/EloquentListRepositoryInterface.php @@ -8,23 +8,24 @@ interface EloquentListRepositoryInterface { * @return [type] [description] */ public function __call_list($type); - + /** - * Main query gues here + * Get list by keywords. * @return [type] [description] */ - public function mainQuery(); + public function get_email_list(); /** - * Get list by keywords. + * Get list by emails. * @return [type] [description] */ - public function get_list_by_keyword(); + public function get_keyword_list(); /** - * Get list by emails. - * @return [type] [description] + * Create keywords list + * @param [array] $data [array of objects] + * @return [array] [array of objects] */ - public function get_list_by_email(); + public function create_keywords_list($data); } \ No newline at end of file diff --git a/app/repositories/EmailsRepository.php b/app/repositories/EmailsRepository.php index 84f0e3d..71679e9 100644 --- a/app/repositories/EmailsRepository.php +++ b/app/repositories/EmailsRepository.php @@ -243,7 +243,7 @@ public function sendMails($fwd_from = null, $test_user_only = false) { FROM mails m - LEFT OUTER JOIN email_address_list e_a_l + LEFT JOIN email_address_list e_a_l ON m.email_address_id = e_a_l.id WHERE m.sent = 0 @@ -271,6 +271,15 @@ public function sendMails($fwd_from = null, $test_user_only = false) { "message_body" => $message_body, "message_subject" => $message_subject]; + // Error handling + foreach ($data as $inputs) { + if($inputs == null || empty($inputs)) { + var_dump($data); + throw new Exception("Some data is missing", 1); + exit; + } + } + // // Basically what we're doing here is that // -> whenever we see a text that says 'Click here' @@ -436,8 +445,6 @@ public function getEmailKeywords($data) { if(count($k_arr_diff) == 0) { - var_dump("we're in..."); - $e_add_list = email_address_list::where("keyword_id", "=", $k_id)->get()->toArray(); if($e_add_list !== null) { diff --git a/app/routes.php b/app/routes.php index d4d545d..2c88158 100644 --- a/app/routes.php +++ b/app/routes.php @@ -57,7 +57,10 @@ Route::group(array('prefix' => 'api/v1'), function() { - Route::get('getAllKeywords', 'ListController@get_all_keywords'); + Route::group(array('prefix' => 'keywords'), function(){ + Route::get('get', 'ListController@get_all_keywords'); + Route::get('create', 'ListController@create_keywords_list'); + }); Route::group(array('prefix' => 'emails'), function() { diff --git a/app/start/global.php b/app/start/global.php index 6efd93a..bbec272 100644 --- a/app/start/global.php +++ b/app/start/global.php @@ -9,8 +9,10 @@ $app['Cartalyst\Sentry\Sentry'] = $app['sentry']; App::bind('UserRepositoryInterface', 'SentryUserRepository'); + +App::bind('EloquentListRepositoryInterface', 'EloquentListRepository'); + App::bind('EmailsRepositoryInterface', 'EmailsRepository'); -App::bind('EloquentListRepository', 'EloquentListRepositoryInterface'); App::bind('EloquentEmailsRepositoryInterface', 'EloquentEmailsRepository'); App::bind('EloquentKeywordsRepositoryInterface', 'EloquentKeywordsRepository'); @@ -30,6 +32,7 @@ app_path().'/commands', app_path().'/controllers', app_path().'/models', + app_path().'/repositories', app_path().'/database/seeds', )); diff --git a/app/views/__modals__/keywords_list/create.php b/app/views/__modals__/keywords_list/create.php index 8a83a21..c1bd94e 100644 --- a/app/views/__modals__/keywords_list/create.php +++ b/app/views/__modals__/keywords_list/create.php @@ -4,7 +4,7 @@