mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
update api
This commit is contained in:
parent
e84f9418a5
commit
b03a073113
@ -1,5 +1,6 @@
|
||||
<?php namespace Visiosoft\AdvsModule\Adv;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Visiosoft\ConnectModule\Command\CheckRequiredParams;
|
||||
@ -23,14 +24,55 @@ class AdvApiCollection extends AdvRepository
|
||||
{
|
||||
$this->dispatch(new CheckRequiredParams(['ad_id'], $params));
|
||||
|
||||
if (!$ad = $this->newQuery()->find($params['ad_id'])) {
|
||||
throw new \Exception(trans('visiosoft.module.advs::message.ad_doesnt_exist'),404);
|
||||
}
|
||||
|
||||
if ($ad->created_by_id != Auth::id()) {
|
||||
throw new \Exception(trans('visiosoft.module.advs::message.permission_error'),403);
|
||||
}
|
||||
$ad = $this->checkAd($params['ad_id']);
|
||||
|
||||
$this->checkOwner($ad);
|
||||
|
||||
return $ad->delete();
|
||||
}
|
||||
|
||||
public function updateAd(array $params)
|
||||
{
|
||||
$this->dispatch(new CheckRequiredParams(['ad_id'], $params));
|
||||
|
||||
$ad = $this->checkAd($params['ad_id']);
|
||||
|
||||
$this->checkOwner($ad);
|
||||
|
||||
unset($params['ad_id'],$params['id'], $params['created_at'], $params['updated_at'],
|
||||
$params['deleted_at'], $params['created_by_id'], $params['updated_by_id']);
|
||||
|
||||
|
||||
$update_params = [
|
||||
'updated_by_id' => Auth::id(),
|
||||
'updated_at' => Carbon::now()
|
||||
];
|
||||
|
||||
$ad->update(array_merge($update_params,$params));
|
||||
|
||||
return $ad;
|
||||
}
|
||||
|
||||
public function getAds()
|
||||
{
|
||||
return $this->currentAds();
|
||||
}
|
||||
|
||||
public function checkAd($id)
|
||||
{
|
||||
if (!$ad = $this->newQuery()->find($id)) {
|
||||
throw new \Exception(trans('visiosoft.module.advs::message.ad_doesnt_exist'), 404);
|
||||
die;
|
||||
}
|
||||
return $ad;
|
||||
}
|
||||
|
||||
public function checkOwner($ad)
|
||||
{
|
||||
if ($ad->created_by_id != Auth::id()) {
|
||||
throw new \Exception(trans('visiosoft.module.advs::message.permission_error'), 403);
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user