Implement Endpoint to return user notification count.
This commit is contained in:
parent
5039c5ccd9
commit
a00c170039
@ -12,6 +12,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
|
||||
class NotificationController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
@ -79,4 +80,14 @@ class NotificationController extends Controller
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public function notify()
|
||||
{
|
||||
try {
|
||||
$response = $this->notification->getNotify();
|
||||
return response()->json($response, Response::HTTP_OK);
|
||||
}catch (\Exception $ex){
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,10 +6,12 @@ use DateTimeInterface;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use OwenIt\Auditing\Auditable;
|
||||
|
||||
class Notifications extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $table = 'notificacoes';
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@ use App\Repositories\Economy\EconomyContractInterface;
|
||||
use App\Repositories\Economy\EconomyRepository;
|
||||
use App\Repositories\Faqs\FaqContractInterface;
|
||||
use App\Repositories\Faqs\FaqRepository;
|
||||
use App\Repositories\Med5min\Med5minContractInterface;
|
||||
use App\Repositories\Med5min\Med5minRepository;
|
||||
use App\Repositories\Notifications\NotificationContractInterface;
|
||||
use App\Repositories\Notifications\NotificationRepository;
|
||||
use App\Repositories\Pld\PldContractInterface;
|
||||
@ -55,6 +57,10 @@ class AppServiceProvider extends ServiceProvider
|
||||
DadosCadastraisContractInterface::class,
|
||||
DadosCadastraisRepository::class
|
||||
);
|
||||
$this->app->bind(
|
||||
Med5minContractInterface::class,
|
||||
Med5minRepository::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
10
app/Repositories/Med5min/Med5minContractInterface.php
Normal file
10
app/Repositories/Med5min/Med5minContractInterface.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Med5min;
|
||||
|
||||
use App\Repositories\ContractInterface;
|
||||
|
||||
interface Med5minContractInterface extends ContractInterface
|
||||
{
|
||||
|
||||
}
|
||||
31
app/Repositories/Med5min/Med5minRepository.php
Normal file
31
app/Repositories/Med5min/Med5minRepository.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repositories\Med5min;
|
||||
|
||||
use App\Models\Med5min;
|
||||
use App\Repositories\AbstractRepository;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
|
||||
class Med5minRepository extends AbstractRepository implements Med5minContractInterface
|
||||
{
|
||||
|
||||
public function __construct(Med5min $med5min)
|
||||
{
|
||||
parent::__construct($med5min);
|
||||
}
|
||||
|
||||
private function execute($fields, $params): Builder
|
||||
{
|
||||
$query = $this->model->select($fields);
|
||||
|
||||
if (!empty($params)) {
|
||||
$query = static::getFilterBuilder($params)->applyFilter($query);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,7 +3,6 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
trait MethodsTrait
|
||||
{
|
||||
@ -38,6 +37,7 @@ trait MethodsTrait
|
||||
return $this->model->with($relations)->get();
|
||||
}
|
||||
|
||||
|
||||
public function search($params)
|
||||
{
|
||||
$filter = static::getFilterBuilder($params);
|
||||
|
||||
@ -6,5 +6,6 @@ use App\Repositories\ContractInterface;
|
||||
|
||||
interface NotificationContractInterface extends ContractInterface
|
||||
{
|
||||
public function getNotify();
|
||||
|
||||
}
|
||||
@ -13,4 +13,9 @@ class NotificationRepository extends AbstractRepository implements NotificationC
|
||||
parent::__construct($notification);
|
||||
}
|
||||
|
||||
public function getNotify(): int
|
||||
{
|
||||
return Notifications::query()->with('users')
|
||||
->whereRelation('users', 'id', '=', auth()->id())->count();
|
||||
}
|
||||
}
|
||||
@ -62,6 +62,8 @@ Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
||||
Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'index']);
|
||||
|
||||
Route::get('download', [\App\Http\Controllers\InfoSectorialController::class, 'download']);
|
||||
|
||||
Route::post('notify', [\App\Http\Controllers\NotificationController::class, 'notify']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user