From 3bbb861044023ab9f234718c35dde1c9af15cbd4 Mon Sep 17 00:00:00 2001
From: Joel von der Weid <joel.von-der-weid@hesge.ch>
Date: Tue, 27 Feb 2024 16:59:40 +0100
Subject: [PATCH] Add sonar route to check if ti is enabled

---
 ExpressAPI/assets/OpenAPI/OpenAPI.yaml | 25 +++++++++++++++++++++++++
 ExpressAPI/src/routes/BaseRoutes.ts    |  9 +++++++++
 ExpressAPI/src/shared                  |  2 +-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/ExpressAPI/assets/OpenAPI/OpenAPI.yaml b/ExpressAPI/assets/OpenAPI/OpenAPI.yaml
index 7f48388..820d542 100644
--- a/ExpressAPI/assets/OpenAPI/OpenAPI.yaml
+++ b/ExpressAPI/assets/OpenAPI/OpenAPI.yaml
@@ -48,6 +48,31 @@ paths:
                     description: OK
                 default:
                     $ref: '#/components/responses/ERROR'
+    /sonar:
+        get:
+            tags:
+                - General
+            summary: Check sonar status
+            description: This route can be used to check if the server supports sonar and if the integration is enabled.
+            responses:
+                '200':
+                    content:
+                        application/json:
+                            schema:
+                                allOf:
+                                    -   $ref: '#/components/schemas/DojoBackendResponse'
+                                    -   type: object
+                                        properties:
+                                            data:
+                                                type: object
+                                                properties:
+                                                    sonarEnabled:
+                                                        type: boolean
+                                                        examples:
+                                                            - true
+                    description: OK
+                default:
+                    $ref: '#/components/responses/ERROR'
     /login:
         post:
             tags:
diff --git a/ExpressAPI/src/routes/BaseRoutes.ts b/ExpressAPI/src/routes/BaseRoutes.ts
index 474f5bb..5d29ac0 100644
--- a/ExpressAPI/src/routes/BaseRoutes.ts
+++ b/ExpressAPI/src/routes/BaseRoutes.ts
@@ -2,12 +2,14 @@ import { Express }     from 'express-serve-static-core';
 import express         from 'express';
 import { StatusCodes } from 'http-status-codes';
 import RoutesManager   from '../express/RoutesManager';
+import SharedConfig    from '../shared/config/SharedConfig';
 
 
 class BaseRoutes implements RoutesManager {
     registerOnBackend(backend: Express) {
         backend.get('/', this.homepage.bind(this));
         backend.get('/health_check', this.healthCheck.bind(this));
+        backend.get('/sonar', this.sonar.bind(this));
     }
 
     private async homepage(req: express.Request, res: express.Response) {
@@ -17,6 +19,13 @@ class BaseRoutes implements RoutesManager {
     private async healthCheck(req: express.Request, res: express.Response) {
         return req.session.sendResponse(res, StatusCodes.OK);
     }
+
+    private async sonar(req: express.Request, res: express.Response) {
+        const data = {
+            sonarEnabled: SharedConfig.useSonar
+        };
+        return req.session.sendResponse(res, StatusCodes.OK, data);
+    }
 }
 
 
diff --git a/ExpressAPI/src/shared b/ExpressAPI/src/shared
index 9e3f29d..d509efa 160000
--- a/ExpressAPI/src/shared
+++ b/ExpressAPI/src/shared
@@ -1 +1 @@
-Subproject commit 9e3f29d2f313ef96944a199da0db39f1827c496a
+Subproject commit d509efa1b35e100446ace49d8e665ca72e5a7afe
-- 
GitLab