From 09e163f00a63bc4db61d3f1f25b9891221825d3e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 5 Jul 2016 20:40:30 -0300 Subject: [PATCH] Ivan - Fix list-owning issues [skip ci] --- server/controllers/ticket/create.php | 8 ++++---- server/controllers/user/login.php | 1 + server/controllers/user/signup.php | 3 +++ server/models/Ticket.php | 23 ++++++++++++++++++++++- server/models/User.php | 7 +++---- tests/ticket/comment.rb | 14 ++++++++++++++ tests/ticket/create.rb | 2 +- 7 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 tests/ticket/comment.rb diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index 28c5918c..cc776be0 100644 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -58,11 +58,11 @@ class CreateController extends Controller { 'file' => '', 'date' => date("F j, Y, g:i a"), 'unread' => false, - 'closed' => false, - 'author' => null, - 'owner'=> null + 'closed' => false )); - $ticket->getBeanInstance()->ownCommentList[] = RedBean::dispense('comment'); + + //TODO: Add logged user as author + $ticket->setAuthor(User::getUser(1)); $ticket->store(); } diff --git a/server/controllers/user/login.php b/server/controllers/user/login.php index 396f5acf..494a8eeb 100644 --- a/server/controllers/user/login.php +++ b/server/controllers/user/login.php @@ -38,6 +38,7 @@ class LoginController extends Controller { return array( 'userId' => $userInstance->id, + 'list' => count($userInstance->ownTicketList), 'userEmail' => $userInstance->email, 'token' => $this->getSession()->getToken() ); diff --git a/server/controllers/user/signup.php b/server/controllers/user/signup.php index a38559d3..31d052e5 100644 --- a/server/controllers/user/signup.php +++ b/server/controllers/user/signup.php @@ -1,4 +1,5 @@ Hashing::hashPassword($password) )); + //$userInstance->getBeanInstance()->sharedTicketList[] = RedBean::dispense('ticket'); + return $userInstance->store(); } } diff --git a/server/models/Ticket.php b/server/models/Ticket.php index 73375562..8d1a8fe8 100644 --- a/server/models/Ticket.php +++ b/server/models/Ticket.php @@ -4,6 +4,8 @@ use RedBeanPHP\Facade as RedBean; class Ticket extends DataStore { const TABLE = 'ticket'; + private $author; + public static function getProps() { return array( 'ticketNumber', @@ -26,10 +28,29 @@ class Ticket extends DataStore { } public function getDefaultProps() { - return array(); + return array( + 'owner' => null + ); } + public function setAuthor(User $user) { + $this->author = $user; + $this->author->addTicket($this); + + $this->setProperties(array( + 'author' => $this->author->getBeanInstance() + )); + } + public function addComment(Comment $comment) { $this->getBeanInstance()->ownCommentList[] = $comment->getBeanInstance(); } + + public function store() { + parent::store(); + + if ($this->author instanceof User) { + $this->author->store(); + } + } } \ No newline at end of file diff --git a/server/models/User.php b/server/models/User.php index 31a1ba79..72359bca 100644 --- a/server/models/User.php +++ b/server/models/User.php @@ -15,8 +15,7 @@ class User extends DataStore { 'email', 'password', 'name', - 'verificationToken', - 'ownTicketList' + 'verificationToken' ); } @@ -24,8 +23,8 @@ class User extends DataStore { return array(); } - public function addTicket($ticket) { - $this->ownTicketList[] = $ticket; + public function addTicket(Ticket $ticket) { + $this->getBeanInstance()->sharedTicketList[] = $ticket->getBeanInstance(); } public static function getUser($value, $property = 'id') { diff --git a/tests/ticket/comment.rb b/tests/ticket/comment.rb new file mode 100644 index 00000000..3b2b12b1 --- /dev/null +++ b/tests/ticket/comment.rb @@ -0,0 +1,14 @@ +describe 'ticket/comment/' do + it 'should fail if not logged' do + + end + + describe 'on successful request' do + it 'should add comment to current ticket' do + + end + it 'should link the comment to author' do + + end + end +end \ No newline at end of file diff --git a/tests/ticket/create.rb b/tests/ticket/create.rb index 4675edec..ac0519b9 100644 --- a/tests/ticket/create.rb +++ b/tests/ticket/create.rb @@ -1,4 +1,4 @@ -describe '/user/login' do +describe '/ticket/create' do it 'should fail if title is too short' do result = request('/ticket/create',{ title: 'GG'