Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.idea
/.idea/workspace.xml
/.sass-cache
.DS_Store
.DS_Store
/storage/debugbar/**/*
20 changes: 19 additions & 1 deletion app/Http/Controllers/TicketsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}

}
4 changes: 4 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions app/Repositories/CommentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
12 changes: 12 additions & 0 deletions app/Repositories/TicketRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

class AddSelectedToTicketsComments extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('ticket_comments', function(Blueprint $table){
$table->boolean('selected')
->after('link')
->default(false);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('ticket_comments', function(Blueprint $table){
$table->dropColumn('selected');
});
}
}
1 change: 1 addition & 0 deletions resources/views/tickets/details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<a href="{{ $comment->link }}" rel="nofollow" target="_blank">
{{ $comment->link }}
</a>
@include('tickets.partials.select-tutorial')
</p>
@endif
<p class="date-t">
Expand Down
7 changes: 7 additions & 0 deletions resources/views/tickets/partials/select-tutorial.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<form action="{{ route('tickets.details', $ticket->id) }}" method="POST" accept-charset="UTF-8">
{!! csrf_field() !!}
<input type="hide" name="comment_id" value="{{ $comment->id }}">
<input type="hide" name="link" value="{{ $comment->link }}">
<button type="submit" class="btn btn-primary">Seleccionar tutorial</button>
</form>

40 changes: 40 additions & 0 deletions tests/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}