Merge pull request #4571 from SierraJC/fix/api--projects-apps-fixes

Fix: API - Projects & Applications endpoints issues
This commit is contained in:
Andras Bacsai 2024-12-18 11:06:22 +01:00 committed by GitHub
commit e41efab9bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 208 additions and 44 deletions

View file

@ -189,8 +189,17 @@ public function applications(Request $request)
),
responses: [
new OA\Response(
response: 200,
response: 201,
description: 'Application created successfully.',
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
properties: [
'uuid' => ['type' => 'string'],
]
)
)
),
new OA\Response(
response: 401,
@ -296,8 +305,17 @@ public function create_public_application(Request $request)
),
responses: [
new OA\Response(
response: 200,
response: 201,
description: 'Application created successfully.',
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
properties: [
'uuid' => ['type' => 'string'],
]
)
)
),
new OA\Response(
response: 401,
@ -403,8 +421,17 @@ public function create_private_gh_app_application(Request $request)
),
responses: [
new OA\Response(
response: 200,
response: 201,
description: 'Application created successfully.',
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
properties: [
'uuid' => ['type' => 'string'],
]
)
)
),
new OA\Response(
response: 401,
@ -494,8 +521,17 @@ public function create_private_deploy_key_application(Request $request)
),
responses: [
new OA\Response(
response: 200,
response: 201,
description: 'Application created successfully.',
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
properties: [
'uuid' => ['type' => 'string'],
]
)
)
),
new OA\Response(
response: 401,
@ -582,8 +618,17 @@ public function create_dockerfile_application(Request $request)
),
responses: [
new OA\Response(
response: 200,
response: 201,
description: 'Application created successfully.',
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
properties: [
'uuid' => ['type' => 'string'],
]
)
)
),
new OA\Response(
response: 401,
@ -636,8 +681,17 @@ public function create_dockerimage_application(Request $request)
),
responses: [
new OA\Response(
response: 200,
response: 201,
description: 'Application created successfully.',
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
properties: [
'uuid' => ['type' => 'string'],
]
)
)
),
new OA\Response(
response: 401,
@ -833,7 +887,7 @@ private function create_application(Request $request, $type)
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
]));
]))->setStatusCode(201);
} elseif ($type === 'private-gh-app') {
$validationRules = [
'git_repository' => 'string|required',
@ -904,12 +958,12 @@ private function create_application(Request $request, $type)
$application->environment_id = $environment->id;
$application->source_type = $githubApp->getMorphClass();
$application->source_id = $githubApp->id;
$application->save();
$application->refresh();
if (isset($useBuildServer)) {
$application->settings->is_build_server_enabled = $useBuildServer;
$application->settings->save();
}
$application->save();
$application->refresh();
if (! $application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
@ -934,7 +988,7 @@ private function create_application(Request $request, $type)
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
]));
]))->setStatusCode(201);
} elseif ($type === 'private-deploy-key') {
$validationRules = [
@ -1001,12 +1055,12 @@ private function create_application(Request $request, $type)
$application->destination_id = $destination->id;
$application->destination_type = $destination->getMorphClass();
$application->environment_id = $environment->id;
$application->save();
$application->refresh();
if (isset($useBuildServer)) {
$application->settings->is_build_server_enabled = $useBuildServer;
$application->settings->save();
}
$application->save();
$application->refresh();
if (! $application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
@ -1031,7 +1085,7 @@ private function create_application(Request $request, $type)
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
]));
]))->setStatusCode(201);
} elseif ($type === 'dockerfile') {
$validationRules = [
'dockerfile' => 'string|required',
@ -1087,15 +1141,16 @@ private function create_application(Request $request, $type)
$application->destination_id = $destination->id;
$application->destination_type = $destination->getMorphClass();
$application->environment_id = $environment->id;
if (isset($useBuildServer)) {
$application->settings->is_build_server_enabled = $useBuildServer;
$application->settings->save();
}
$application->git_repository = 'coollabsio/coolify';
$application->git_branch = 'main';
$application->save();
$application->refresh();
if (isset($useBuildServer)) {
$application->settings->is_build_server_enabled = $useBuildServer;
$application->settings->save();
}
if (! $application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
@ -1116,7 +1171,7 @@ private function create_application(Request $request, $type)
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
]));
]))->setStatusCode(201);
} elseif ($type === 'dockerimage') {
$validationRules = [
'docker_registry_image_name' => 'string|required',
@ -1151,15 +1206,15 @@ private function create_application(Request $request, $type)
$application->destination_id = $destination->id;
$application->destination_type = $destination->getMorphClass();
$application->environment_id = $environment->id;
if (isset($useBuildServer)) {
$application->settings->is_build_server_enabled = $useBuildServer;
$application->settings->save();
}
$application->git_repository = 'coollabsio/coolify';
$application->git_branch = 'main';
$application->save();
$application->refresh();
if (isset($useBuildServer)) {
$application->settings->is_build_server_enabled = $useBuildServer;
$application->settings->save();
}
if (! $application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
@ -1180,7 +1235,7 @@ private function create_application(Request $request, $type)
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
]));
]))->setStatusCode(201);
} elseif ($type === 'dockercompose') {
$allowedFields = ['project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'instant_deploy', 'docker_compose_raw'];
@ -1262,7 +1317,7 @@ private function create_application(Request $request, $type)
return response()->json(serializeApiResponse([
'uuid' => data_get($service, 'uuid'),
'domains' => data_get($service, 'domains'),
]));
]))->setStatusCode(201);
}
return response()->json(['message' => 'Invalid type.'], 400);

View file

@ -90,11 +90,12 @@ public function project_by_uuid(Request $request)
if (is_null($teamId)) {
return invalidTokenResponse();
}
$project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first()->load(['environments']);
$project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first();
if (! $project) {
return response()->json(['message' => 'Project not found.'], 404);
}
$project->load(['environments']);
return response()->json(
serializeApiResponse($project),
);

View file

@ -347,8 +347,20 @@
}
},
"responses": {
"200": {
"description": "Application created successfully."
"201": {
"description": "Application created successfully.",
"content": {
"application\/json": {
"schema": {
"properties": {
"uuid": {
"type": "string"
}
},
"type": "object"
}
}
}
},
"401": {
"$ref": "#\/components\/responses\/401"
@ -669,8 +681,20 @@
}
},
"responses": {
"200": {
"description": "Application created successfully."
"201": {
"description": "Application created successfully.",
"content": {
"application\/json": {
"schema": {
"properties": {
"uuid": {
"type": "string"
}
},
"type": "object"
}
}
}
},
"401": {
"$ref": "#\/components\/responses\/401"
@ -991,8 +1015,20 @@
}
},
"responses": {
"200": {
"description": "Application created successfully."
"201": {
"description": "Application created successfully.",
"content": {
"application\/json": {
"schema": {
"properties": {
"uuid": {
"type": "string"
}
},
"type": "object"
}
}
}
},
"401": {
"$ref": "#\/components\/responses\/401"
@ -1242,8 +1278,20 @@
}
},
"responses": {
"200": {
"description": "Application created successfully."
"201": {
"description": "Application created successfully.",
"content": {
"application\/json": {
"schema": {
"properties": {
"uuid": {
"type": "string"
}
},
"type": "object"
}
}
}
},
"401": {
"$ref": "#\/components\/responses\/401"
@ -1476,8 +1524,20 @@
}
},
"responses": {
"200": {
"description": "Application created successfully."
"201": {
"description": "Application created successfully.",
"content": {
"application\/json": {
"schema": {
"properties": {
"uuid": {
"type": "string"
}
},
"type": "object"
}
}
}
},
"401": {
"$ref": "#\/components\/responses\/401"
@ -1563,8 +1623,20 @@
}
},
"responses": {
"200": {
"description": "Application created successfully."
"201": {
"description": "Application created successfully.",
"content": {
"application\/json": {
"schema": {
"properties": {
"uuid": {
"type": "string"
}
},
"type": "object"
}
}
}
},
"401": {
"$ref": "#\/components\/responses\/401"

View file

@ -250,8 +250,14 @@ paths:
description: 'Use build server.'
type: object
responses:
'200':
'201':
description: 'Application created successfully.'
content:
application/json:
schema:
properties:
uuid: { type: string }
type: object
'401':
$ref: '#/components/responses/401'
'400':
@ -483,8 +489,14 @@ paths:
description: 'Use build server.'
type: object
responses:
'200':
'201':
description: 'Application created successfully.'
content:
application/json:
schema:
properties:
uuid: { type: string }
type: object
'401':
$ref: '#/components/responses/401'
'400':
@ -716,8 +728,14 @@ paths:
description: 'Use build server.'
type: object
responses:
'200':
'201':
description: 'Application created successfully.'
content:
application/json:
schema:
properties:
uuid: { type: string }
type: object
'401':
$ref: '#/components/responses/401'
'400':
@ -896,8 +914,14 @@ paths:
description: 'Use build server.'
type: object
responses:
'200':
'201':
description: 'Application created successfully.'
content:
application/json:
schema:
properties:
uuid: { type: string }
type: object
'401':
$ref: '#/components/responses/401'
'400':
@ -1067,8 +1091,14 @@ paths:
description: 'Use build server.'
type: object
responses:
'200':
'201':
description: 'Application created successfully.'
content:
application/json:
schema:
properties:
uuid: { type: string }
type: object
'401':
$ref: '#/components/responses/401'
'400':
@ -1129,8 +1159,14 @@ paths:
description: 'Use build server.'
type: object
responses:
'200':
'201':
description: 'Application created successfully.'
content:
application/json:
schema:
properties:
uuid: { type: string }
type: object
'401':
$ref: '#/components/responses/401'
'400':