diff --git a/.gitignore b/.gitignore index b8c5d68..d6cfeee 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /.idea /.idea/workspace.xml /.sass-cache -.DS_Store \ No newline at end of file +.DS_Store +/storage/debugbar/**/* \ No newline at end of file diff --git a/app/Http/Controllers/TicketsController.php b/app/Http/Controllers/TicketsController.php index cc11c3a..35dec9f 100644 --- a/app/Http/Controllers/TicketsController.php +++ b/app/Http/Controllers/TicketsController.php @@ -4,15 +4,21 @@ use Illuminate\Support\Facades\Redirect; use Illuminate\Http\Request; +use TeachMe\Repositories\CommentRepository; use TeachMe\Repositories\TicketRepository; class TicketsController extends Controller { private $ticketRepository; + private $commentRepository; - public function __construct(TicketRepository $ticketRepository) + public function __construct( + TicketRepository $ticketRepository, + CommentRepository $commentRepository + ) { $this->ticketRepository = $ticketRepository; + $this->commentRepository = $commentRepository; } public function latest() @@ -66,4 +72,16 @@ public function store(Request $request) return Redirect::route('tickets.details', $ticket->id); } + public function close(Request $reques, $id) + { + $link = $reques->get('link'); + $comment_id = $reques->get('comment_id'); + + $ticket = $this->ticketRepository->closeTicket($id, $link); + + $comment = $this->commentRepository->selected($comment_id); + + return Redirect::route('tickets.details', $ticket->id); + } + } diff --git a/app/Http/routes.php b/app/Http/routes.php index 0e3f934..c1232c1 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -29,6 +29,10 @@ 'as' => 'tickets.details', 'uses' => 'TicketsController@details' ]); +Route::post('/solicitud/{id}', [ + 'as' => 'tickets.details', + 'uses' => 'TicketsController@close' +]); Route::controllers([ 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', diff --git a/app/Repositories/CommentRepository.php b/app/Repositories/CommentRepository.php index 5359be5..abbc44d 100644 --- a/app/Repositories/CommentRepository.php +++ b/app/Repositories/CommentRepository.php @@ -20,4 +20,13 @@ public function create(Ticket $ticket, User $user, $comment, $link = '') $ticket->comments()->save($comment); } + public function selected($id) + { + $comment = $this->findOrFail($id); + + $comment->selected = true; + + return $comment->save(); + } + } \ No newline at end of file diff --git a/app/Repositories/TicketRepository.php b/app/Repositories/TicketRepository.php index c3eab95..d256a62 100644 --- a/app/Repositories/TicketRepository.php +++ b/app/Repositories/TicketRepository.php @@ -52,4 +52,16 @@ public function openNew($user, $title, $link = '') ]); } + public function closeTicket($id, $link) + { + $ticket = $this->findOrFail($id); + + $ticket->status = 'closed'; + $ticket->link = $link; + + $ticket->save(); + + return $ticket; + } + } \ No newline at end of file diff --git a/database/migrations/2015_12_15_234610_add_selected_to_tickets_comments.php b/database/migrations/2015_12_15_234610_add_selected_to_tickets_comments.php new file mode 100644 index 0000000..e40bd10 --- /dev/null +++ b/database/migrations/2015_12_15_234610_add_selected_to_tickets_comments.php @@ -0,0 +1,34 @@ +boolean('selected') + ->after('link') + ->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('ticket_comments', function(Blueprint $table){ + $table->dropColumn('selected'); + }); + } +} diff --git a/resources/views/tickets/details.blade.php b/resources/views/tickets/details.blade.php index cb8faf4..403ddfc 100644 --- a/resources/views/tickets/details.blade.php +++ b/resources/views/tickets/details.blade.php @@ -81,6 +81,7 @@ {{ $comment->link }} + @include('tickets.partials.select-tutorial')
@endifdiff --git a/resources/views/tickets/partials/select-tutorial.blade.php b/resources/views/tickets/partials/select-tutorial.blade.php new file mode 100644 index 0000000..477bb12 --- /dev/null +++ b/resources/views/tickets/partials/select-tutorial.blade.php @@ -0,0 +1,7 @@ +
+ diff --git a/tests/ResourceTest.php b/tests/ResourceTest.php index 1fcada1..0bd8cd7 100644 --- a/tests/ResourceTest.php +++ b/tests/ResourceTest.php @@ -37,4 +37,44 @@ public function test_create_resource() ->seeLink('Ver recurso', $this->link); } + public function test_select_resource() + { + // Having + $user = seed('User'); + + $ticket = seed('Ticket',[ + 'title' => $this->title, + 'user_id' => $user->id, + 'status' => 'open' + ]); + + + $comment = seed('TicketComment',[ + 'ticket_id' => $ticket->id, + 'link' => $this->link, + ]); + + // When + $this->actingAs($user) + ->visit(route('tickets.details', $ticket)) + ->press('Seleccionar tutorial'); + + // Then + $this->seeInDatabase('tickets',[ + 'id' => $ticket->id, + 'status' => 'closed', + 'link' => $this->link, + ]); + + + $this->seeInDatabase('ticket_comments', [ + 'id' => $comment->id, + 'selected' => true + ]); + + $this->seePageIs(route('tickets.details', $ticket)); + + $this->seeLink('Ver recurso', $this->link); + } + }