Added billable and project_id to time entry endpoints; Enhanced api docs; Added pagination

This commit is contained in:
Constantin Graf
2024-03-19 17:19:12 +01:00
parent 7cc686f230
commit 2133eb0c16
22 changed files with 616 additions and 309 deletions

View File

@@ -26,6 +26,8 @@ class ClientController extends Controller
/**
* Get clients
*
* @return ClientCollection<ClientResource>
*
* @throws AuthorizationException
*/
public function index(Organization $organization): ClientCollection
@@ -35,7 +37,7 @@ class ClientController extends Controller
$clients = Client::query()
->whereBelongsTo($organization, 'organization')
->orderBy('created_at', 'desc')
->get();
->paginate();
return new ClientCollection($clients);
}

View File

@@ -6,7 +6,8 @@ namespace App\Http\Controllers\Api\V1;
use App\Exceptions\Api\UserNotPlaceholderApiException;
use App\Http\Requests\V1\User\UserIndexRequest;
use App\Http\Resources\V1\User\UserCollection;
use App\Http\Resources\V1\User\MemberCollection;
use App\Http\Resources\V1\User\MemberResource;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Auth\Access\AuthorizationException;
@@ -14,25 +15,27 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Laravel\Jetstream\Contracts\InvitesTeamMembers;
class UserController extends Controller
class MemberController extends Controller
{
/**
* List all users in an organization
* List all members of an organization
*
* @return MemberCollection<MemberResource>>
*
* @throws AuthorizationException
*/
public function index(Organization $organization, UserIndexRequest $request): UserCollection
public function index(Organization $organization, UserIndexRequest $request): MemberCollection
{
$this->checkPermission($organization, 'users:view');
$users = $organization->users()
->paginate();
return UserCollection::make($users);
return MemberCollection::make($users);
}
/**
* Invite a placeholder user to become a real user in the organization
* Invite a placeholder user to become a member of the organization
*
* @throws AuthorizationException|UserNotPlaceholderApiException
*/
@@ -51,6 +54,6 @@ class UserController extends Controller
'employee'
);
return response()->json($user);
return response()->json(null, 204);
}
}

View File

@@ -27,16 +27,18 @@ class ProjectController extends Controller
/**
* Get projects
*
* @return ProjectCollection<ProjectResource>
*
* @throws AuthorizationException
*
* @operationId getProjects
*/
public function index(Organization $organization): JsonResource
public function index(Organization $organization): ProjectCollection
{
$this->checkPermission($organization, 'projects:view');
$projects = Project::query()
->whereBelongsTo($organization, 'organization')
->get();
->paginate();
return new ProjectCollection($projects);
}

View File

@@ -26,9 +26,11 @@ class TagController extends Controller
/**
* Get tags
*
* @throws AuthorizationException
* @return TagCollection<TagResource>
*
* @operationId getTags
*
* @throws AuthorizationException
*/
public function index(Organization $organization): TagCollection
{
@@ -37,7 +39,7 @@ class TagController extends Controller
$tags = Tag::query()
->whereBelongsTo($organization, 'organization')
->orderBy('created_at', 'desc')
->get();
->paginate();
return new TagCollection($tags);
}

View File

@@ -104,7 +104,8 @@ class TimeEntryController extends Controller
/**
* Create time entry
*
* @throws AuthorizationException|TimeEntryStillRunningApiException
* @throws AuthorizationException
* @throws TimeEntryStillRunningApiException
*
* @operationId createTimeEntry
*/
@@ -117,7 +118,6 @@ class TimeEntryController extends Controller
}
if ($request->get('end') === null && TimeEntry::query()->where('user_id', $request->get('user_id'))->where('end', null)->exists()) {
// TODO: API documentation
throw new TimeEntryStillRunningApiException();
}
@@ -145,6 +145,8 @@ class TimeEntryController extends Controller
$this->checkPermission($organization, 'time-entries:update:all', $timeEntry);
}
// TODO: TimeEntryStillRunningApiException
$timeEntry->fill($request->validated());
$timeEntry->description = $request->get('description', $timeEntry->description) ?? '';
$timeEntry->save();