From d206ff2b99f67a6a0700d30d7ccddcf72ea640da 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 | 27 ++++++++++++++++++++++++++
 ExpressAPI/src/routes/BaseRoutes.ts    | 10 ++++++++++
 ExpressAPI/src/shared                  |  2 +-
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/ExpressAPI/assets/OpenAPI/OpenAPI.yaml b/ExpressAPI/assets/OpenAPI/OpenAPI.yaml
index fe3d4ef..7c83f80 100644
--- a/ExpressAPI/assets/OpenAPI/OpenAPI.yaml
+++ b/ExpressAPI/assets/OpenAPI/OpenAPI.yaml
@@ -86,6 +86,33 @@ paths:
                                                     - gitlabAccountUsername
                                                     - loginGitlabClientId
                     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 8e3b4c4..cf0746f 100644
--- a/ExpressAPI/src/routes/BaseRoutes.ts
+++ b/ExpressAPI/src/routes/BaseRoutes.ts
@@ -3,6 +3,7 @@ import express, { RequestHandler } from 'express';
 import { StatusCodes }             from 'http-status-codes';
 import RoutesManager               from '../express/RoutesManager.js';
 import Config                      from '../config/Config';
+import SharedConfig    from '../shared/config/SharedConfig';
 
 
 class BaseRoutes implements RoutesManager {
@@ -10,6 +11,8 @@ class BaseRoutes implements RoutesManager {
         backend.get('/', this.homepage.bind(this) as RequestHandler);
         backend.get('/health_check', this.healthCheck.bind(this) as RequestHandler);
 
+        backend.get('/sonar', this.sonar.bind(this));
+        
         backend.get('/clients_config', this.clientsConfig.bind(this) as RequestHandler);
     }
 
@@ -30,6 +33,13 @@ class BaseRoutes implements RoutesManager {
             exerciseMaxPerAssignment: Config.exercise.maxPerAssignment
         });
     }
+
+    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 92008b2..937081e 160000
--- a/ExpressAPI/src/shared
+++ b/ExpressAPI/src/shared
@@ -1 +1 @@
-Subproject commit 92008b25753c96bef9917cd39baab3a4d160cd9c
+Subproject commit 937081e68f6127b669daca30e57c43e73b9c96c9
-- 
GitLab