Skip to content

Commit

Permalink
Tip 4: Think of different states as different resources
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Aug 2, 2017
1 parent 0153567 commit b389a98
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
18 changes: 0 additions & 18 deletions app/Http/Controllers/PodcastsController.php
Expand Up @@ -88,22 +88,4 @@ public function destroy($id)

return redirect("/podcasts");
}

public function publish($id)
{
$podcast = Auth::user()->podcasts()->findOrFail($id);

$podcast->publish();

return response('', 204);
}

public function unpublish($id)
{
$podcast = Auth::user()->podcasts()->findOrFail($id);

$podcast->unpublish();

return response('', 204);
}
}
27 changes: 27 additions & 0 deletions app/Http/Controllers/PublishedPodcastsController.php
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class PublishedPodcastsController extends Controller
{
public function store()
{
$podcast = Auth::user()->podcasts()->findOrFail(request('podcast_id'));

$podcast->publish();

return $podcast;
}

public function destroy($id)
{
$podcast = Auth::user()->podcasts()->findOrFail($id);

$podcast->unpublish();

return $podcast;
}
}
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=709e8b72da6ddd2b44a3",
"/js/app.js": "/js/app.js?id=3360b40ad762590bebdd",
"/css/app.css": "/css/app.css?id=50995fffe414fda6556a"
}
8 changes: 4 additions & 4 deletions resources/assets/js/components/PublishButton.vue
Expand Up @@ -28,21 +28,21 @@ export default {
publish() {
this.working = true
axios.post(this.podcast.links.publish)
axios.post('/published-podcasts', { podcast_id: this.podcast.id })
.takeAtLeast(300)
.then(response => {
this.podcast.published = true
this.podcast = response.data
this.working = false
this.hovering = false
})
},
unpublish() {
this.working = true
axios.post(this.podcast.links.unpublish)
axios.delete(`/published-podcasts/${this.podcast.id}`)
.takeAtLeast(300)
.then(response => {
this.podcast.published = false
this.podcast = response.data
this.working = false
this.hovering = false
})
Expand Down
5 changes: 3 additions & 2 deletions routes/web.php
Expand Up @@ -22,8 +22,6 @@
Route::get('/podcasts/{id}/edit', 'PodcastsController@edit');
Route::patch('/podcasts/{id}', 'PodcastsController@update');
Route::delete('/podcasts/{id}', 'PodcastsController@destroy');
Route::post('/podcasts/{id}/publish', 'PodcastsController@publish');
Route::post('/podcasts/{id}/unpublish', 'PodcastsController@unpublish');

Route::get('/episodes', 'EpisodesController@index');
Route::get('/episodes/{id}', 'EpisodesController@show');
Expand All @@ -38,3 +36,6 @@

Route::post('/subscriptions', 'SubscriptionsController@store');
Route::delete('/subscriptions/{id}', 'SubscriptionsController@destroy');

Route::post('/published-podcasts', 'PublishedPodcastsController@store');
Route::delete('/published-podcasts/{id}', 'PublishedPodcastsController@destroy');

0 comments on commit b389a98

Please sign in to comment.