mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-13 10:42:16 +01:00
Add skip and meta to resource in time entry endpoint
This commit is contained in:
committed by
Gregor Vostrak
parent
3ee7839ca9
commit
a882ec6ca0
@@ -46,6 +46,8 @@ class TimeEntryController extends Controller
|
||||
* If you only need time entries for a specific user, you can filter by `user_id`.
|
||||
* Users with the permission `time-entries:view:own` can only use this endpoint with their own user ID in the user_id filter.
|
||||
*
|
||||
* @return TimeEntryCollection<TimeEntryResource>
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*
|
||||
* @operationId getTimeEntries
|
||||
@@ -76,11 +78,14 @@ class TimeEntryController extends Controller
|
||||
$filter->addClientIdsFilter($request->input('client_ids'));
|
||||
$filter->addBillableFilter($request->input('billable'));
|
||||
|
||||
$limit = $request->has('limit') ? (int) $request->input('limit', 100) : 100;
|
||||
$totalCount = $timeEntriesQuery->count();
|
||||
|
||||
$limit = $request->getLimit();
|
||||
if ($limit > 1000) {
|
||||
$limit = 1000;
|
||||
}
|
||||
$timeEntriesQuery->limit($limit);
|
||||
$timeEntriesQuery->skip($request->getSkip());
|
||||
|
||||
$timeEntries = $timeEntriesQuery->get();
|
||||
|
||||
@@ -114,7 +119,12 @@ class TimeEntryController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
return new TimeEntryCollection($timeEntries);
|
||||
return (new TimeEntryCollection($timeEntries))
|
||||
->additional([
|
||||
'meta' => [
|
||||
'total' => $totalCount,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,6 +131,11 @@ class TimeEntryIndexRequest extends FormRequest
|
||||
'min:1',
|
||||
'max:500',
|
||||
],
|
||||
// Skip the first n time entries (default: 0)
|
||||
'skip' => [
|
||||
'integer',
|
||||
'min:0',
|
||||
],
|
||||
// Filter makes sure that only time entries of a whole date are returned
|
||||
'only_full_dates' => [
|
||||
'string',
|
||||
@@ -143,4 +148,14 @@ class TimeEntryIndexRequest extends FormRequest
|
||||
{
|
||||
return $this->input('only_full_dates', 'false') === 'true';
|
||||
}
|
||||
|
||||
public function getLimit(): int
|
||||
{
|
||||
return $this->has('limit') ? (int) $this->validated('limit', 100) : 100;
|
||||
}
|
||||
|
||||
public function getSkip(): int
|
||||
{
|
||||
return $this->has('skip') ? (int) $this->validated('skip', 0) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\V1\TimeEntry;
|
||||
|
||||
use App\Http\Resources\PaginatedResourceCollection;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class TimeEntryCollection extends ResourceCollection
|
||||
class TimeEntryCollection extends ResourceCollection implements PaginatedResourceCollection
|
||||
{
|
||||
/**
|
||||
* The resource that this resource collects.
|
||||
|
||||
Reference in New Issue
Block a user