From f4450e81de9bcb40a09c670c80a8ada2cff9729a Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 3 Jul 2016 21:32:34 -0300 Subject: [PATCH] Ivan - Update ownCommentList logic for tickets [skip ci] --- server/controllers/ticket/comment.php | 31 ++++++++------------------- server/controllers/ticket/create.php | 7 +++--- server/models/Comment.php | 2 +- server/models/Ticket.php | 15 ++++++++----- server/models/User.php | 11 +++++----- tests/ticket/create.rb | 2 +- tests/user/signup.rb | 2 +- 7 files changed, 31 insertions(+), 39 deletions(-) diff --git a/server/controllers/ticket/comment.php b/server/controllers/ticket/comment.php index 58f7b40b..3854c86f 100644 --- a/server/controllers/ticket/comment.php +++ b/server/controllers/ticket/comment.php @@ -8,38 +8,25 @@ class CommentController extends Controller { private $content; public function handler() { - /* - //$this->storeComment(); - $ticket = RedBean::load('tickets', Controller::request('ticketId')); - $comment = RedBean::dispense('comments'); - $comment->content = Controller::request('content'); + $this->requestData(); + $this->storeComment(); - $ticket->ownCommentsList[] = $comment; + Response::respondSuccess(); + } - RedBean::store($ticket); - $ticket = RedBean::load('tickets', Controller::request('ticketId')); - - $string = ""; - $string += count($ticket->ownCommentsList); - - foreach( $ticket->ownCommentsList as $comment2 ) { - }*/ + private function requestData() { + $this->ticketId = Controller::request('ticketId'); + $this->content = Controller::request('content'); } private function storeComment() { - $this->ticketId = Controller::request('ticketId'); - $this->content = Controller::request('content'); - $ticket = Ticket::getTicket($this->ticketId); - $comment = new Comment(); $comment->setProperties(array( 'content' => $this->content - //'ticket' => $ticket->getBeanInstance() )); - $ticket->getBeanInstance()->ownCommentsList = [$comment->getBeanInstance()]; - $ticket->store(); $ticket = Ticket::getTicket($this->ticketId); - Response::respondError(count($ticket->ownCommentsList)); + $ticket->addComment($comment); + $ticket->store(); } } \ No newline at end of file diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index f60dc85c..28c5918c 100644 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -59,10 +59,11 @@ class CreateController extends Controller { 'date' => date("F j, Y, g:i a"), 'unread' => false, 'closed' => false, - 'author' => '', - 'owner'=> '', - 'ownComments' => [] + 'author' => null, + 'owner'=> null )); + $ticket->getBeanInstance()->ownCommentList[] = RedBean::dispense('comment'); + $ticket->store(); } } \ No newline at end of file diff --git a/server/models/Comment.php b/server/models/Comment.php index 968e013b..da011200 100644 --- a/server/models/Comment.php +++ b/server/models/Comment.php @@ -1,7 +1,7 @@ getBeanInstance()->ownCommentList[] = $comment->getBeanInstance(); + } } \ No newline at end of file diff --git a/server/models/User.php b/server/models/User.php index f1cf37b3..31a1ba79 100644 --- a/server/models/User.php +++ b/server/models/User.php @@ -1,7 +1,8 @@ [] - ); + return array(); } public function addTicket($ticket) { - $this->ownTickets[] = $ticket; + $this->ownTicketList[] = $ticket; } public static function getUser($value, $property = 'id') { diff --git a/tests/ticket/create.rb b/tests/ticket/create.rb index 8742c287..4675edec 100644 --- a/tests/ticket/create.rb +++ b/tests/ticket/create.rb @@ -50,7 +50,7 @@ describe '/user/login' do }) (result['status']).should.equal('success') - ticket = $database.getRow('tickets','Winter is coming','title') + ticket = $database.getRow('ticket','Winter is coming','title') (ticket['content']).should.equal('The north remembers') end end \ No newline at end of file diff --git a/tests/user/signup.rb b/tests/user/signup.rb index 51c3885f..c22af4c5 100644 --- a/tests/user/signup.rb +++ b/tests/user/signup.rb @@ -5,7 +5,7 @@ describe '/user/signup' do 'password' => 'custom' }) - userRow = $database.getRow('users', response['data']['userId']) + userRow = $database.getRow('user', response['data']['userId']) (userRow['email']).should.equal('steve@jobs.com') end