Skip to content

Commit

Permalink
Merge pull request #42 from tomatophp/develop
Browse files Browse the repository at this point in the history
add app store
  • Loading branch information
3x1io authored Mar 28, 2024
2 parents 92e1f22 + 029f85d commit ce36d77
Show file tree
Hide file tree
Showing 43 changed files with 1,342 additions and 83 deletions.
13 changes: 13 additions & 0 deletions Modules/CircleApps/App/Facades/CircleApps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Modules\CircleApps\App\Facades;

use Illuminate\Support\Facades\Facade;

class CircleApps extends Facade
{
protected static function getFacadeAccessor()
{
return 'circle-apps';
}
}
17 changes: 17 additions & 0 deletions Modules/CircleApps/App/Facades/CircleAppsMenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Modules\CircleApps\App\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static array get()
* @method static void register(string|array $menus)
*/
class CircleAppsMenu extends Facade
{
protected static function getFacadeAccessor()
{
return 'circle-apps-menu';
}
}
Empty file.
170 changes: 170 additions & 0 deletions Modules/CircleApps/App/Http/Controllers/AppController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php

namespace Modules\CircleApps\App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use TomatoPHP\TomatoAdmin\Facade\Tomato;

class AppController extends Controller
{
public string $model;

public function __construct()
{
$this->model = \Modules\CircleApps\App\Models\App::class;
}

/**
* @param Request $request
* @return View|JsonResponse
*/
public function index(Request $request): View|JsonResponse
{
return Tomato::index(
request: $request,
model: $this->model,
view: 'circle-apps::apps.index',
table: \Modules\CircleApps\App\Tables\AppTable::class
);
}

/**
* @param Request $request
* @return JsonResponse
*/
public function api(Request $request): JsonResponse
{
return Tomato::json(
request: $request,
model: \Modules\CircleApps\App\Models\App::class,
);
}

/**
* @return View
*/
public function create(): View
{
return Tomato::create(
view: 'circle-apps::apps.create',
);
}

/**
* @param \Modules\CircleApps\App\Http\Requests\App\AppStoreRequest $request
* @return RedirectResponse|JsonResponse
*/
public function store(\Modules\CircleApps\App\Http\Requests\App\AppStoreRequest $request): RedirectResponse|JsonResponse
{
$response = Tomato::store(
request: $request,
model: \Modules\CircleApps\App\Models\App::class,
message: __('App updated successfully'),
redirect: 'admin.apps.index',
hasMedia: true,
collection: [
'logo' => false,
'cover' => false,
]
);

$response->record->categories()->sync($request->categories);

if($response instanceof JsonResponse){
return $response;
}

return $response->redirect;
}

/**
* @param \Modules\CircleApps\App\Models\App $model
* @return View|JsonResponse
*/
public function show(\Modules\CircleApps\App\Models\App $model): View|JsonResponse
{
return Tomato::get(
model: $model,
view: 'circle-apps::apps.show',
hasMedia: true,
collection: [
'logo' => false,
'cover' => false,
]
);
}

/**
* @param \Modules\CircleApps\App\Models\App $model
* @return View
*/
public function edit(\Modules\CircleApps\App\Models\App $model): View
{
$model->categories = $model->categories->pluck('id')->toArray();
return Tomato::get(
model: $model,
view: 'circle-apps::apps.edit',
hasMedia: true,
collection: [
'logo' => false,
'cover' => false,
]
);
}

/**
* @param \Modules\CircleApps\App\Http\Requests\App\AppUpdateRequest $request
* @param \Modules\CircleApps\App\Models\App $model
* @return RedirectResponse|JsonResponse
*/
public function update(\Modules\CircleApps\App\Http\Requests\App\AppUpdateRequest $request, \Modules\CircleApps\App\Models\App $model): RedirectResponse|JsonResponse
{
$response = Tomato::update(
request: $request,
model: $model,
message: __('App updated successfully'),
redirect: 'admin.apps.index',
hasMedia: true,
collection: [
'logo' => false,
'cover' => false,
]
);

$response->record->categories()->sync($request->categories);

if($response instanceof JsonResponse){
return $response;
}

return $response->redirect;
}

/**
* @param \Modules\CircleApps\App\Models\App $model
* @return RedirectResponse|JsonResponse
*/
public function destroy(\Modules\CircleApps\App\Models\App $model): RedirectResponse|JsonResponse
{
$response = Tomato::destroy(
model: $model,
message: __('App deleted successfully'),
redirect: 'admin.apps.index',
hasMedia: true,
collection: [
'logo' => false,
'cover' => false,
]
);

if($response instanceof JsonResponse){
return $response;
}

return $response->redirect;
}
}
65 changes: 28 additions & 37 deletions Modules/CircleApps/App/Http/Controllers/CircleAppsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,53 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\CircleApps\App\Models\App;
use ProtoneMedia\Splade\Facades\Toast;

class CircleAppsController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
public function index(Request $request)
{
return view('circleapps::index');
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('circleapps::create');
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
//
$apps= App::query();
if($request->has('search')) {
$apps->where('name', 'like', '%'.$request->search.'%');
}
if($request->has('category')) {
$apps->whereHas('categories', function ($query) use ($request) {
$query->where('id', $request->category);
});
}
$apps->where('is_active', true);
$apps->orderBy('id', 'desc');
$apps = $apps->paginate(12);

return view('circle-apps::index', compact('apps'));
}

/**
* Show the specified resource.
*/
public function show($id)
public function show(App $app)
{
return view('circleapps::show');
return view('circle-apps::show', compact('app'));
}

/**
* Show the form for editing the specified resource.
*/
public function edit($id)
public function install(App $app)
{
return view('circleapps::edit');
}
auth('accounts')->user()->apps()->attach($app->id);

/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
//
Toast::success(__('App installed successfully!'))->autoDismiss(2);
return back();
}

/**
* Remove the specified resource from storage.
*/
public function destroy($id)
public function uninstall(App $app)
{
//
auth('accounts')->user()->apps()->detach($app->id);

Toast::success(__('App installed successfully!'))->autoDismiss(2);
return back();
}
}
Empty file.
Empty file.
47 changes: 47 additions & 0 deletions Modules/CircleApps/App/Http/Requests/App/AppStoreRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Modules\CircleApps\App\Http\Requests\App;

use Illuminate\Foundation\Http\FormRequest;

class AppStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'account_id' => 'nullable|exists:accounts,id',
'name' => 'required|max:255|string',
'description' => 'nullable|max:255|string',
'key' => 'required|string',
'readme' => 'nullable',
'homepage' => 'nullable|max:255|string',
'email' => 'nullable|max:255|string|email',
'docs' => 'nullable|max:255|string',
'github' => 'nullable|max:255|string',
'privacy' => 'nullable|max:255|string',
'faq' => 'nullable|max:255|string',
'status' => 'nullable|max:255|string',
'is_active' => 'nullable',
'price' => 'nullable',
'price_per' => 'nullable|max:255|string',
'discount' => 'nullable',
'discount_to' => 'nullable',
'is_free' => 'nullable'
];
}
}
47 changes: 47 additions & 0 deletions Modules/CircleApps/App/Http/Requests/App/AppUpdateRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Modules\CircleApps\App\Http\Requests\App;

use Illuminate\Foundation\Http\FormRequest;

class AppUpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'account_id' => 'nullable|exists:accounts,id',
'name' => 'sometimes|max:255|string',
'description' => 'nullable|max:255|string',
'key' => 'sometimes|string',
'readme' => 'nullable',
'homepage' => 'nullable|max:255|string',
'email' => 'nullable|max:255|string|email',
'docs' => 'nullable|max:255|string',
'github' => 'nullable|max:255|string',
'privacy' => 'nullable|max:255|string',
'faq' => 'nullable|max:255|string',
'status' => 'nullable|max:255|string',
'is_active' => 'nullable',
'price' => 'nullable',
'price_per' => 'nullable|max:255|string',
'discount' => 'nullable',
'discount_to' => 'nullable',
'is_free' => 'nullable'
];
}
}
Empty file.
Loading

0 comments on commit ce36d77

Please sign in to comment.