More shop stuff (again!!!)
This commit is contained in:
parent
313ac4e108
commit
a4218d3302
|
|
@ -12,7 +12,7 @@ use Illuminate\Support\Facades\Auth;
|
|||
|
||||
class FeedController extends Controller
|
||||
{
|
||||
protected function listjson()
|
||||
protected function listJson()
|
||||
{
|
||||
// TODO: XlXi: Group shouts.
|
||||
$postsQuery = Shout::getPosts()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
|
|||
use App\Helpers\ValidationHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Shout;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
|
|
@ -25,9 +26,9 @@ class ShopController extends Controller
|
|||
return response(ValidationHelper::generateErrorJSON($validator), 400);
|
||||
}
|
||||
|
||||
protected function getAssets($assetTypeIds, $gearGenre=null)
|
||||
protected static function getAssets($assetTypeIds, $gearGenre=null)
|
||||
{
|
||||
// TODO: XlXi: IMPORTANT!! Do not return raw DB response, return only needed values.
|
||||
// TODO: XlXi: Group owned assets
|
||||
return Asset::where('approved', true)
|
||||
->where('moderated', false)
|
||||
->where('onSale', true)
|
||||
|
|
@ -36,11 +37,10 @@ class ShopController extends Controller
|
|||
|
||||
if ($gearGenre != null)
|
||||
$query->whereIn('assetAttributeId', explode(',', $gearGenre));
|
||||
})
|
||||
->get();
|
||||
});
|
||||
}
|
||||
|
||||
protected function listjson(Request $request)
|
||||
protected function listJson(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'assetTypeId' => ['required', 'regex:/^\\d(,?\\d)*$/i'],
|
||||
|
|
@ -65,13 +65,29 @@ class ShopController extends Controller
|
|||
return ShopController::generateValidatorError($validator);
|
||||
}
|
||||
|
||||
$assets = $this->getAssets($valid['assetTypeId'], (isset($valid['gearGenreId']) ? $valid['gearGenreId'] : null));
|
||||
/* */
|
||||
|
||||
$assets = self::getAssets($valid['assetTypeId'], (isset($valid['gearGenreId']) ? $valid['gearGenreId'] : null));
|
||||
$assets = $assets->orderByDesc('created_at')
|
||||
->paginate(30);
|
||||
|
||||
$data = [];
|
||||
foreach($assets as $asset) {
|
||||
$creator = $asset->user;
|
||||
|
||||
array_push($data, [
|
||||
'Name' => $asset->name,
|
||||
'Creator' => [
|
||||
'Name' => $creator->username,
|
||||
'Link' => url('/user/' . strval($creator->username) . '/profile')
|
||||
],
|
||||
'Thumbnail' => $asset->getThumbnail()
|
||||
]);
|
||||
}
|
||||
|
||||
return response([
|
||||
'pages' => 123,
|
||||
'data' => $assets,
|
||||
'next_cursor' => null,
|
||||
'prev_cursor' => null
|
||||
'pages' => ($assets->hasPages() ? $assets->lastPage() : 1),
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,22 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\AssetVersion;
|
||||
use App\Models\User;
|
||||
|
||||
class Asset extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'creatorId');
|
||||
|
|
@ -20,6 +31,11 @@ class Asset extends Model
|
|||
return $this->belongsTo(AssetVersion::class, 'assetVersionId');
|
||||
}
|
||||
|
||||
public function getThumbnail()
|
||||
{
|
||||
return 'https://gtoria.local/images/testing/hat.png';
|
||||
}
|
||||
|
||||
// Version 0 is internally considered the latest.
|
||||
public function getContent($version = 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ class Shop extends Component {
|
|||
}
|
||||
|
||||
navigateCategory(categoryId, data) {
|
||||
this.setState({selectedCategoryId: categoryId, pageLoaded: false, pageNumber: null, pageCount: null});
|
||||
this.setState({selectedCategoryId: categoryId, pageLoaded: false});
|
||||
|
||||
let url = buildGenericApiUrl('api', 'catalog/v1/list-json');
|
||||
let paramIterator = 0;
|
||||
|
|
@ -253,9 +253,6 @@ class Shop extends Component {
|
|||
.then(res => {
|
||||
const items = res.data;
|
||||
|
||||
this.nextCursor = items.next_cursor;
|
||||
this.prevCursor = items.prev_cursor;
|
||||
|
||||
this.setState({ pageItems: items.data, pageCount: items.pages, pageNumber: 1, pageLoaded: true, error: false });
|
||||
}).catch(err => {
|
||||
const data = err.response.data;
|
||||
|
|
@ -264,7 +261,7 @@ class Shop extends Component {
|
|||
if(data.errors)
|
||||
errorMessage = data.errors[0].message;
|
||||
|
||||
this.setState({ pageItems: [], pageCount: null, pageNumber: null, pageLoaded: true, error: errorMessage });
|
||||
this.setState({ pageItems: [], pageCount: 1, pageNumber: 1, pageLoaded: true, error: errorMessage });
|
||||
this.inputBox.current.focus();
|
||||
});
|
||||
}
|
||||
|
|
@ -310,34 +307,39 @@ class Shop extends Component {
|
|||
:
|
||||
<div>
|
||||
{
|
||||
this.state.pageItems.map(({}, index) => {
|
||||
<a className="graphictoria-item-card" href="#" key={index}>
|
||||
this.state.pageItems.map(({Name, Creator, Thumbnail}, index) =>
|
||||
<a className="graphictoria-item-card" href="#" key={ index }>
|
||||
<span className="card m-2">
|
||||
<img className="img-fluid" src="https://gtoria.local/images/testing/hat.png" />
|
||||
<img className="img-fluid" src={ Thumbnail } />
|
||||
<div className="p-2">
|
||||
<p>Test hat</p>
|
||||
<p>{ Name }</p>
|
||||
<p className="text-muted">Free</p>
|
||||
</div>
|
||||
</span>
|
||||
</a>
|
||||
})
|
||||
)
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<ul className="list-inline mx-auto mt-3">
|
||||
<li className="list-inline-item">
|
||||
<button className="btn btn-secondary" disabled={(this.state.pageLoaded && this.prevCursor != null) ? null : true}><i className="fa-solid fa-angle-left"></i></button>
|
||||
</li>
|
||||
<li className="list-inline-item graphictoria-paginator">
|
||||
<span>Page </span>
|
||||
<input type="text" value={ this.state.pageNumber || '' } className="form-control" disabled={this.state.pageLoaded ? null : true} />
|
||||
<span> of { this.state.pageCount || '???' }</span>
|
||||
</li>
|
||||
<li className="list-inline-item">
|
||||
<button className="btn btn-secondary" disabled={(this.state.pageLoaded && this.nextCursor != null) ? null : true}><i className="fa-solid fa-angle-right"></i></button>
|
||||
</li>
|
||||
</ul>
|
||||
{
|
||||
this.state.pageCount > 1 ?
|
||||
<ul className="list-inline mx-auto mt-3">
|
||||
<li className="list-inline-item">
|
||||
<button className="btn btn-secondary" disabled={(this.state.pageNumber <= 1) ? true : null}><i className="fa-solid fa-angle-left"></i></button>
|
||||
</li>
|
||||
<li className="list-inline-item graphictoria-paginator">
|
||||
<span>Page </span>
|
||||
<input type="text" value={ this.state.pageNumber || '' } className="form-control" disabled={this.state.pageLoaded ? null : true} />
|
||||
<span> of { this.state.pageCount || '???' }</span>
|
||||
</li>
|
||||
<li className="list-inline-item">
|
||||
<button className="btn btn-secondary" disabled={(this.state.pageNumber >= this.state.pageCount) ? true : null}><i className="fa-solid fa-angle-right"></i></button>
|
||||
</li>
|
||||
</ul>
|
||||
:
|
||||
null
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ Route::get('/', 'ApiController@index')->name('index');
|
|||
Route::middleware('auth')->group(function () {
|
||||
Route::group(['as' => 'feed.', 'prefix' => 'feed'], function() {
|
||||
Route::group(['as' => 'v1.', 'prefix' => 'v1'], function() {
|
||||
Route::get('/list-json', 'FeedController@listjson')->name('list');
|
||||
Route::get('/list-json', 'FeedController@listJson')->name('list');
|
||||
Route::post('/share', 'FeedController@share')->name('share')->middleware('throttle:3,2');
|
||||
});
|
||||
});
|
||||
|
|
@ -13,7 +13,7 @@ Route::middleware('auth')->group(function () {
|
|||
|
||||
Route::group(['as' => 'catalog.', 'prefix' => 'catalog'], function() {
|
||||
Route::group(['as' => 'v1.', 'prefix' => 'v1'], function() {
|
||||
Route::get('/list-json', 'ShopController@listjson')->name('list');
|
||||
Route::get('/list-json', 'ShopController@listJson')->name('list');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue