v2 first commit
This commit is contained in:
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Setting\Category as Request;
|
||||
use App\Jobs\Setting\CreateCategory;
|
||||
use App\Jobs\Setting\DeleteCategory;
|
||||
use App\Jobs\Setting\UpdateCategory;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Transformers\Setting\Category as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Categories extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -43,9 +43,9 @@ class Categories extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$category = Category::create($request->all());
|
||||
$category = $this->dispatch(new CreateCategory($request));
|
||||
|
||||
return $this->response->created(url('api/categories/'.$category->id));
|
||||
return $this->response->created(url('api/categories/' . $category->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +57,43 @@ class Categories extends ApiController
|
||||
*/
|
||||
public function update(Category $category, Request $request)
|
||||
{
|
||||
$category->update($request->all());
|
||||
try {
|
||||
$category = $this->dispatch(new UpdateCategory($category, $request));
|
||||
|
||||
return $this->response->item($category->fresh(), new Transformer());
|
||||
return $this->item($category->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Category $category
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Category $category)
|
||||
{
|
||||
$category = $this->dispatch(new UpdateCategory($category, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($category->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Category $category
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Category $category)
|
||||
{
|
||||
try {
|
||||
$category = $this->dispatch(new UpdateCategory($category, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($category->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +104,12 @@ class Categories extends ApiController
|
||||
*/
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
$category->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteCategory($category));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Setting\Currency as Request;
|
||||
use App\Jobs\Setting\CreateCurrency;
|
||||
use App\Jobs\Setting\DeleteCurrency;
|
||||
use App\Jobs\Setting\UpdateCurrency;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Transformers\Setting\Currency as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Currencies extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -27,11 +27,18 @@ class Currencies extends ApiController
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Currency $currency
|
||||
* @param int|string $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Currency $currency)
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or code
|
||||
if (is_numeric($id)) {
|
||||
$currency = Currency::find($id);
|
||||
} else {
|
||||
$currency = Currency::where('code', $id)->first();
|
||||
}
|
||||
|
||||
return $this->response->item($currency, new Transformer());
|
||||
}
|
||||
|
||||
@ -43,9 +50,9 @@ class Currencies extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$currency = Currency::create($request->all());
|
||||
$currency = $this->dispatch(new CreateCurrency($request));
|
||||
|
||||
return $this->response->created(url('api/currencies/'.$currency->id));
|
||||
return $this->response->created(url('api/currencies/' . $currency->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +64,43 @@ class Currencies extends ApiController
|
||||
*/
|
||||
public function update(Currency $currency, Request $request)
|
||||
{
|
||||
$currency->update($request->all());
|
||||
try {
|
||||
$currency = $this->dispatch(new UpdateCurrency($currency, $request));
|
||||
|
||||
return $this->response->item($currency->fresh(), new Transformer());
|
||||
return $this->item($currency->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Currency $currency
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Currency $currency)
|
||||
{
|
||||
$currency = $this->dispatch(new UpdateCurrency($currency, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($currency->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Currency $currency
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Currency $currency)
|
||||
{
|
||||
try {
|
||||
$currency = $this->dispatch(new UpdateCurrency($currency, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($currency->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +111,12 @@ class Currencies extends ApiController
|
||||
*/
|
||||
public function destroy(Currency $currency)
|
||||
{
|
||||
$currency->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteCurrency($currency));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Setting\Setting as Request;
|
||||
use App\Models\Setting\Setting;
|
||||
use App\Transformers\Setting\Setting as Transformer;
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Setting\Tax as Request;
|
||||
use App\Jobs\Setting\CreateTax;
|
||||
use App\Jobs\Setting\DeleteTax;
|
||||
use App\Jobs\Setting\UpdateTax;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Transformers\Setting\Tax as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Taxes extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -43,9 +43,9 @@ class Taxes extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$tax = Tax::create($request->all());
|
||||
$tax = $this->dispatch(new CreateTax($request));
|
||||
|
||||
return $this->response->created(url('api/taxes/'.$tax->id));
|
||||
return $this->response->created(url('api/taxes/' . $tax->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +57,43 @@ class Taxes extends ApiController
|
||||
*/
|
||||
public function update(Tax $tax, Request $request)
|
||||
{
|
||||
$tax->update($request->all());
|
||||
try {
|
||||
$tax = $this->dispatch(new UpdateTax($tax, $request));
|
||||
|
||||
return $this->response->item($tax->fresh(), new Transformer());
|
||||
return $this->item($tax->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Tax $tax
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Tax $tax)
|
||||
{
|
||||
$tax = $this->dispatch(new UpdateTax($tax, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($tax->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Tax $tax
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Tax $tax)
|
||||
{
|
||||
try {
|
||||
$tax = $this->dispatch(new UpdateTax($tax, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($tax->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +104,12 @@ class Taxes extends ApiController
|
||||
*/
|
||||
public function destroy(Tax $tax)
|
||||
{
|
||||
$tax->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteTax($tax));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user