Merged in create-ticket/comment (pull request #18)

Create ticket/comment
This commit is contained in:
Ivan Diaz 2016-07-08 04:02:55 -03:00
commit 89b2e52e87
11 changed files with 101 additions and 21 deletions

View File

@ -1,9 +1,11 @@
<?php
include 'ticket/create.php';
include 'ticket/comment.php';
$ticketControllers = new ControllerGroup();
$ticketControllers->setGroupPath('/ticket');
$ticketControllers->addController(new CreateController);
$ticketControllers->addController(new CommentController);
$ticketControllers->finalize();

View File

@ -0,0 +1,32 @@
<?php
use RedBeanPHP\Facade as RedBean;
class CommentController extends Controller {
const PATH = '/comment';
private $ticketId;
private $content;
public function handler() {
$this->requestData();
$this->storeComment();
Response::respondSuccess();
}
private function requestData() {
$this->ticketId = Controller::request('ticketId');
$this->content = Controller::request('content');
}
private function storeComment() {
$comment = new Comment();
$comment->setProperties(array(
'content' => $this->content
));
$ticket = Ticket::getTicket($this->ticketId);
$ticket->addComment($comment);
$ticket->store();
}
}

View File

@ -1,11 +1,12 @@
<?php
use RedBeanPHP\Facade as RedBean;
use Respect\Validation\Validator as DataValidator;
class CreateController extends Controller {
const PATH = '/create';
private $title ;
private $title;
private $content;
private $departmentId;
private $language;
@ -51,11 +52,12 @@ class CreateController extends Controller {
'file' => '',
'date' => date('F j, Y, g:i a'),
'unread' => false,
'closed' => false,
'author' => '',
'owner'=> '',
'ownComments' => []
'closed' => false
));
//TODO: Add logged user as author
$ticket->setAuthor(User::getUser(1));
$ticket->store();
}
}

View File

@ -45,6 +45,7 @@ class LoginController extends Controller {
return array(
'userId' => $userInstance->id,
'list' => count($userInstance->ownTicketList),
'userEmail' => $userInstance->email,
'token' => $this->getSession()->getToken()
);

View File

@ -1,4 +1,5 @@
<?php
use RedBeanPHP\Facade as RedBean;
class SignUpController extends Controller {
const PATH = '/signup';

View File

@ -1,7 +1,7 @@
<?php
class Comment extends DataStore {
const TABLE = 'comments';
const TABLE = 'comment';
public static function getProps() {
return array(

View File

@ -1,11 +1,14 @@
<?php
use RedBeanPHP\Facade as RedBean;
class Ticket extends DataStore {
const TABLE = 'tickets';
const TABLE = 'ticket';
private $author;
public static function getProps() {
return array(
'ticketId',
'ticketNumber',
'title',
'content',
'language',
@ -16,11 +19,38 @@ class Ticket extends DataStore {
'closed',
'author',
'owner',
'ownComments'
'ownCommentList'
);
}
protected function getDefaultProps() {
return array();
public static function getTicket($value, $property = 'id') {
return parent::getDataStore($value, $property);
}
public function getDefaultProps() {
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();
}
}
}

View File

@ -1,7 +1,8 @@
<?php
use RedBeanPHP\Facade as RedBean;
class User extends DataStore {
const TABLE = 'users';
const TABLE = 'user';
public static function authenticate($userEmail, $userPassword) {
$user = User::getUser($userEmail, 'email');
@ -14,19 +15,16 @@ class User extends DataStore {
'email',
'password',
'name',
'verificationToken',
'ownTickets'
'verificationToken'
);
}
public function getDefaultProps() {
return array(
'ownTickets' => []
);
return array();
}
public function addTicket($ticket) {
$this->ownTickets[] = $ticket;
public function addTicket(Ticket $ticket) {
$this->getBeanInstance()->sharedTicketList[] = $ticket->getBeanInstance();
}
public static function getUser($value, $property = 'id') {

14
tests/ticket/comment.rb Normal file
View File

@ -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

View File

@ -50,7 +50,7 @@ describe '/ticket/create' 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

View File

@ -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