1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Http/Controllers/ProjectApiController.php

224 lines
5.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use App\Http\Requests\CreateProjectRequest;
use App\Http\Requests\ProjectRequest;
use App\Http\Requests\UpdateProjectRequest;
use App\Models\Project;
use App\Ninja\Repositories\ProjectRepository;
use App\Services\ProjectService;
use Auth;
use Input;
use Session;
use View;
/**
* Class ProjectApiController
* @package App\Http\Controllers
*/
class ProjectApiController extends BaseAPIController
{
/**
* @var ProjectRepository
*/
protected $projectRepo;
/**
* @var ProjectService
*/
protected $projectService;
/**
* @var string
*/
protected $entityType = ENTITY_PROJECT;
/**
* ProjectApiController constructor.
* @param ProjectRepository $projectRepo
* @param ProjectService $projectService
*/
public function __construct(ProjectRepository $projectRepo, ProjectService $projectService)
{
2017-04-27 16:29:13 +02:00
parent::__construct();
$this->projectRepo = $projectRepo;
$this->projectService = $projectService;
}
/**
* @SWG\Get(
* path="/projects",
* summary="List projects",
* operationId="listProjects",
* tags={"project"},
* @SWG\Response(
* response=200,
* description="A list of projects",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Project"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2017-04-27 16:29:13 +02:00
public function index()
{
$projects = Project::scope()
->withTrashed()
->orderBy('created_at', 'desc');
return $this->listResponse($projects);
}
/**
* @SWG\Get(
* path="/projects/{project_id}",
* summary="Retrieve a project",
* operationId="getProject",
* tags={"project"},
* @SWG\Parameter(
* in="path",
* name="project_id",
* type="integer",
* required=true
* ),
* @SWG\Response(
* response=200,
* description="A single project",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Project"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2017-04-27 16:29:13 +02:00
public function show(ProjectRequest $request)
{
return $this->itemResponse($request->entity());
}
2017-04-27 16:29:13 +02:00
/**
* @SWG\Post(
* path="/projects",
* summary="Create a project",
* operationId="createProject",
* tags={"project"},
* @SWG\Parameter(
* in="body",
* name="body",
2017-11-06 15:36:36 +01:00
* @SWG\Schema(ref="#/definitions/Project")
* ),
* @SWG\Response(
* response=200,
* description="New project",
2017-11-06 15:36:36 +01:00
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Project"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2017-04-27 16:29:13 +02:00
public function store(CreateProjectRequest $request)
{
$project = $this->projectService->save($request->input());
return $this->itemResponse($project);
}
2017-04-27 16:29:13 +02:00
/**
* @SWG\Put(
* path="/projects/{project_id}",
* summary="Update a project",
* operationId="updateProject",
* tags={"project"},
* @SWG\Parameter(
* in="path",
* name="project_id",
* type="integer",
* required=true
* ),
* @SWG\Parameter(
* in="body",
* name="project",
2017-11-06 15:36:36 +01:00
* @SWG\Schema(ref="#/definitions/Project")
* ),
* @SWG\Response(
* response=200,
* description="Updated project",
2017-11-06 15:36:36 +01:00
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Project"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*
* @param mixed $publicId
*/
2017-04-27 16:29:13 +02:00
public function update(UpdateProjectRequest $request, $publicId)
{
if ($request->action) {
return $this->handleAction($request);
}
$data = $request->input();
$data['public_id'] = $publicId;
$project = $this->projectService->save($request->input(), $request->entity());
return $this->itemResponse($project);
}
/**
* @SWG\Delete(
* path="/projects/{project_id}",
* summary="Delete a project",
* operationId="deleteProject",
* tags={"project"},
* @SWG\Parameter(
* in="path",
* name="project_id",
* type="integer",
* required=true
* ),
* @SWG\Response(
* response=200,
* description="Deleted project",
2017-11-06 15:36:36 +01:00
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Project"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
2017-04-27 16:29:13 +02:00
*
*/
public function destroy(UpdateProjectRequest $request)
{
$project = $request->entity();
$this->projectRepo->delete($project);
return $this->itemResponse($project);
}
}