Update service Application FQDN by UUID.

This commit is contained in:
MD Mahbub Hasan 2024-10-15 23:04:02 +06:00
parent 5d62a46a16
commit a52b5af595
2 changed files with 115 additions and 1 deletions

View file

@ -1240,4 +1240,118 @@ class ServicesController extends Controller
);
}
#[OA\Patch(
summary: 'Update Service Application FQDN',
description: 'Update service Application FQDN by UUID.',
path: '/services/{uuid}/fqdn',
operationId: 'update-service-fqdn-by-uuid',
security: [
['bearerAuth' => []],
],
tags: ['Services'],
parameters: [
new OA\Parameter(
name: 'uuid',
in: 'path',
description: 'UUID of the service.',
required: true,
schema: new OA\Schema(
type: 'string',
format: 'uuid',
)
),
],
requestBody: new OA\RequestBody(
description: 'FQDN update and application UUID to exclude.',
required: true,
content: [
new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
properties: [
'fqdn' => ['type' => 'string', 'description' => 'Comma-separated FQDNs.'],
'applications_uuid' => ['type' => 'string', 'description' => 'UUID of the application to exclude.'],
],
required: ['fqdn', 'applications_uuid'],
),
),
],
),
responses: [
new OA\Response(
response: 200,
description: 'FQDN updated.',
content: [
new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
properties: [
'uuid' => ['type' => 'string'],
'fqdn' => ['type' => 'string'],
]
)
),
]),
new OA\Response(
response: 401,
ref: '#/components/responses/401',
),
new OA\Response(
response: 400,
ref: '#/components/responses/400',
),
new OA\Response(
response: 404,
ref: '#/components/responses/404',
),
]
)]
public function update_service_fqdn_by_uuid(Request $request, $uuid)
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
// Find the service with the specified UUID and teamId
$service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($uuid)->first();
// If service not found, return error response
if (!$service) {
return response()->json(['message' => 'Service not found.'], 404);
}
// Validate the request input
$validator = customApiValidator($request->all(), [
'fqdn' => 'required|string|max:255',
'applications_uuid' => 'required|string|max:255',
]);
// If validation fails, return error response
if ($validator->fails()) {
return response()->json([
'message' => 'Validation failed.',
'errors' => $validator->errors(),
], 422);
}
// Find the application with the specified applications_uuid
$application = $service->applications()->where('uuid',$request->applications_uuid)->first();
// If application not found, return error response
if (!$application) {
return response()->json(['message' => 'Application not found.'], 404);
}
// Update the FQDN for the found application
$application->fqdn = $request->fqdn;
$application->save(); // Save the updated application
// Return the updated application with 200 response
return response()->json($application, 200);
}
}

View file

@ -116,7 +116,7 @@ Route::group([
Route::get('/services/{uuid}', [ServicesController::class, 'service_by_uuid']);
// Route::patch('/services/{uuid}', [ServicesController::class, 'update_by_uuid'])->middleware([IgnoreReadOnlyApiToken::class]);
Route::delete('/services/{uuid}', [ServicesController::class, 'delete_by_uuid'])->middleware([IgnoreReadOnlyApiToken::class]);
Route::patch('/services/{uuid}/fqdn', [ServicesController::class, 'update_service_fqdn_by_uuid'])->middleware([IgnoreReadOnlyApiToken::class]);
Route::get('/services/{uuid}/envs', [ServicesController::class, 'envs']);
Route::post('/services/{uuid}/envs', [ServicesController::class, 'create_env'])->middleware([IgnoreReadOnlyApiToken::class]);
Route::patch('/services/{uuid}/envs/bulk', [ServicesController::class, 'create_bulk_envs'])->middleware([IgnoreReadOnlyApiToken::class]);