Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Commit

Permalink
fixed new lists being created & routing
Browse files Browse the repository at this point in the history
  • Loading branch information
jung35 committed Mar 21, 2015
1 parent 629a9fe commit 955741d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 73 deletions.
48 changes: 30 additions & 18 deletions app/Http/Controllers/APIv1/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class ListController extends Controller
{
public function mySimpleList()
{
$this->middleware('auth');

$myList = UserList::where('user_id', Auth::user()->id)
->orderBy('id', 'desc')
->get([
Expand All @@ -37,8 +35,6 @@ public function mySimpleList()
}
public function listList()
{
$this->middleware('auth');

$return = [
'my_list' => [],
'friends_list' => []
Expand Down Expand Up @@ -181,9 +177,6 @@ public function customList(UserList $userList)

public function modifyCustomList($listId = null)
{
$this->middleware('csrf');
$this->middleware('auth');

$messages = [
'required' => 'The :attribute field is required.',
'numeric' => 'The :attribute field is required.',
Expand Down Expand Up @@ -227,20 +220,45 @@ public function modifyCustomList($listId = null)
return ['error' => 'There was an error while trying to save the list.'];
}

return $user->UserList()
->orderBy('id', 'desc')
$myLists = UserList::where('user_list.user_id', $user->id)
->leftjoin('user_list_profile as ulp_1', 'ulp_1.user_list_id', '=', 'user_list.id')
->groupBy('user_list.id')
->orderBy('user_list.id', 'desc')
->leftJoin('subscription', function($join)
{
$join->on('subscription.user_list_id', '=', 'user_list.id')
->whereNull('subscription.deleted_at');
})->whereNull('ulp_1.deleted_at')
->get([
'user_list.id',
'user_list.title',
'user_list.privacy',
'user_list.created_at',

\DB::raw('count(ulp_1.id) as users_in_list'),
\DB::raw('count(distinct subscription.id) as sub_count'),
]);

$return = [];

foreach($myLists as $myList)
{
$return[] = [
'id' => $myList->id,
'title' => $myList->title,
'privacy' => $myList->privacy,
'created_at' => $myList->created_at->format("M j Y"),

'users_in_list' => $myList->users_in_list,
'sub_count' => $myList->sub_count,
];
}

return $return;
}

public function deleteCustomList(UserList $userList)
{
$this->middleware('csrf');
$this->middleware('auth');

$userList->UserListProfile()->delete();

if(!$userList->delete()) {
Expand All @@ -252,9 +270,6 @@ public function deleteCustomList(UserList $userList)

public function listSubscribe(UserList $userList)
{
$this->middleware('csrf');
$this->middleware('auth');

if(!isset($userList->id)) {
return ['error' => '404'];
}
Expand All @@ -279,9 +294,6 @@ public function listSubscribe(UserList $userList)

public function listUnsubscribe(UserList $userList)
{
$this->middleware('csrf');
$this->middleware('auth');

if(!isset($userList->id)) {
return ['error' => '404'];
}
Expand Down
6 changes: 0 additions & 6 deletions app/Http/Controllers/APIv1/ListUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class ListUserController extends Controller
{
public function addToList()
{
$this->middleware('csrf');
$this->middleware('auth');

$messages = [
'required' => 'The :attribute field is required.',
'numeric' => 'The :attribute field is required.',
Expand Down Expand Up @@ -72,9 +69,6 @@ public function addToList()

public function deleteFromList()
{
$this->middleware('csrf');
$this->middleware('auth');

$input = Input::all();

$userListProfile = UserListProfile::where('user_list_id', $input['list_id'])
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function login()
$steam64BitId = str_replace("http://steamcommunity.com/openid/id/", "", $steamuser['steamid'] );

// Try to grab user if it exists
$user = User::whereSmallId(Steam::toSmallId($steam64BitId))->first();
$user = User::whereSmallId((int) Steam::toSmallId($steam64BitId))->first();

$steamAPI = new SteamAPI('info');
$steamAPI->setSteamId($steam64BitId);
Expand All @@ -50,7 +50,7 @@ public function login()
if(!isset($user->id))
{
$user = new User;
$user->small_id = (string) Steam::toSmallId($userSteamInfo->steamid);
$user->small_id = (int) Steam::toSmallId($userSteamInfo->steamid);
}

$user->display_name = (string) $userSteamInfo->personaname;
Expand Down
4 changes: 0 additions & 4 deletions app/Http/Controllers/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public function profilePage($steam64BitId)

public function listListPage()
{
$this->middleware('auth');

return view('pages/listPortal');
}

Expand Down Expand Up @@ -86,8 +84,6 @@ public function donatePage()

public function searchPage()
{
$this->middleware('csrf');

$searchQuery = Input::get('search');

if(!$searchQuery) return redirect()->route('home');
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class SettingsController extends Controller
{
public function subscriptionPage()
{
$this->middleware('auth');
return view('settings/subscription');
}

Expand Down
89 changes: 48 additions & 41 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
]);

get('/logout', [
'middleware' => 'auth',
'as' => 'auth.logout',
'uses' => 'LoginController@logout'
]);
});

get('/list', [
'as' => 'list.list',
'middleware' => 'auth',
'uses' => 'PagesController@listListPage'
]);

Expand Down Expand Up @@ -84,6 +86,7 @@
Route::group(['prefix' => 'settings'], function()
{
get('/', [
'middleware' => 'auth',
'as' => 'settings',
'uses' => 'SettingsController@subscriptionPage'
]);
Expand Down Expand Up @@ -111,6 +114,7 @@
Route::group(['prefix' => 'list'], function()
{
get('/simple', [
'middleware' => 'auth',
'as' => 'api.v1.list.simple',
'uses' => 'ListController@mySimpleList'
]);
Expand All @@ -125,53 +129,56 @@
'uses' => 'ListController@latestTracked'
]);

get('/{userList}', [
'as' => 'api.v1.tracked.latest',
'uses' => 'ListController@customList'
]);

get('/', [
'middleware' => 'auth',
'as' => 'api.v1.list.list',
'uses' => 'ListController@listList'
]);

//
// ---------------------------------
//

post('/add', [
'as' => 'api.v1.list.user.add',
'uses' => 'ListUserController@addToList'
]);

post('/{listId?}', [
'as' => 'api.v1.list.create',
'uses' => 'ListController@modifyCustomList'
get('/{userList}', [
'as' => 'api.v1.tracked.latest',
'uses' => 'ListController@customList'
]);

post('/subscribe/{userList}', [
'as' => 'api.v1.list.subscribe',
'uses' => 'ListController@listSubscribe'
]);

//
// ---------------------------------
//

delete('/subscribe/{userList}', [
'as' => 'api.v1.list.unsubscribe',
'uses' => 'ListController@listUnsubscribe'
]);

delete('/delete', [
'as' => 'api.v1.list.user.delete',
'uses' => 'ListUserController@deleteFromList'
]);

delete('/{userList}', [
'as' => 'api.v1.tracked.latest',
'uses' => 'ListController@deleteCustomList'
]);
Route::group(['middleware' => 'auth'], function()
{
post('/add', [
'as' => 'api.v1.list.user.add',
'uses' => 'ListUserController@addToList'
]);

post('/{listId?}', [
'as' => 'api.v1.list.create',
'uses' => 'ListController@modifyCustomList'
]);

post('/subscribe/{userList}', [
'as' => 'api.v1.list.subscribe',
'uses' => 'ListController@listSubscribe'
]);

//
// ---------------------------------
//

delete('/subscribe/{userList}', [
'as' => 'api.v1.list.unsubscribe',
'uses' => 'ListController@listUnsubscribe'
]);

delete('/delete', [
'as' => 'api.v1.list.user.delete',
'uses' => 'ListUserController@deleteFromList'
]);

delete('/{userList}', [
'as' => 'api.v1.tracked.latest',
'uses' => 'ListController@deleteCustomList'
]);
});
});

Route::group(['prefix' => 'news'], function()
Expand Down Expand Up @@ -199,7 +206,7 @@
Route::any('/ipn', array('uses' => 'DonationController@IPN'));
});

Route::group(['prefix' => 'settings'], function()
Route::group(['prefix' => 'settings', 'middleware' => 'auth'], function()
{
get('/', [
'as' => 'api.v1.settings',
Expand Down Expand Up @@ -235,9 +242,9 @@
]);

post('/announcement', [
'as' => 'admin.announcement.save',
'uses' => 'MainController@announcementSave'
]);
'as' => 'admin.announcement.save',
'uses' => 'MainController@announcementSave'
]);

Route::group(['prefix' => 'db'], function()
{
Expand Down
1 change: 0 additions & 1 deletion resources/assets/jsx/listHandler.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var auth_check = $('meta[name=auth]').attr("content");
var ListHandler = React.createClass({
submitNewListToServer: function(data)
{
console.log(data);
$.ajax({
url: '/api/v1/list',
dataType: 'json',
Expand Down

0 comments on commit 955741d

Please sign in to comment.