INA-5 | Add docs for a task scheduler

This commit is contained in:
Nikola Cirkovic 2022-05-23 02:13:23 +02:00
parent e8a2476463
commit fd028102bd
3 changed files with 215 additions and 8 deletions

View File

@ -0,0 +1,51 @@
<?php
/**
* @OA\Schema(
* schema="TaskSchedulerSchema",
* type="object",
*
* * @OA\Property(property="paused",type="bool",example="false",description="The scheduler paused state"),
* @OA\Property(property="repeat_every",type="string",example="DAY",description="Accepted values (DAY,WEEK,MONTH,3MONTHS,YEAR)"),
* @OA\Property(property="start_from",type="integer",example="1652898504",description="Timestamp when we should start the scheduler, default is today"),
* @OA\Property(property="date_range", type="string", example="last7", description="The string representation of the date range of data to be returned"),
* @OA\Property(property="date_key", type="string", example="created_at", description="The date column to search between."),
* @OA\Property(property="start_date", type="string", example="2000-10-31", description="The start date to search between"),
* @OA\Property(property="end_date", type="string", example="2", description="The end date to search between"),
* @OA\Property(
* property="report_keys",
* type="array",
* @OA\Items(
* type="string",
* description="Array of Keys to export",
* example="['name','date']",
* ),
* ),
*
* )
*/
/**
* @OA\Schema(
* schema="UpdateTaskSchedulerSchema",
* type="object",
*
* @OA\Property(property="paused",type="bool",example="false",description="The scheduler paused state"),
* @OA\Property(property="archived",type="bool",example="false",description="The scheduler archived state"),
* * @OA\Property(property="repeat_every",type="string",example="DAY",description="Accepted values (DAY,WEEK,MONTH,3MONTHS,YEAR)"),
* @OA\Property(property="start_from",type="integer",example="1652898504",description="Timestamp when we should start the scheduler, default is today"),
*
* )
*/
/**
* @OA\Schema(
* schema="UpdateJobForASchedulerSchema",
* type="object",
* @OA\Property(property="action_name",type="string",example="create_client_report",description="Set action name, action names can be found in ScheduledJob Model"),
*
* )
*/

View File

@ -15,44 +15,201 @@ use Symfony\Component\HttpFoundation\Request;
class TaskSchedulerController extends BaseController
{
/**
* @OA\GET(
* path="/api/v1/task_scheduler/",
* operationId="getTaskSchedulers",
* tags={"task_scheduler"},
* summary="Task Scheduler Index",
* description="Get all schedulers with associated jobs",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Response(
* response=200,
* description="success",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function index()
{
return Scheduler::all();
}
/**
* @param \App\Http\Requests\TaskScheduler\CreateScheduledTaskRequest $request
* @OA\Post(
* path="/api/v1/task_scheduler/",
* operationId="createTaskScheduler",
* tags={"task_scheduler"},
* summary="Create task scheduler with job ",
* description="Create task scheduler with a job (action(job) request should be sent via request also. Example: We want client report to be job which will be run
* multiple times, we should send the same parameters in the request as we would send if we wanted to get report, see example",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(ref="#/components/schemas/TaskSchedulerSchema")
* ),
* @OA\Response(
* response=200,
* description="success",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function store(CreateScheduledTaskRequest $request)
{
$scheduler = new Scheduler();
return $scheduler->service()->store($scheduler, $request);
}
/**
* @OA\GET(
* path="/api/v1/task_scheduler/{scheduler}",
* operationId="showTaskScheduler",
* tags={"task_scheduler"},
* summary="Show given scheduler",
* description="Get scheduler with associated job",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Response(
* response=200,
* description="success",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function show(Scheduler $scheduler): Scheduler
{
return $scheduler;
}
/**
* @param \App\Models\Scheduler $scheduler
* @param \App\Http\Requests\TaskScheduler\UpdateScheduleRequest $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
* @OA\PUT(
* path="/api/v1/task_scheduler/{scheduler}",
* operationId="updateTaskScheduler",
* tags={"task_scheduler"},
* summary="Update task scheduler ",
* description="Update task scheduler",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(ref="#/components/schemas/UpdateTaskSchedulerSchema")
* ),
* @OA\Response(
* response=200,
* description="success",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function update(Scheduler $scheduler, UpdateScheduleRequest $request)
{
return $scheduler->service()->update($scheduler, $request);
}
/**
* @OA\PUT(
* path="/api/v1/task_scheduler/{scheduler}/update_job/",
* operationId="updateTaskSchedulerJob",
* tags={"task_scheduler"},
* summary="Update job for a task scheduler ",
* description="Update job for a task scheduler | if we are changing action for a job, we should send the request for a new job same as we are creating new scheduler",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(ref="#/components/schemas/UpdateJobForASchedulerSchema")
* ),
* @OA\Response(
* response=200,
* description="success",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function updateJob(Scheduler $scheduler, UpdateScheduledJobRequest $request)
{
return $scheduler->service()->updateJob($scheduler, $request);
}
/**
* @OA\DELETE(
* path="/api/v1/task_scheduler/{scheduler}",
* operationId="destroyTaskScheduler",
* tags={"task_scheduler"},
* summary="Destroy Task Scheduler",
* description="Destroy task scheduler and its associated job",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Response(
* response=200,
* description="success",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function destroy(Scheduler $scheduler)
{
return $scheduler->service()->destroy($scheduler);

View File

@ -35,7 +35,6 @@ class UpdateScheduleRequest extends Request
'archived' => 'sometimes|bool',
'repeat_every' => 'sometimes|string|in:DAY,WEEK,MONTH,3MONTHS,YEAR',
'start_from' => 'sometimes|string',
'job' => 'sometimes|string',
];
}
}