From 917abfc03cdf0141052e72d8a6deb8b269b96df4 Mon Sep 17 00:00:00 2001 From: b1ek Date: Wed, 21 Aug 2024 11:48:54 +1000 Subject: [PATCH] fix: unfuck list API --- controllers/ApiController.php | 5 ++- web/openapi.yml | 61 ++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 3b30e2d..292d7cb 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -12,7 +12,10 @@ class ApiController extends \yii\rest\Controller { public function actionIndex() { - return Parameter::find()->with(['icon', 'iconGray'])->all(); + return [ + 'images' => Image::find()->join('INNER JOIN', 'parameters', 'parameters.icon_id = image.id OR parameters.icon_gray_id = image.id')->all(), + 'params' => Parameter::find()->all(), + ]; } public function actionImage(Request $request, Response $response) diff --git a/web/openapi.yml b/web/openapi.yml index fd17dd2..94bc38f 100644 --- a/web/openapi.yml +++ b/web/openapi.yml @@ -47,33 +47,48 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/Parameter' - example: [ - { - "id": 1, - "title": "A thing happening somewhere", - "type": 1, - "icon": null, - "icon_gray": null - }, - { - "id": 2, - "title": "The fox jumping over a cat", - "type": 1, - "icon": { + type: object + properties: + images: + type: array + items: + $ref: '#/components/schemas/Image' + params: + type: array + items: + $ref: '#/components/schemas/Parameter' + example: { + "images": [ + { "id": 1, - "original_name": "fox_jump.jpeg", - "sha256": "SHA256" + "sha256": "0000000000000000000000000000000000000000000000000000000000000000", + "original_name": "filename.svg", + "mime": "image/svg+xml" }, - "icon_gray": { + { + "id": 1, + "sha256": "0000000000000000000000000000000000000000000000000000000000000001", + "original_name": "filename.svg", + "mime": "image/svg+xml" + }, + ], + "params": [ + { + "id": 1, + "title": "A thing happening somewhere", + "type": 1, + "icon": null, + "icon_gray": null + }, + { "id": 2, - "original_name": "fox_jump.gray.jpeg", - "sha256": "SHA256" + "title": "The fox jumping over a cat", + "type": 1, + "icon_id": 1, + "icon_gray_id": 2, } - } - ] + ], + } components: schemas: Image: