From 3639b4478f1d73f857b9c75d2af47c9d4cd99228 Mon Sep 17 00:00:00 2001 From: Firas Shmit Date: Tue, 15 Oct 2024 15:08:06 +0200 Subject: [PATCH 01/16] EW-1008 added filtered spec of lessons --- scripts/filtered-spec.json | 460 +++++++++++++++++++++++++++++++++++++ 1 file changed, 460 insertions(+) create mode 100644 scripts/filtered-spec.json diff --git a/scripts/filtered-spec.json b/scripts/filtered-spec.json new file mode 100644 index 00000000000..5c64e5c0e34 --- /dev/null +++ b/scripts/filtered-spec.json @@ -0,0 +1,460 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Schulcloud-Verbund-Software Server API", + "description": "This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1.", + "version": "3.0", + "contact": {} + }, + "servers": [ + { + "url": "/api/v3/" + } + ], + "paths": { + "/lessons/{lessonId}": { + "delete": { + "operationId": "LessonController_delete", + "parameters": [ + { + "name": "lessonId", + "required": true, + "in": "path", + "description": "The id of the lesson.", + "schema": { + "nullable": false, + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "boolean" + } + } + } + } + }, + "tags": [ + "Lesson" + ], + "security": [ + { + "bearer": [] + } + ] + }, + "get": { + "operationId": "LessonController_getLesson", + "parameters": [ + { + "name": "lessonId", + "required": true, + "in": "path", + "description": "The id of the lesson.", + "schema": { + "nullable": false, + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LessonResponse" + } + } + } + } + }, + "tags": [ + "Lesson" + ], + "security": [ + { + "bearer": [] + } + ] + } + }, + "/lessons/course/{courseId}": { + "get": { + "operationId": "LessonController_getCourseLessons", + "parameters": [ + { + "name": "courseId", + "required": true, + "in": "path", + "description": "The id of the course the lesson belongs to.", + "schema": { + "nullable": false, + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LessonMetadataListResponse" + } + } + } + } + }, + "tags": [ + "Lesson" + ], + "security": [ + { + "bearer": [] + } + ] + } + }, + "/lessons/{lessonId}/tasks": { + "get": { + "operationId": "LessonController_getLessonTasks", + "parameters": [ + { + "name": "lessonId", + "required": true, + "in": "path", + "description": "The id of the lesson.", + "schema": { + "nullable": false, + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/LessonLinkedTaskResponse" + } + } + } + } + } + }, + "tags": [ + "Lesson" + ], + "security": [ + { + "bearer": [] + } + ] + } + } + }, + "components": { + "securitySchemes": { + "bearer": { + "scheme": "bearer", + "bearerFormat": "JWT", + "type": "http" + } + }, + "schemas": { + "LessonMetadataResponse": { + "type": "object", + "properties": { + "_id": { + "type": "string", + "description": "The id of the Lesson entity", + "pattern": "[a-f0-9]{24}" + }, + "name": { + "type": "string", + "description": "Name of the Lesson entity" + } + }, + "required": [ + "_id", + "name" + ] + }, + "LessonMetadataListResponse": { + "type": "object", + "properties": { + "data": { + "description": "The items for the current page.", + "type": "array", + "items": { + "$ref": "#/components/schemas/LessonMetadataResponse" + } + }, + "total": { + "type": "number", + "description": "The total amount of items." + }, + "skip": { + "type": "number", + "description": "The amount of items skipped from the start." + }, + "limit": { + "type": "number", + "description": "The page size of the response." + } + }, + "required": [ + "data", + "total", + "skip", + "limit" + ] + }, + "LessonContentResponse": { + "type": "object", + "properties": { + "content": { + "type": "object" + }, + "_id": { + "type": "string", + "description": "The id of the Material entity", + "pattern": "[a-f0-9]{24}", + "deprecated": true + }, + "id": { + "type": "string", + "description": "The id of the Material entity", + "pattern": "[a-f0-9]{24}" + }, + "title": { + "type": "string", + "description": "Title of the Material entity" + }, + "component": { + "type": "string", + "enum": [ + "Etherpad", + "geoGebra", + "internal", + "resources", + "text", + "neXboard" + ] + }, + "hidden": { + "type": "boolean" + } + }, + "required": [ + "content", + "_id", + "id", + "title", + "component", + "hidden" + ] + }, + "MaterialResponse": { + "type": "object", + "properties": { + "_id": { + "type": "string", + "description": "The id of the Material entity", + "pattern": "[a-f0-9]{24}" + }, + "id": { + "type": "string", + "description": "The id of the Material entity", + "pattern": "[a-f0-9]{24}" + }, + "title": { + "type": "string", + "description": "Title of the Material entity" + }, + "relatedResources": { + "description": "?", + "type": "array", + "items": { + "type": "string" + } + }, + "url": { + "type": "string", + "description": "Url of the material" + }, + "client": { + "type": "string", + "description": "Position of the Lesson entity" + }, + "license": { + "description": "Description of the material license", + "type": "array", + "items": { + "type": "string" + } + }, + "merlinReference": { + "type": "string", + "description": "For material from Merlin, the Merlin reference" + } + }, + "required": [ + "_id", + "id", + "title", + "relatedResources", + "url", + "client", + "license", + "merlinReference" + ] + }, + "LessonResponse": { + "type": "object", + "properties": { + "_id": { + "type": "string", + "description": "The id of the Lesson entity", + "pattern": "[a-f0-9]{24}", + "deprecated": true + }, + "id": { + "type": "string", + "description": "The id of the Lesson entity", + "pattern": "[a-f0-9]{24}" + }, + "name": { + "type": "string", + "description": "Name of the Lesson entity" + }, + "courseId": { + "type": "string", + "description": "The id of the Course entity", + "pattern": "[a-f0-9]{24}" + }, + "courseGroupId": { + "type": "string", + "description": "The id of the Course-group entity", + "pattern": "[a-f0-9]{24}" + }, + "hidden": { + "type": "boolean", + "description": "Hidden status of the Lesson entity" + }, + "position": { + "type": "number", + "description": "Position of the Lesson entity" + }, + "contents": { + "description": "Contents of the Lesson entity", + "type": "array", + "items": { + "$ref": "#/components/schemas/LessonContentResponse" + } + }, + "materials": { + "description": "Materials of the Lesson entity", + "type": "array", + "items": { + "$ref": "#/components/schemas/MaterialResponse" + } + } + }, + "required": [ + "_id", + "id", + "name", + "hidden", + "position", + "contents", + "materials" + ] + }, + "LessonLinkedTaskResponse": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "descriptionInputFormat": { + "type": "string", + "enum": [ + "plainText", + "richTextCk5Simple", + "richTextCk4", + "richTextCk5" + ] + }, + "availableDate": { + "format": "date-time", + "type": "string", + "nullable": true + }, + "dueDate": { + "format": "date-time", + "type": "string", + "nullable": true + }, + "private": { + "type": "boolean" + }, + "publicSubmissions": { + "type": "boolean", + "nullable": true + }, + "teamSubmissions": { + "type": "boolean", + "nullable": true + }, + "creator": { + "type": "string", + "nullable": true + }, + "courseId": { + "type": "string", + "nullable": true + }, + "submissionIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "finishedIds": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "name", + "description", + "descriptionInputFormat", + "availableDate", + "dueDate", + "private", + "publicSubmissions", + "teamSubmissions", + "creator", + "courseId", + "submissionIds", + "finishedIds" + ] + } + } + } +} \ No newline at end of file From 03b00e1060cba956db5503e03e15bbac70448158 Mon Sep 17 00:00:00 2001 From: Maximilian Kreuzkam Date: Tue, 15 Oct 2024 16:34:44 +0200 Subject: [PATCH 02/16] Generate Api. --- .../lessons-api-client/.gitignore | 4 + .../lessons-api-client/.npmignore | 1 + .../.openapi-generator-ignore | 23 ++ .../.openapi-generator/FILES | 17 ++ .../.openapi-generator/VERSION | 1 + .../lesson-client/lessons-api-client/api.ts | 18 ++ .../lessons-api-client/api/lesson-api.ts | 228 ++++++++++++++++++ .../lesson-client/lessons-api-client/base.ts | 86 +++++++ .../lessons-api-client/common.ts | 150 ++++++++++++ .../lessons-api-client/configuration.ts | 110 +++++++++ .../lessons-api-client/git_push.sh | 57 +++++ .../lesson-client/lessons-api-client/index.ts | 18 ++ .../lessons-api-client/models/index.ts | 6 + .../models/lesson-content-response.ts | 73 ++++++ .../models/lesson-linked-task-response.ts | 106 ++++++++ .../models/lesson-metadata-list-response.ts | 51 ++++ .../models/lesson-metadata-response.ts | 36 +++ .../models/lesson-response.ts | 85 +++++++ .../models/material-response.ts | 72 ++++++ 19 files changed, 1142 insertions(+) create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.gitignore create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.npmignore create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator-ignore create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator/FILES create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator/VERSION create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/api.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/api/lesson-api.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/base.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/common.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/configuration.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/git_push.sh create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/index.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/index.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-content-response.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-linked-task-response.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-metadata-list-response.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-metadata-response.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-response.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/material-response.ts diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.gitignore b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.gitignore new file mode 100644 index 00000000000..149b5765472 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.gitignore @@ -0,0 +1,4 @@ +wwwroot/*.js +node_modules +typings +dist diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.npmignore b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.npmignore new file mode 100644 index 00000000000..999d88df693 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.npmignore @@ -0,0 +1 @@ +# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm \ No newline at end of file diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator-ignore b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator/FILES b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator/FILES new file mode 100644 index 00000000000..96db8953479 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator/FILES @@ -0,0 +1,17 @@ +.gitignore +.npmignore +.openapi-generator-ignore +api.ts +api/lesson-api.ts +base.ts +common.ts +configuration.ts +git_push.sh +index.ts +models/index.ts +models/lesson-content-response.ts +models/lesson-linked-task-response.ts +models/lesson-metadata-list-response.ts +models/lesson-metadata-response.ts +models/lesson-response.ts +models/material-response.ts diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator/VERSION b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator/VERSION new file mode 100644 index 00000000000..93c8ddab9fe --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.6.0 diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/api.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/api.ts new file mode 100644 index 00000000000..e2267d5e672 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/api.ts @@ -0,0 +1,18 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +export * from './api/lesson-api'; + diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/api/lesson-api.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/api/lesson-api.ts new file mode 100644 index 00000000000..7adc931634b --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/api/lesson-api.ts @@ -0,0 +1,228 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from '../configuration'; +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; +import globalAxios from 'axios'; +// Some imports not used depending on template conditions +// @ts-ignore +import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common'; +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base'; +// @ts-ignore +import type { LessonLinkedTaskResponse } from '../models'; +// @ts-ignore +import type { LessonResponse } from '../models'; +/** + * LessonApi - axios parameter creator + * @export + */ +export const LessonApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + lessonControllerGetLesson: async (lessonId: string, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'lessonId' is not null or undefined + assertParamExists('lessonControllerGetLesson', 'lessonId', lessonId) + const localVarPath = `/lessons/{lessonId}` + .replace(`{${"lessonId"}}`, encodeURIComponent(String(lessonId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication bearer required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + lessonControllerGetLessonTasks: async (lessonId: string, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'lessonId' is not null or undefined + assertParamExists('lessonControllerGetLessonTasks', 'lessonId', lessonId) + const localVarPath = `/lessons/{lessonId}/tasks` + .replace(`{${"lessonId"}}`, encodeURIComponent(String(lessonId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication bearer required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * LessonApi - functional programming interface + * @export + */ +export const LessonApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = LessonApiAxiosParamCreator(configuration) + return { + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async lessonControllerGetLesson(lessonId: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.lessonControllerGetLesson(lessonId, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['LessonApi.lessonControllerGetLesson']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async lessonControllerGetLessonTasks(lessonId: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.lessonControllerGetLessonTasks(lessonId, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['LessonApi.lessonControllerGetLessonTasks']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + } +}; + +/** + * LessonApi - factory interface + * @export + */ +export const LessonApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + const localVarFp = LessonApiFp(configuration) + return { + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + lessonControllerGetLesson(lessonId: string, options?: any): AxiosPromise { + return localVarFp.lessonControllerGetLesson(lessonId, options).then((request) => request(axios, basePath)); + }, + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + lessonControllerGetLessonTasks(lessonId: string, options?: any): AxiosPromise> { + return localVarFp.lessonControllerGetLessonTasks(lessonId, options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * LessonApi - interface + * @export + * @interface LessonApi + */ +export interface LessonApiInterface { + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof LessonApiInterface + */ + lessonControllerGetLesson(lessonId: string, options?: RawAxiosRequestConfig): AxiosPromise; + + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof LessonApiInterface + */ + lessonControllerGetLessonTasks(lessonId: string, options?: RawAxiosRequestConfig): AxiosPromise>; + +} + +/** + * LessonApi - object-oriented interface + * @export + * @class LessonApi + * @extends {BaseAPI} + */ +export class LessonApi extends BaseAPI implements LessonApiInterface { + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof LessonApi + */ + public lessonControllerGetLesson(lessonId: string, options?: RawAxiosRequestConfig) { + return LessonApiFp(this.configuration).lessonControllerGetLesson(lessonId, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @param {string} lessonId The id of the lesson. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof LessonApi + */ + public lessonControllerGetLessonTasks(lessonId: string, options?: RawAxiosRequestConfig) { + return LessonApiFp(this.configuration).lessonControllerGetLessonTasks(lessonId, options).then((request) => request(this.axios, this.basePath)); + } +} + diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/base.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/base.ts new file mode 100644 index 00000000000..82686c7b81b --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/base.ts @@ -0,0 +1,86 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from './configuration'; +// Some imports not used depending on template conditions +// @ts-ignore +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; +import globalAxios from 'axios'; + +export const BASE_PATH = "http://localhost/api/v3".replace(/\/+$/, ""); + +/** + * + * @export + */ +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +/** + * + * @export + * @interface RequestArgs + */ +export interface RequestArgs { + url: string; + options: RawAxiosRequestConfig; +} + +/** + * + * @export + * @class BaseAPI + */ +export class BaseAPI { + protected configuration: Configuration | undefined; + + constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) { + if (configuration) { + this.configuration = configuration; + this.basePath = configuration.basePath ?? basePath; + } + } +}; + +/** + * + * @export + * @class RequiredError + * @extends {Error} + */ +export class RequiredError extends Error { + constructor(public field: string, msg?: string) { + super(msg); + this.name = "RequiredError" + } +} + +interface ServerMap { + [key: string]: { + url: string, + description: string, + }[]; +} + +/** + * + * @export + */ +export const operationServerMap: ServerMap = { +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/common.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/common.ts new file mode 100644 index 00000000000..6c119efb60d --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/common.ts @@ -0,0 +1,150 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from "./configuration"; +import type { RequestArgs } from "./base"; +import type { AxiosInstance, AxiosResponse } from 'axios'; +import { RequiredError } from "./base"; + +/** + * + * @export + */ +export const DUMMY_BASE_URL = 'https://example.com' + +/** + * + * @throws {RequiredError} + * @export + */ +export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) { + if (paramValue === null || paramValue === undefined) { + throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); + } +} + +/** + * + * @export + */ +export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) { + if (configuration && configuration.apiKey) { + const localVarApiKeyValue = typeof configuration.apiKey === 'function' + ? await configuration.apiKey(keyParamName) + : await configuration.apiKey; + object[keyParamName] = localVarApiKeyValue; + } +} + +/** + * + * @export + */ +export const setBasicAuthToObject = function (object: any, configuration?: Configuration) { + if (configuration && (configuration.username || configuration.password)) { + object["auth"] = { username: configuration.username, password: configuration.password }; + } +} + +/** + * + * @export + */ +export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) { + if (configuration && configuration.accessToken) { + const accessToken = typeof configuration.accessToken === 'function' + ? await configuration.accessToken() + : await configuration.accessToken; + object["Authorization"] = "Bearer " + accessToken; + } +} + +/** + * + * @export + */ +export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) { + if (configuration && configuration.accessToken) { + const localVarAccessTokenValue = typeof configuration.accessToken === 'function' + ? await configuration.accessToken(name, scopes) + : await configuration.accessToken; + object["Authorization"] = "Bearer " + localVarAccessTokenValue; + } +} + +function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void { + if (parameter == null) return; + if (typeof parameter === "object") { + if (Array.isArray(parameter)) { + (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); + } + else { + Object.keys(parameter).forEach(currentKey => + setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`) + ); + } + } + else { + if (urlSearchParams.has(key)) { + urlSearchParams.append(key, parameter); + } + else { + urlSearchParams.set(key, parameter); + } + } +} + +/** + * + * @export + */ +export const setSearchParams = function (url: URL, ...objects: any[]) { + const searchParams = new URLSearchParams(url.search); + setFlattenedQueryParams(searchParams, objects); + url.search = searchParams.toString(); +} + +/** + * + * @export + */ +export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) { + const nonString = typeof value !== 'string'; + const needsSerialization = nonString && configuration && configuration.isJsonMime + ? configuration.isJsonMime(requestOptions.headers['Content-Type']) + : nonString; + return needsSerialization + ? JSON.stringify(value !== undefined ? value : {}) + : (value || ""); +} + +/** + * + * @export + */ +export const toPathString = function (url: URL) { + return url.pathname + url.search + url.hash +} + +/** + * + * @export + */ +export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) { + return >(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url}; + return axios.request(axiosRequestArgs); + }; +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/configuration.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/configuration.ts new file mode 100644 index 00000000000..8c97d307cf4 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/configuration.ts @@ -0,0 +1,110 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface ConfigurationParameters { + apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); + username?: string; + password?: string; + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); + basePath?: string; + serverIndex?: number; + baseOptions?: any; + formDataCtor?: new () => any; +} + +export class Configuration { + /** + * parameter for apiKey security + * @param name security name + * @memberof Configuration + */ + apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); + /** + * parameter for basic security + * + * @type {string} + * @memberof Configuration + */ + username?: string; + /** + * parameter for basic security + * + * @type {string} + * @memberof Configuration + */ + password?: string; + /** + * parameter for oauth2 security + * @param name security name + * @param scopes oauth2 scope + * @memberof Configuration + */ + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); + /** + * override base path + * + * @type {string} + * @memberof Configuration + */ + basePath?: string; + /** + * override server index + * + * @type {number} + * @memberof Configuration + */ + serverIndex?: number; + /** + * base options for axios calls + * + * @type {any} + * @memberof Configuration + */ + baseOptions?: any; + /** + * The FormData constructor that will be used to create multipart form data + * requests. You can inject this here so that execution environments that + * do not support the FormData class can still run the generated client. + * + * @type {new () => FormData} + */ + formDataCtor?: new () => any; + + constructor(param: ConfigurationParameters = {}) { + this.apiKey = param.apiKey; + this.username = param.username; + this.password = param.password; + this.accessToken = param.accessToken; + this.basePath = param.basePath; + this.serverIndex = param.serverIndex; + this.baseOptions = param.baseOptions; + this.formDataCtor = param.formDataCtor; + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + public isJsonMime(mime: string): boolean { + const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); + return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); + } +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/git_push.sh b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/git_push.sh new file mode 100644 index 00000000000..f53a75d4fab --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/index.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/index.ts new file mode 100644 index 00000000000..8b762df664e --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/index.ts @@ -0,0 +1,18 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export * from "./api"; +export * from "./configuration"; +export * from "./models"; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/index.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/index.ts new file mode 100644 index 00000000000..9abd938430d --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/index.ts @@ -0,0 +1,6 @@ +export * from './lesson-content-response'; +export * from './lesson-linked-task-response'; +export * from './lesson-metadata-list-response'; +export * from './lesson-metadata-response'; +export * from './lesson-response'; +export * from './material-response'; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-content-response.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-content-response.ts new file mode 100644 index 00000000000..da12106638f --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-content-response.ts @@ -0,0 +1,73 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface LessonContentResponse + */ +export interface LessonContentResponse { + /** + * + * @type {object} + * @memberof LessonContentResponse + */ + 'content': object; + /** + * The id of the Material entity + * @type {string} + * @memberof LessonContentResponse + * @deprecated + */ + '_id': string; + /** + * The id of the Material entity + * @type {string} + * @memberof LessonContentResponse + */ + 'id': string; + /** + * Title of the Material entity + * @type {string} + * @memberof LessonContentResponse + */ + 'title': string; + /** + * + * @type {string} + * @memberof LessonContentResponse + */ + 'component': LessonContentResponseComponent; + /** + * + * @type {boolean} + * @memberof LessonContentResponse + */ + 'hidden': boolean; +} + +export const LessonContentResponseComponent = { + ETHERPAD: 'Etherpad', + GEO_GEBRA: 'geoGebra', + INTERNAL: 'internal', + RESOURCES: 'resources', + TEXT: 'text', + NE_XBOARD: 'neXboard' +} as const; + +export type LessonContentResponseComponent = typeof LessonContentResponseComponent[keyof typeof LessonContentResponseComponent]; + + diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-linked-task-response.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-linked-task-response.ts new file mode 100644 index 00000000000..58cc71d2d39 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-linked-task-response.ts @@ -0,0 +1,106 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface LessonLinkedTaskResponse + */ +export interface LessonLinkedTaskResponse { + /** + * + * @type {string} + * @memberof LessonLinkedTaskResponse + */ + 'name': string; + /** + * + * @type {string} + * @memberof LessonLinkedTaskResponse + */ + 'description': string; + /** + * + * @type {string} + * @memberof LessonLinkedTaskResponse + */ + 'descriptionInputFormat': LessonLinkedTaskResponseDescriptionInputFormat; + /** + * + * @type {string} + * @memberof LessonLinkedTaskResponse + */ + 'availableDate': string | null; + /** + * + * @type {string} + * @memberof LessonLinkedTaskResponse + */ + 'dueDate': string | null; + /** + * + * @type {boolean} + * @memberof LessonLinkedTaskResponse + */ + 'private': boolean; + /** + * + * @type {boolean} + * @memberof LessonLinkedTaskResponse + */ + 'publicSubmissions': boolean | null; + /** + * + * @type {boolean} + * @memberof LessonLinkedTaskResponse + */ + 'teamSubmissions': boolean | null; + /** + * + * @type {string} + * @memberof LessonLinkedTaskResponse + */ + 'creator': string | null; + /** + * + * @type {string} + * @memberof LessonLinkedTaskResponse + */ + 'courseId': string | null; + /** + * + * @type {Array} + * @memberof LessonLinkedTaskResponse + */ + 'submissionIds': Array; + /** + * + * @type {Array} + * @memberof LessonLinkedTaskResponse + */ + 'finishedIds': Array; +} + +export const LessonLinkedTaskResponseDescriptionInputFormat = { + PLAIN_TEXT: 'plainText', + RICH_TEXT_CK5_SIMPLE: 'richTextCk5Simple', + RICH_TEXT_CK4: 'richTextCk4', + RICH_TEXT_CK5: 'richTextCk5' +} as const; + +export type LessonLinkedTaskResponseDescriptionInputFormat = typeof LessonLinkedTaskResponseDescriptionInputFormat[keyof typeof LessonLinkedTaskResponseDescriptionInputFormat]; + + diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-metadata-list-response.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-metadata-list-response.ts new file mode 100644 index 00000000000..4a528b10ead --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-metadata-list-response.ts @@ -0,0 +1,51 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import type { LessonMetadataResponse } from './lesson-metadata-response'; + +/** + * + * @export + * @interface LessonMetadataListResponse + */ +export interface LessonMetadataListResponse { + /** + * The items for the current page. + * @type {Array} + * @memberof LessonMetadataListResponse + */ + 'data': Array; + /** + * The total amount of items. + * @type {number} + * @memberof LessonMetadataListResponse + */ + 'total': number; + /** + * The amount of items skipped from the start. + * @type {number} + * @memberof LessonMetadataListResponse + */ + 'skip': number; + /** + * The page size of the response. + * @type {number} + * @memberof LessonMetadataListResponse + */ + 'limit': number; +} + diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-metadata-response.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-metadata-response.ts new file mode 100644 index 00000000000..c9e144139a1 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-metadata-response.ts @@ -0,0 +1,36 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface LessonMetadataResponse + */ +export interface LessonMetadataResponse { + /** + * The id of the Lesson entity + * @type {string} + * @memberof LessonMetadataResponse + */ + '_id': string; + /** + * Name of the Lesson entity + * @type {string} + * @memberof LessonMetadataResponse + */ + 'name': string; +} + diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-response.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-response.ts new file mode 100644 index 00000000000..ac2a0c697ba --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/lesson-response.ts @@ -0,0 +1,85 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import type { LessonContentResponse } from './lesson-content-response'; +// May contain unused imports in some cases +// @ts-ignore +import type { MaterialResponse } from './material-response'; + +/** + * + * @export + * @interface LessonResponse + */ +export interface LessonResponse { + /** + * The id of the Lesson entity + * @type {string} + * @memberof LessonResponse + * @deprecated + */ + '_id': string; + /** + * The id of the Lesson entity + * @type {string} + * @memberof LessonResponse + */ + 'id': string; + /** + * Name of the Lesson entity + * @type {string} + * @memberof LessonResponse + */ + 'name': string; + /** + * The id of the Course entity + * @type {string} + * @memberof LessonResponse + */ + 'courseId'?: string; + /** + * The id of the Course-group entity + * @type {string} + * @memberof LessonResponse + */ + 'courseGroupId'?: string; + /** + * Hidden status of the Lesson entity + * @type {boolean} + * @memberof LessonResponse + */ + 'hidden': boolean; + /** + * Position of the Lesson entity + * @type {number} + * @memberof LessonResponse + */ + 'position': number; + /** + * Contents of the Lesson entity + * @type {Array} + * @memberof LessonResponse + */ + 'contents': Array; + /** + * Materials of the Lesson entity + * @type {Array} + * @memberof LessonResponse + */ + 'materials': Array; +} + diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/material-response.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/material-response.ts new file mode 100644 index 00000000000..6b427cb511f --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-api-client/models/material-response.ts @@ -0,0 +1,72 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface MaterialResponse + */ +export interface MaterialResponse { + /** + * The id of the Material entity + * @type {string} + * @memberof MaterialResponse + */ + '_id': string; + /** + * The id of the Material entity + * @type {string} + * @memberof MaterialResponse + */ + 'id': string; + /** + * Title of the Material entity + * @type {string} + * @memberof MaterialResponse + */ + 'title': string; + /** + * ? + * @type {Array} + * @memberof MaterialResponse + */ + 'relatedResources': Array; + /** + * Url of the material + * @type {string} + * @memberof MaterialResponse + */ + 'url': string; + /** + * Position of the Lesson entity + * @type {string} + * @memberof MaterialResponse + */ + 'client': string; + /** + * Description of the material license + * @type {Array} + * @memberof MaterialResponse + */ + 'license': Array; + /** + * For material from Merlin, the Merlin reference + * @type {string} + * @memberof MaterialResponse + */ + 'merlinReference': string; +} + From b755abd3a5ba0dd94203c9d492312ddb78f120a7 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Tue, 15 Oct 2024 16:40:10 +0200 Subject: [PATCH 03/16] ignore sonar generated code --- scripts/filtered-spec.json | 460 ------------------------------------- sonar-project.properties | 2 +- 2 files changed, 1 insertion(+), 461 deletions(-) delete mode 100644 scripts/filtered-spec.json diff --git a/scripts/filtered-spec.json b/scripts/filtered-spec.json deleted file mode 100644 index 5c64e5c0e34..00000000000 --- a/scripts/filtered-spec.json +++ /dev/null @@ -1,460 +0,0 @@ -{ - "openapi": "3.0.0", - "info": { - "title": "Schulcloud-Verbund-Software Server API", - "description": "This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1.", - "version": "3.0", - "contact": {} - }, - "servers": [ - { - "url": "/api/v3/" - } - ], - "paths": { - "/lessons/{lessonId}": { - "delete": { - "operationId": "LessonController_delete", - "parameters": [ - { - "name": "lessonId", - "required": true, - "in": "path", - "description": "The id of the lesson.", - "schema": { - "nullable": false, - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "boolean" - } - } - } - } - }, - "tags": [ - "Lesson" - ], - "security": [ - { - "bearer": [] - } - ] - }, - "get": { - "operationId": "LessonController_getLesson", - "parameters": [ - { - "name": "lessonId", - "required": true, - "in": "path", - "description": "The id of the lesson.", - "schema": { - "nullable": false, - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/LessonResponse" - } - } - } - } - }, - "tags": [ - "Lesson" - ], - "security": [ - { - "bearer": [] - } - ] - } - }, - "/lessons/course/{courseId}": { - "get": { - "operationId": "LessonController_getCourseLessons", - "parameters": [ - { - "name": "courseId", - "required": true, - "in": "path", - "description": "The id of the course the lesson belongs to.", - "schema": { - "nullable": false, - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/LessonMetadataListResponse" - } - } - } - } - }, - "tags": [ - "Lesson" - ], - "security": [ - { - "bearer": [] - } - ] - } - }, - "/lessons/{lessonId}/tasks": { - "get": { - "operationId": "LessonController_getLessonTasks", - "parameters": [ - { - "name": "lessonId", - "required": true, - "in": "path", - "description": "The id of the lesson.", - "schema": { - "nullable": false, - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/LessonLinkedTaskResponse" - } - } - } - } - } - }, - "tags": [ - "Lesson" - ], - "security": [ - { - "bearer": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "bearer": { - "scheme": "bearer", - "bearerFormat": "JWT", - "type": "http" - } - }, - "schemas": { - "LessonMetadataResponse": { - "type": "object", - "properties": { - "_id": { - "type": "string", - "description": "The id of the Lesson entity", - "pattern": "[a-f0-9]{24}" - }, - "name": { - "type": "string", - "description": "Name of the Lesson entity" - } - }, - "required": [ - "_id", - "name" - ] - }, - "LessonMetadataListResponse": { - "type": "object", - "properties": { - "data": { - "description": "The items for the current page.", - "type": "array", - "items": { - "$ref": "#/components/schemas/LessonMetadataResponse" - } - }, - "total": { - "type": "number", - "description": "The total amount of items." - }, - "skip": { - "type": "number", - "description": "The amount of items skipped from the start." - }, - "limit": { - "type": "number", - "description": "The page size of the response." - } - }, - "required": [ - "data", - "total", - "skip", - "limit" - ] - }, - "LessonContentResponse": { - "type": "object", - "properties": { - "content": { - "type": "object" - }, - "_id": { - "type": "string", - "description": "The id of the Material entity", - "pattern": "[a-f0-9]{24}", - "deprecated": true - }, - "id": { - "type": "string", - "description": "The id of the Material entity", - "pattern": "[a-f0-9]{24}" - }, - "title": { - "type": "string", - "description": "Title of the Material entity" - }, - "component": { - "type": "string", - "enum": [ - "Etherpad", - "geoGebra", - "internal", - "resources", - "text", - "neXboard" - ] - }, - "hidden": { - "type": "boolean" - } - }, - "required": [ - "content", - "_id", - "id", - "title", - "component", - "hidden" - ] - }, - "MaterialResponse": { - "type": "object", - "properties": { - "_id": { - "type": "string", - "description": "The id of the Material entity", - "pattern": "[a-f0-9]{24}" - }, - "id": { - "type": "string", - "description": "The id of the Material entity", - "pattern": "[a-f0-9]{24}" - }, - "title": { - "type": "string", - "description": "Title of the Material entity" - }, - "relatedResources": { - "description": "?", - "type": "array", - "items": { - "type": "string" - } - }, - "url": { - "type": "string", - "description": "Url of the material" - }, - "client": { - "type": "string", - "description": "Position of the Lesson entity" - }, - "license": { - "description": "Description of the material license", - "type": "array", - "items": { - "type": "string" - } - }, - "merlinReference": { - "type": "string", - "description": "For material from Merlin, the Merlin reference" - } - }, - "required": [ - "_id", - "id", - "title", - "relatedResources", - "url", - "client", - "license", - "merlinReference" - ] - }, - "LessonResponse": { - "type": "object", - "properties": { - "_id": { - "type": "string", - "description": "The id of the Lesson entity", - "pattern": "[a-f0-9]{24}", - "deprecated": true - }, - "id": { - "type": "string", - "description": "The id of the Lesson entity", - "pattern": "[a-f0-9]{24}" - }, - "name": { - "type": "string", - "description": "Name of the Lesson entity" - }, - "courseId": { - "type": "string", - "description": "The id of the Course entity", - "pattern": "[a-f0-9]{24}" - }, - "courseGroupId": { - "type": "string", - "description": "The id of the Course-group entity", - "pattern": "[a-f0-9]{24}" - }, - "hidden": { - "type": "boolean", - "description": "Hidden status of the Lesson entity" - }, - "position": { - "type": "number", - "description": "Position of the Lesson entity" - }, - "contents": { - "description": "Contents of the Lesson entity", - "type": "array", - "items": { - "$ref": "#/components/schemas/LessonContentResponse" - } - }, - "materials": { - "description": "Materials of the Lesson entity", - "type": "array", - "items": { - "$ref": "#/components/schemas/MaterialResponse" - } - } - }, - "required": [ - "_id", - "id", - "name", - "hidden", - "position", - "contents", - "materials" - ] - }, - "LessonLinkedTaskResponse": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "description": { - "type": "string" - }, - "descriptionInputFormat": { - "type": "string", - "enum": [ - "plainText", - "richTextCk5Simple", - "richTextCk4", - "richTextCk5" - ] - }, - "availableDate": { - "format": "date-time", - "type": "string", - "nullable": true - }, - "dueDate": { - "format": "date-time", - "type": "string", - "nullable": true - }, - "private": { - "type": "boolean" - }, - "publicSubmissions": { - "type": "boolean", - "nullable": true - }, - "teamSubmissions": { - "type": "boolean", - "nullable": true - }, - "creator": { - "type": "string", - "nullable": true - }, - "courseId": { - "type": "string", - "nullable": true - }, - "submissionIds": { - "type": "array", - "items": { - "type": "string" - } - }, - "finishedIds": { - "type": "array", - "items": { - "type": "string" - } - } - }, - "required": [ - "name", - "description", - "descriptionInputFormat", - "availableDate", - "dueDate", - "private", - "publicSubmissions", - "teamSubmissions", - "creator", - "courseId", - "submissionIds", - "finishedIds" - ] - } - } - } -} \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties index 79aa1797c82..d8f2f98ccd8 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,7 @@ sonar.projectKey=hpi-schul-cloud_schulcloud-server sonar.sources=. sonar.tests=. sonar.test.inclusions=**/*.spec.ts -sonar.exclusions=**/*.js,jest.config.ts,globalSetup.ts,globalTeardown.ts,**/*.app.ts,**/seed-data/*.ts,**/migrations/mikro-orm/*.ts,**/etherpad-api-client/**/*.ts,**/authorization-api-client/**/*.ts, **/course-api-client/**/*.ts,**/board-api-client/**/*.ts,**/generated/**/*.ts,**/room-api-client/**/*.ts +sonar.exclusions=**/*.js,jest.config.ts,globalSetup.ts,globalTeardown.ts,**/*.app.ts,**/seed-data/*.ts,**/migrations/mikro-orm/*.ts,**/etherpad-api-client/**/*.ts,**/authorization-api-client/**/*.ts, **/course-api-client/**/*.ts,**/board-api-client/**/*.ts,**/generated/**/*.ts,**/room-api-client/**/*.ts,**/lessons-api-client/**/*.ts sonar.coverage.exclusions=**/board-management.uc.ts,**/*.module.ts,**/*.factory.ts,**/migrations/mikro-orm/*.ts,**/globalSetup.ts,**/globalTeardown.ts,**/etherpad-api-client/**/*.ts,**/authorization-api-client/**/*.ts, **/course-api-client/**/*.ts,**/board-api-client/**/*.ts,**/generated/**/*.ts,**/room-api-client/**/*.ts sonar.cpd.exclusions=**/controller/dto/**/*.ts,**/api/dto/**/*.ts,**/shared/testing/factory/*.factory.ts sonar.javascript.lcov.reportPaths=merged-lcov.info From e8c3330a31e4c6554a60a4605b5b1c4e6025f0ba Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Wed, 16 Oct 2024 16:59:57 +0200 Subject: [PATCH 04/16] implement getLesson/getLessonTasks --- .../lesson-client/dto/index.ts | 6 ++ .../lesson-client/dto/lesson-contents.dto.ts | 34 ++++++++++ .../dto/lesson-linked-task.dto.ts | 50 +++++++++++++++ .../lesson-client/dto/lesson-materials.dto.ts | 28 ++++++++ .../dto/lesson-meta-data-list.dto.ts | 18 ++++++ .../lesson-client/dto/lesson-meta-data.dto.ts | 10 +++ .../lesson-client/dto/lesson.dto.ts | 34 ++++++++++ .../lesson-client/lesson-client.adapter.ts | 52 +++++++++++++++ .../lesson-client/lesson-client.config.ts | 5 ++ .../lesson-client/lessons-client.module.ts | 26 ++++++++ .../lesson-client/mapper/lesson-dto.mapper.ts | 64 +++++++++++++++++++ 11 files changed, 327 insertions(+) create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/index.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-linked-task.dto.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-materials.dto.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data-list.dto.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data.dto.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson.dto.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.config.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-client.module.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/index.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/index.ts new file mode 100644 index 00000000000..11609ff5890 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/index.ts @@ -0,0 +1,6 @@ +export * from './lesson.dto'; +export * from './lesson-materials.dto'; +export * from './lesson-contents.dto'; +export * from './lesson-linked-task.dto'; +export * from './lesson-meta-data.dto'; +export * from './lesson-meta-data-list.dto'; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts new file mode 100644 index 00000000000..df49916130e --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts @@ -0,0 +1,34 @@ +export class LessonContentDto { + content: object; + + _id: string; + + contentId: string; + + title: string; + + component: LessonContentDtoComponent; + + hidden: boolean; + + constructor(props: LessonContentDto) { + this.content = props.content; + this._id = props._id; + this.contentId = props.contentId; + this.title = props.title; + this.component = props.component; + this.hidden = props.hidden; + } +} + +export const LessonContentDtoComponentValues = { + ETHERPAD: 'Etherpad', + GEO_GEBRA: 'geoGebra', + INTERNAL: 'internal', + RESOURCES: 'resources', + TEXT: 'text', + NE_XBOARD: 'neXboard', +} as const; + +export type LessonContentDtoComponent = + typeof LessonContentDtoComponentValues[keyof typeof LessonContentDtoComponentValues]; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-linked-task.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-linked-task.dto.ts new file mode 100644 index 00000000000..f2b5344b4ac --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-linked-task.dto.ts @@ -0,0 +1,50 @@ +export class LessonLinkedTaskDto { + name: string; + + description: string; + + descriptionInputFormat: LessonLinkedTaskDescriptionInputFormatType; + + availableDate: string | null; + + dueDate: string | null; + + private: boolean; + + publicSubmissions: boolean | null; + + teamSubmissions: boolean | null; + + creator: string | null; + + courseId: string | null; + + submissionIds: string[]; + + finishedIds: string[]; + + constructor(props: LessonLinkedTaskDto) { + this.name = props.name; + this.description = props.description; + this.descriptionInputFormat = props.descriptionInputFormat; + this.availableDate = props.availableDate; + this.dueDate = props.dueDate; + this.private = props.private; + this.creator = props.creator; + this.courseId = props.courseId; + this.publicSubmissions = props.publicSubmissions; + this.teamSubmissions = props.teamSubmissions; + this.submissionIds = props.submissionIds; + this.finishedIds = props.finishedIds; + } +} + +export const LessonLinkedTaskDescriptionInputFormat = { + PLAIN_TEXT: 'plainText', + RICH_TEXT_CK5_SIMPLE: 'richTextCk5Simple', + RICH_TEXT_CK4: 'richTextCk4', + RICH_TEXT_CK5: 'richTextCk5', +} as const; + +export type LessonLinkedTaskDescriptionInputFormatType = + typeof LessonLinkedTaskDescriptionInputFormat[keyof typeof LessonLinkedTaskDescriptionInputFormat]; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-materials.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-materials.dto.ts new file mode 100644 index 00000000000..90845e646ed --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-materials.dto.ts @@ -0,0 +1,28 @@ +export class LessonMaterialsDto { + _id: string; + + materialsId: string; + + title: string; + + relatedResources: string[]; + + url: string; + + client: string; + + license: string[]; + + merlinReference: string; + + constructor(props: LessonMaterialsDto) { + this._id = props._id; + this.materialsId = props.materialsId; + this.title = props.title; + this.relatedResources = props.relatedResources; + this.url = props.url; + this.client = props.client; + this.license = props.license; + this.merlinReference = props.merlinReference; + } +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data-list.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data-list.dto.ts new file mode 100644 index 00000000000..a32563e969f --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data-list.dto.ts @@ -0,0 +1,18 @@ +import { LessonMetaDataDto } from './lesson-meta-data.dto'; + +export class LessonMetaDataListDto { + data: Array; + + total: number; + + skip: number; + + limit: number; + + constructor(props: LessonMetaDataListDto) { + this.data = props.data; + this.total = props.total; + this.skip = props.skip; + this.limit = props.limit; + } +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data.dto.ts new file mode 100644 index 00000000000..b614c2dce14 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data.dto.ts @@ -0,0 +1,10 @@ +export class LessonMetaDataDto { + _id: string; + + name: string; + + constructor(props: LessonMetaDataDto) { + this._id = props._id; + this.name = props.name; + } +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson.dto.ts new file mode 100644 index 00000000000..aba4739bf6f --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson.dto.ts @@ -0,0 +1,34 @@ +import { LessonContentDto } from './lesson-contents.dto'; +import { LessonMaterialsDto } from './lesson-materials.dto'; + +export class LessonDto { + _id: string; + + lessonId: string; + + name: string; + + courseId?: string; + + courseGroupId?: string; + + hidden: boolean; + + position: number; + + contents: LessonContentDto[]; + + materials: LessonMaterialsDto[]; + + constructor(props: LessonDto) { + this._id = props._id; + this.lessonId = props.lessonId; + this.name = props.name; + this.courseId = props.courseId; + this.courseGroupId = props.courseGroupId; + this.hidden = props.hidden; + this.position = props.position; + this.contents = props.contents; + this.materials = props.materials; + } +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.ts new file mode 100644 index 00000000000..1f215baa312 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.ts @@ -0,0 +1,52 @@ +import { Inject, Injectable, UnauthorizedException } from '@nestjs/common'; +import { REQUEST } from '@nestjs/core'; +import { extractJwtFromHeader } from '@shared/common'; +import { RawAxiosRequestConfig } from 'axios'; +import { Request } from 'express'; +import { LessonDto, LessonLinkedTaskDto } from './dto'; +import { LessonApi } from './lessons-api-client'; +import { LessonDtoMapper } from './mapper/lesson-dto.mapper'; + +@Injectable() +export class LessonClientAdapter { + constructor(private readonly lessonApi: LessonApi, @Inject(REQUEST) private request: Request) {} + + public async getLessonById(lessonId: string): Promise { + const options = this.createOptionParams(); + const lessonResponse = await this.lessonApi + .lessonControllerGetLesson(lessonId, options) + .then((response) => response.data); + + const lessonDto = LessonDtoMapper.mapToLessonDto(lessonResponse); + + return lessonDto; + } + + public async getLessonTasks(lessonId: string): Promise { + const options = this.createOptionParams(); + const lessonTasksResponse = await this.lessonApi + .lessonControllerGetLessonTasks(lessonId, options) + .then((response) => response.data); + + const lessonTasksDtoList = lessonTasksResponse.map((task) => LessonDtoMapper.mapToLessonLinkedTaskDto(task)); + + return lessonTasksDtoList; + } + + private createOptionParams(): RawAxiosRequestConfig { + const jwt = this.getJwt(); + const options: RawAxiosRequestConfig = { headers: { authorization: `Bearer ${jwt}` } }; + + return options; + } + + private getJwt(): string { + const jwt = extractJwtFromHeader(this.request) ?? this.request.headers.authorization; + + if (!jwt) { + throw new UnauthorizedException('No JWT found in request'); + } + + return jwt; + } +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.config.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.config.ts new file mode 100644 index 00000000000..48cabd48e58 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.config.ts @@ -0,0 +1,5 @@ +import { ConfigurationParameters } from './lessons-api-client'; + +export interface LessonsClientConfig extends ConfigurationParameters { + basePath: string; +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-client.module.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-client.module.ts new file mode 100644 index 00000000000..e04fbf1ffb7 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-client.module.ts @@ -0,0 +1,26 @@ +import { DynamicModule, Module } from '@nestjs/common'; +import { LessonsClientConfig } from './lesson-client.config'; +import { LessonClientAdapter } from './lesson-client.adapter'; +import { LessonApi, Configuration } from './lessons-api-client'; + +@Module({}) +export class LessonsClientModule { + static register(config: LessonsClientConfig): DynamicModule { + const providers = [ + LessonClientAdapter, + { + provide: LessonApi, + useFactory: () => { + const configuration = new Configuration(config); + return new LessonApi(configuration); + }, + }, + ]; + + return { + module: LessonsClientModule, + providers, + exports: [LessonClientAdapter], + }; + } +} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts new file mode 100644 index 00000000000..700fd1084dd --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts @@ -0,0 +1,64 @@ +import { LessonContentDto, LessonDto, LessonLinkedTaskDto, LessonMaterialsDto } from '../dto'; +import { + LessonContentResponse, + LessonLinkedTaskResponse, + LessonResponse, + MaterialResponse, +} from '../lessons-api-client'; + +export class LessonDtoMapper { + static mapToLessonLinkedTaskDto(task: LessonLinkedTaskResponse): LessonLinkedTaskDto { + return new LessonLinkedTaskDto({ + name: task.name, + description: task.description, + descriptionInputFormat: task.descriptionInputFormat, + availableDate: task.availableDate, + dueDate: task.dueDate, + private: task.private, + publicSubmissions: task.publicSubmissions, + teamSubmissions: task.teamSubmissions, + courseId: task.courseId, + creator: task.creator, + submissionIds: task.submissionIds, + finishedIds: task.finishedIds, + }); + } + + public static mapToLessonDto(lessonResponse: LessonResponse): LessonDto { + return new LessonDto({ + _id: lessonResponse._id, + lessonId: lessonResponse.id, + name: lessonResponse.name, + courseId: lessonResponse.courseId, + courseGroupId: lessonResponse.courseGroupId, + hidden: lessonResponse.hidden, + position: lessonResponse.position, + contents: lessonResponse.contents.map((content) => this.mapToLessenContentDto(content)), + materials: lessonResponse.materials.map((material) => this.mapToLessonMaterialDto(material)), + }); + } + + private static mapToLessonMaterialDto(materialResponse: MaterialResponse): LessonMaterialsDto { + return new LessonMaterialsDto({ + _id: materialResponse._id, + materialsId: materialResponse.id, + title: materialResponse.title, + relatedResources: materialResponse.relatedResources.map((resource) => resource), + url: materialResponse.url, + client: materialResponse.client, + license: materialResponse.license, + merlinReference: materialResponse.merlinReference, + }); + } + + private static mapToLessenContentDto(lessonContentResponse: LessonContentResponse) { + return new LessonContentDto({ + content: lessonContentResponse.content, + _id: lessonContentResponse._id, + contentId: lessonContentResponse.id, + title: lessonContentResponse.title, + component: lessonContentResponse.component, + hidden: lessonContentResponse.hidden, + }); + } +} From 5864c3a7144724ba8ed93f59af5f0980197207ac Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Thu, 17 Oct 2024 14:03:56 +0200 Subject: [PATCH 05/16] remove unused Dto --- .../dto/lesson-meta-data-list.dto.ts | 18 ------------------ .../lesson-client/dto/lesson-meta-data.dto.ts | 10 ---------- 2 files changed, 28 deletions(-) delete mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data-list.dto.ts delete mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data.dto.ts diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data-list.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data-list.dto.ts deleted file mode 100644 index a32563e969f..00000000000 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data-list.dto.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { LessonMetaDataDto } from './lesson-meta-data.dto'; - -export class LessonMetaDataListDto { - data: Array; - - total: number; - - skip: number; - - limit: number; - - constructor(props: LessonMetaDataListDto) { - this.data = props.data; - this.total = props.total; - this.skip = props.skip; - this.limit = props.limit; - } -} diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data.dto.ts deleted file mode 100644 index b614c2dce14..00000000000 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-meta-data.dto.ts +++ /dev/null @@ -1,10 +0,0 @@ -export class LessonMetaDataDto { - _id: string; - - name: string; - - constructor(props: LessonMetaDataDto) { - this._id = props._id; - this.name = props.name; - } -} From 03726eeec63c34a381b804ae424f1d4cb9c733c0 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Thu, 17 Oct 2024 14:19:15 +0200 Subject: [PATCH 06/16] clean implementation --- .../common-cartridge-client/lesson-client/dto/index.ts | 2 -- .../lesson-client/lesson-client.config.ts | 2 +- .../{lessons-client.module.ts => lesson-client.module.ts} | 8 ++++---- .../lesson-client/mapper/lesson-dto.mapper.ts | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) rename apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/{lessons-client.module.ts => lesson-client.module.ts} (71%) diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/index.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/index.ts index 11609ff5890..08e0eea5cf6 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/index.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/index.ts @@ -2,5 +2,3 @@ export * from './lesson.dto'; export * from './lesson-materials.dto'; export * from './lesson-contents.dto'; export * from './lesson-linked-task.dto'; -export * from './lesson-meta-data.dto'; -export * from './lesson-meta-data-list.dto'; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.config.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.config.ts index 48cabd48e58..2ffb2218be3 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.config.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.config.ts @@ -1,5 +1,5 @@ import { ConfigurationParameters } from './lessons-api-client'; -export interface LessonsClientConfig extends ConfigurationParameters { +export interface LessonClientConfig extends ConfigurationParameters { basePath: string; } diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-client.module.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.ts similarity index 71% rename from apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-client.module.ts rename to apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.ts index e04fbf1ffb7..08fdac95d4e 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lessons-client.module.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.ts @@ -1,11 +1,11 @@ import { DynamicModule, Module } from '@nestjs/common'; -import { LessonsClientConfig } from './lesson-client.config'; +import { LessonClientConfig } from './lesson-client.config'; import { LessonClientAdapter } from './lesson-client.adapter'; import { LessonApi, Configuration } from './lessons-api-client'; @Module({}) -export class LessonsClientModule { - static register(config: LessonsClientConfig): DynamicModule { +export class LessonClientModule { + static register(config: LessonClientConfig): DynamicModule { const providers = [ LessonClientAdapter, { @@ -18,7 +18,7 @@ export class LessonsClientModule { ]; return { - module: LessonsClientModule, + module: LessonClientModule, providers, exports: [LessonClientAdapter], }; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts index 700fd1084dd..5d1ffdfc444 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts @@ -7,7 +7,7 @@ import { } from '../lessons-api-client'; export class LessonDtoMapper { - static mapToLessonLinkedTaskDto(task: LessonLinkedTaskResponse): LessonLinkedTaskDto { + public static mapToLessonLinkedTaskDto(task: LessonLinkedTaskResponse): LessonLinkedTaskDto { return new LessonLinkedTaskDto({ name: task.name, description: task.description, From 8ed739b7eaf85a2af8bb4fb8be971d5d6b539030 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Fri, 18 Oct 2024 12:02:24 +0200 Subject: [PATCH 07/16] modified lessen content --- .../controller/dto/lesson-content.response.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/lesson/controller/dto/lesson-content.response.ts b/apps/server/src/modules/lesson/controller/dto/lesson-content.response.ts index 0af0d4006ba..a2134608f33 100644 --- a/apps/server/src/modules/lesson/controller/dto/lesson-content.response.ts +++ b/apps/server/src/modules/lesson/controller/dto/lesson-content.response.ts @@ -1,4 +1,4 @@ -import { ApiProperty } from '@nestjs/swagger'; +import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger'; import { EntityId } from '@shared/domain/types'; import { ComponentEtherpadProperties, @@ -11,6 +11,14 @@ import { ComponentType, } from '@shared/domain/entity/lesson.entity'; +@ApiExtraModels( + ComponentTextProperties, + ComponentEtherpadProperties, + ComponentGeogebraProperties, + ComponentInternalProperties, + ComponentLernstoreProperties, + ComponentNexboardProperties +) export class LessonContentResponse { constructor(lessonContent: ComponentProperties) { this.id = lessonContent._id; @@ -22,7 +30,17 @@ export class LessonContentResponse { this.content = lessonContent.content; } - @ApiProperty() + @ApiProperty({ + description: '', + oneOf: [ + { $ref: getSchemaPath(ComponentTextProperties) }, + { $ref: getSchemaPath(ComponentEtherpadProperties) }, + { $ref: getSchemaPath(ComponentGeogebraProperties) }, + { $ref: getSchemaPath(ComponentInternalProperties) }, + { $ref: getSchemaPath(ComponentLernstoreProperties) }, + { $ref: getSchemaPath(ComponentNexboardProperties) }, + ], + }) content?: | ComponentTextProperties | ComponentEtherpadProperties From ce96af9df1e0a70bde1e7f490146f0bbd3e13f52 Mon Sep 17 00:00:00 2001 From: Firas Shmit Date: Fri, 18 Oct 2024 12:27:49 +0200 Subject: [PATCH 08/16] EW-1008 trying to map lesson content --- .../lesson-client/dto/lesson-contents.dto.ts | 3 --- .../lesson-client/mapper/lesson-dto.mapper.ts | 3 +-- .../controller/dto/lesson-content.response.ts | 22 ++----------------- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts index df49916130e..19cd092e72d 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts @@ -1,8 +1,6 @@ export class LessonContentDto { content: object; - _id: string; - contentId: string; title: string; @@ -13,7 +11,6 @@ export class LessonContentDto { constructor(props: LessonContentDto) { this.content = props.content; - this._id = props._id; this.contentId = props.contentId; this.title = props.title; this.component = props.component; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts index 5d1ffdfc444..75a04b73c77 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts @@ -53,8 +53,7 @@ export class LessonDtoMapper { private static mapToLessenContentDto(lessonContentResponse: LessonContentResponse) { return new LessonContentDto({ - content: lessonContentResponse.content, - _id: lessonContentResponse._id, + content: { ...lessonContentResponse.content }, contentId: lessonContentResponse.id, title: lessonContentResponse.title, component: lessonContentResponse.component, diff --git a/apps/server/src/modules/lesson/controller/dto/lesson-content.response.ts b/apps/server/src/modules/lesson/controller/dto/lesson-content.response.ts index a2134608f33..0af0d4006ba 100644 --- a/apps/server/src/modules/lesson/controller/dto/lesson-content.response.ts +++ b/apps/server/src/modules/lesson/controller/dto/lesson-content.response.ts @@ -1,4 +1,4 @@ -import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger'; +import { ApiProperty } from '@nestjs/swagger'; import { EntityId } from '@shared/domain/types'; import { ComponentEtherpadProperties, @@ -11,14 +11,6 @@ import { ComponentType, } from '@shared/domain/entity/lesson.entity'; -@ApiExtraModels( - ComponentTextProperties, - ComponentEtherpadProperties, - ComponentGeogebraProperties, - ComponentInternalProperties, - ComponentLernstoreProperties, - ComponentNexboardProperties -) export class LessonContentResponse { constructor(lessonContent: ComponentProperties) { this.id = lessonContent._id; @@ -30,17 +22,7 @@ export class LessonContentResponse { this.content = lessonContent.content; } - @ApiProperty({ - description: '', - oneOf: [ - { $ref: getSchemaPath(ComponentTextProperties) }, - { $ref: getSchemaPath(ComponentEtherpadProperties) }, - { $ref: getSchemaPath(ComponentGeogebraProperties) }, - { $ref: getSchemaPath(ComponentInternalProperties) }, - { $ref: getSchemaPath(ComponentLernstoreProperties) }, - { $ref: getSchemaPath(ComponentNexboardProperties) }, - ], - }) + @ApiProperty() content?: | ComponentTextProperties | ComponentEtherpadProperties From baa4e67fd57913a38c96b24d19d13a7717e3571b Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Fri, 18 Oct 2024 12:52:21 +0200 Subject: [PATCH 09/16] remove unused deprecated _id --- .../lesson-client/dto/lesson-contents.dto.ts | 3 --- .../lesson-client/dto/lesson-materials.dto.ts | 3 --- .../common-cartridge-client/lesson-client/dto/lesson.dto.ts | 3 --- .../lesson-client/mapper/lesson-dto.mapper.ts | 3 --- .../src/modules/common-cartridge/common-cartridge.module.ts | 4 ++++ 5 files changed, 4 insertions(+), 12 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts index df49916130e..19cd092e72d 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts @@ -1,8 +1,6 @@ export class LessonContentDto { content: object; - _id: string; - contentId: string; title: string; @@ -13,7 +11,6 @@ export class LessonContentDto { constructor(props: LessonContentDto) { this.content = props.content; - this._id = props._id; this.contentId = props.contentId; this.title = props.title; this.component = props.component; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-materials.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-materials.dto.ts index 90845e646ed..daec368ce49 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-materials.dto.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-materials.dto.ts @@ -1,6 +1,4 @@ export class LessonMaterialsDto { - _id: string; - materialsId: string; title: string; @@ -16,7 +14,6 @@ export class LessonMaterialsDto { merlinReference: string; constructor(props: LessonMaterialsDto) { - this._id = props._id; this.materialsId = props.materialsId; this.title = props.title; this.relatedResources = props.relatedResources; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson.dto.ts index aba4739bf6f..864b6502f19 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson.dto.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson.dto.ts @@ -2,8 +2,6 @@ import { LessonContentDto } from './lesson-contents.dto'; import { LessonMaterialsDto } from './lesson-materials.dto'; export class LessonDto { - _id: string; - lessonId: string; name: string; @@ -21,7 +19,6 @@ export class LessonDto { materials: LessonMaterialsDto[]; constructor(props: LessonDto) { - this._id = props._id; this.lessonId = props.lessonId; this.name = props.name; this.courseId = props.courseId; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts index 5d1ffdfc444..25b5fd7cfef 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts @@ -26,7 +26,6 @@ export class LessonDtoMapper { public static mapToLessonDto(lessonResponse: LessonResponse): LessonDto { return new LessonDto({ - _id: lessonResponse._id, lessonId: lessonResponse.id, name: lessonResponse.name, courseId: lessonResponse.courseId, @@ -40,7 +39,6 @@ export class LessonDtoMapper { private static mapToLessonMaterialDto(materialResponse: MaterialResponse): LessonMaterialsDto { return new LessonMaterialsDto({ - _id: materialResponse._id, materialsId: materialResponse.id, title: materialResponse.title, relatedResources: materialResponse.relatedResources.map((resource) => resource), @@ -54,7 +52,6 @@ export class LessonDtoMapper { private static mapToLessenContentDto(lessonContentResponse: LessonContentResponse) { return new LessonContentDto({ content: lessonContentResponse.content, - _id: lessonContentResponse._id, contentId: lessonContentResponse.id, title: lessonContentResponse.title, component: lessonContentResponse.component, diff --git a/apps/server/src/modules/common-cartridge/common-cartridge.module.ts b/apps/server/src/modules/common-cartridge/common-cartridge.module.ts index 9f54ce75802..c89eb5d24f2 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge.module.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge.module.ts @@ -11,6 +11,7 @@ import { CoursesClientModule } from './common-cartridge-client/course-client'; import { CommonCartridgeExportService } from './service/common-cartridge-export.service'; import { CommonCartridgeUc } from './uc/common-cartridge.uc'; import { CourseRoomsModule } from './common-cartridge-client/room-client'; +import { LessonClientModule } from './common-cartridge-client/lesson-client/lesson-client.module'; @Module({ imports: [ @@ -33,6 +34,9 @@ import { CourseRoomsModule } from './common-cartridge-client/room-client'; CourseRoomsModule.register({ basePath: `${Configuration.get('API_HOST') as string}/v3/`, }), + LessonClientModule.register({ + basePath: `${Configuration.get('API_HOST') as string}/v3/`, + }), ], providers: [CommonCartridgeUc, CommonCartridgeExportService], exports: [CommonCartridgeUc], From 4dd622624040d9452a56f1e6142015c920352734 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Fri, 18 Oct 2024 12:54:54 +0200 Subject: [PATCH 10/16] create testing endpoints --- .../controller/common-cartridge.controller.ts | 11 +++++++++++ .../service/common-cartridge-export.service.ts | 16 +++++++++++++++- .../common-cartridge/uc/common-cartridge.uc.ts | 13 +++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/apps/server/src/modules/common-cartridge/controller/common-cartridge.controller.ts b/apps/server/src/modules/common-cartridge/controller/common-cartridge.controller.ts index bd609c4ff88..da6a59f1a0d 100644 --- a/apps/server/src/modules/common-cartridge/controller/common-cartridge.controller.ts +++ b/apps/server/src/modules/common-cartridge/controller/common-cartridge.controller.ts @@ -3,6 +3,7 @@ import { ApiTags } from '@nestjs/swagger'; import { CommonCartridgeUc } from '../uc/common-cartridge.uc'; import { ExportCourseParams } from './dto'; import { CourseExportBodyResponse } from './dto/course-export-body.response'; +import { LessonDto, LessonLinkedTaskDto } from '../common-cartridge-client/lesson-client/dto'; @ApiTags('common-cartridge') @Controller('common-cartridge') @@ -13,4 +14,14 @@ export class CommonCartridgeController { public async exportCourse(@Param() exportCourseParams: ExportCourseParams): Promise { return this.commonCartridgeUC.exportCourse(exportCourseParams.parentId); } + + @Get('export/lesson/:parentId') + public async exportLesson(@Param() exportCourseParams: ExportCourseParams): Promise { + return this.commonCartridgeUC.exportLesson(exportCourseParams.parentId); + } + + @Get('export/lessontasks/:parentId') + public async exportLessonTasks(@Param() exportCourseParams: ExportCourseParams): Promise { + return this.commonCartridgeUC.exportLessonTasks(exportCourseParams.parentId); + } } diff --git a/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.ts b/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.ts index 9d358dba255..33ee5e918e6 100644 --- a/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.ts @@ -4,6 +4,7 @@ import { BoardClientAdapter } from '../common-cartridge-client/board-client'; import { CourseCommonCartridgeMetadataDto, CoursesClientAdapter } from '../common-cartridge-client/course-client'; import { CourseRoomsClientAdapter } from '../common-cartridge-client/room-client'; import { RoomBoardDto } from '../common-cartridge-client/room-client/dto/room-board.dto'; +import { LessonClientAdapter } from '../common-cartridge-client/lesson-client/lesson-client.adapter'; @Injectable() export class CommonCartridgeExportService { @@ -11,7 +12,8 @@ export class CommonCartridgeExportService { private readonly filesService: FilesStorageClientAdapterService, private readonly boardClientAdapter: BoardClientAdapter, private readonly coursesClientAdapter: CoursesClientAdapter, - private readonly courseRoomsClientAdapter: CourseRoomsClientAdapter + private readonly courseRoomsClientAdapter: CourseRoomsClientAdapter, + private readonly lessonClientAdapter: LessonClientAdapter ) {} public async findCourseFileRecords(courseId: string): Promise { @@ -31,4 +33,16 @@ export class CommonCartridgeExportService { return courseRooms; } + + public async getLessonById(lessonId: string) { + const lesson = await this.lessonClientAdapter.getLessonById(lessonId); + + return lesson; + } + + public async getLessonTasks(lessonId: string) { + const lessonTasks = await this.lessonClientAdapter.getLessonTasks(lessonId); + + return lessonTasks; + } } diff --git a/apps/server/src/modules/common-cartridge/uc/common-cartridge.uc.ts b/apps/server/src/modules/common-cartridge/uc/common-cartridge.uc.ts index 8caa9381633..af8bf4af2e3 100644 --- a/apps/server/src/modules/common-cartridge/uc/common-cartridge.uc.ts +++ b/apps/server/src/modules/common-cartridge/uc/common-cartridge.uc.ts @@ -4,6 +4,7 @@ import { CourseFileIdsResponse } from '../controller/dto'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; import { CourseExportBodyResponse } from '../controller/dto/course-export-body.response'; import { CourseCommonCartridgeMetadataDto } from '../common-cartridge-client/course-client'; +import { LessonDto, LessonLinkedTaskDto } from '../common-cartridge-client/lesson-client/dto'; @Injectable() export class CommonCartridgeUc { @@ -22,4 +23,16 @@ export class CommonCartridgeUc { return response; } + + public async exportLesson(lessonId: string): Promise { + const lesson = await this.exportService.getLessonById(lessonId); + + return lesson; + } + + public async exportLessonTasks(lessonId: string): Promise { + const lessonLinkedTasks = await this.exportService.getLessonTasks(lessonId); + + return lessonLinkedTasks; + } } From 51e95862e5386a03f86f71afa23f6e65e5ef181a Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Fri, 18 Oct 2024 16:05:55 +0200 Subject: [PATCH 11/16] remove unused attribute --- .../lesson-client/dto/lesson-contents.dto.ts | 2 -- .../lesson-client/mapper/lesson-dto.mapper.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts index 19cd092e72d..6d093c2a4b4 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts @@ -1,7 +1,6 @@ export class LessonContentDto { content: object; - contentId: string; title: string; @@ -11,7 +10,6 @@ export class LessonContentDto { constructor(props: LessonContentDto) { this.content = props.content; - this.contentId = props.contentId; this.title = props.title; this.component = props.component; this.hidden = props.hidden; diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts index 25b5fd7cfef..39db5271899 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts @@ -52,7 +52,6 @@ export class LessonDtoMapper { private static mapToLessenContentDto(lessonContentResponse: LessonContentResponse) { return new LessonContentDto({ content: lessonContentResponse.content, - contentId: lessonContentResponse.id, title: lessonContentResponse.title, component: lessonContentResponse.component, hidden: lessonContentResponse.hidden, From b059b70bd103957909be3c844324ef39e45eb5a2 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Fri, 18 Oct 2024 16:07:13 +0200 Subject: [PATCH 12/16] typo --- .../lesson-client/dto/lesson-contents.dto.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts index 6d093c2a4b4..e9f00a471d4 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/dto/lesson-contents.dto.ts @@ -1,7 +1,6 @@ export class LessonContentDto { content: object; - title: string; component: LessonContentDtoComponent; From e076ff88ff4678c667a426ed39b4f64728ec20d1 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Wed, 23 Oct 2024 13:49:29 +0200 Subject: [PATCH 13/16] add tests --- .../lesson-client.adapter.spec.ts | 206 ++++++++++++++++++ .../lesson-client.module.spec.ts | 28 +++ .../mapper/lesson-dto.mapper.spec.ts | 126 +++++++++++ 3 files changed, 360 insertions(+) create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.spec.ts diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts new file mode 100644 index 00000000000..3b054291db4 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts @@ -0,0 +1,206 @@ +import { faker } from '@faker-js/faker'; +import { createMock, DeepMocked } from '@golevelup/ts-jest'; +import { UnauthorizedException } from '@nestjs/common'; +import { REQUEST } from '@nestjs/core'; +import { Test, TestingModule } from '@nestjs/testing'; +import { AxiosResponse } from 'axios'; +import { Request } from 'express'; +import { LessonClientAdapter } from './lesson-client.adapter'; +import { LessonApi, LessonLinkedTaskResponse, LessonResponse } from './lessons-api-client'; + +const jwtToken = 'someJwtToken'; + +describe(LessonClientAdapter.name, () => { + let module: TestingModule; + let sut: LessonClientAdapter; + let lessonApiMock: DeepMocked; + + beforeAll(async () => { + module = await Test.createTestingModule({ + providers: [ + LessonClientAdapter, + { + provide: LessonApi, + useValue: createMock(), + }, + { + provide: REQUEST, + useValue: createMock({ + headers: { + authorization: `Bearer ${jwtToken}`, + }, + }), + }, + ], + }).compile(); + + sut = module.get(LessonClientAdapter); + lessonApiMock = module.get(LessonApi); + }); + + afterAll(async () => { + await module.close(); + }); + + afterEach(() => { + jest.resetAllMocks(); + }); + + it('should be defined', () => { + expect(sut).toBeDefined(); + }); + + describe('getLessonById', () => { + describe('When getLessonById is called', () => { + const setup = () => { + const response = createMock>({ + data: { + _id: faker.string.uuid(), + id: faker.string.uuid(), + name: faker.lorem.sentence(), + courseId: faker.string.uuid(), + courseGroupId: faker.string.uuid(), + hidden: faker.datatype.boolean(), + position: faker.number.int(), + contents: [ + { + content: { text: faker.lorem.sentence() }, + _id: faker.string.uuid(), + id: faker.string.uuid(), + title: faker.lorem.sentence(), + component: faker.helpers.arrayElement(['Etherpad', 'geoGebra', 'neXboard']), + hidden: faker.datatype.boolean(), + }, + ], + materials: [ + { + _id: faker.string.uuid(), + id: faker.string.uuid(), + title: faker.lorem.sentence(), + relatedResources: [faker.lorem.sentence()], + url: faker.internet.url(), + client: faker.lorem.sentence(), + license: [faker.lorem.sentence()], + merlinReference: faker.lorem.sentence(), + }, + ], + }, + }); + + lessonApiMock.lessonControllerGetLesson.mockResolvedValue(response); + + return { lessonId: response.data.id }; + }; + it('should call lessonControllerGetLesson', async () => { + const { lessonId } = setup(); + + await sut.getLessonById(lessonId); + + expect(lessonApiMock.lessonControllerGetLesson).toHaveBeenCalled(); + }); + }); + + describe('When getLessonById is called with invalid id', () => { + const setup = () => { + const lessonResponseId = faker.string.uuid(); + + return { lessonResponseId }; + }; + it('should throw an error', async () => { + const { lessonResponseId } = setup(); + + lessonApiMock.lessonControllerGetLesson.mockRejectedValueOnce(new Error('error')); + + const result = sut.getLessonById(lessonResponseId); + + await expect(result).rejects.toThrowError('error'); + }); + }); + + describe('When no JWT token is found', () => { + const setup = () => { + const lessonResponseId = faker.string.uuid(); + const request = createMock({ + headers: {}, + }) as Request; + + const adapter: LessonClientAdapter = new LessonClientAdapter(lessonApiMock, request); + + return { lessonResponseId, adapter }; + }; + it('should throw an UnauthorizedError', async () => { + const { lessonResponseId, adapter } = setup(); + + await expect(adapter.getLessonById(lessonResponseId)).rejects.toThrowError(UnauthorizedException); + }); + }); + }); + + describe('getLessonTasks', () => { + describe('When getLessonTasks is called', () => { + const setup = () => { + const lessonId = faker.string.uuid(); + const response = createMock>({ + data: [ + { + name: faker.lorem.sentence(), + description: faker.lorem.sentence(), + descriptionInputFormat: faker.helpers.arrayElement(['plainText', 'richTextCk4', 'richTextCk5Simple']), + availableDate: faker.date.recent().toString(), + dueDate: faker.date.future().toString(), + private: faker.datatype.boolean(), + publicSubmissions: faker.datatype.boolean(), + teamSubmissions: faker.datatype.boolean(), + }, + ], + }); + + lessonApiMock.lessonControllerGetLessonTasks.mockResolvedValue(response); + + return { lessonId }; + }; + it('should call lessonControllerGetLessonTasks', async () => { + const { lessonId } = setup(); + + await sut.getLessonTasks(lessonId); + + expect(lessonApiMock.lessonControllerGetLessonTasks).toHaveBeenCalled(); + }); + }); + + describe('When getLessonTasks is called with invalid id', () => { + const setup = () => { + const lessonResponseId = faker.string.uuid(); + + return { lessonResponseId }; + }; + it('should throw an error', async () => { + const { lessonResponseId } = setup(); + + lessonApiMock.lessonControllerGetLessonTasks.mockRejectedValueOnce(new Error('error')); + + const result = sut.getLessonTasks(lessonResponseId); + + await expect(result).rejects.toThrowError('error'); + }); + }); + + describe('When no JWT token is found', () => { + const setup = () => { + const lessonResponseId = faker.string.uuid(); + const request = createMock({ + headers: {}, + }) as Request; + + const adapter: LessonClientAdapter = new LessonClientAdapter(lessonApiMock, request); + + return { lessonResponseId, adapter }; + }; + it('should throw an UnauthorizedError', async () => { + const { lessonResponseId, adapter } = setup(); + + await expect(adapter.getLessonTasks(lessonResponseId)).rejects.toThrowError(UnauthorizedException); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.spec.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.spec.ts new file mode 100644 index 00000000000..c513fa5c812 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.spec.ts @@ -0,0 +1,28 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { LessonClientModule } from './lesson-client.module'; +import { LessonClientAdapter } from './lesson-client.adapter'; + +describe('LessonClientModule', () => { + let module: TestingModule; + + beforeAll(async () => { + module = await Test.createTestingModule({ + imports: [ + LessonClientModule.register({ + basePath: 'http://localhost:3030/api/v3', + }), + ], + }).compile(); + }); + + afterAll(async () => { + await module.close(); + }); + + describe('when module is initialized', () => { + it('should have the LessonClientAdapter defined', () => { + const lessonClientAdapter = module.get(LessonClientAdapter); + expect(lessonClientAdapter).toBeDefined(); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.spec.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.spec.ts new file mode 100644 index 00000000000..15a34c5dab8 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.spec.ts @@ -0,0 +1,126 @@ +import { faker } from '@faker-js/faker'; +import { + MaterialResponse, + LessonContentResponse, + LessonResponse, + LessonLinkedTaskResponse, +} from '../lessons-api-client'; +import { LessonDtoMapper } from './lesson-dto.mapper'; + +describe('LessonDtoMapper', () => { + describe('mapToLessonDto', () => { + describe('when mapping to LessonResponse', () => { + const setup = () => { + const materialResponse: MaterialResponse = { + _id: faker.string.uuid(), + id: faker.string.uuid(), + title: faker.lorem.sentence(), + relatedResources: [faker.lorem.sentence()], + url: faker.internet.url(), + client: faker.lorem.sentence(), + license: [faker.lorem.sentence()], + merlinReference: faker.lorem.sentence(), + }; + + const lessonContentResponse: LessonContentResponse = { + content: { text: faker.lorem.sentence() }, + _id: faker.string.uuid(), + id: faker.string.uuid(), + title: faker.lorem.sentence(), + component: faker.helpers.arrayElement(['Etherpad', 'neXboard', 'geoGebra']), + hidden: faker.datatype.boolean(), + }; + + const lessonResponse: LessonResponse = { + _id: faker.string.uuid(), + id: faker.string.uuid(), + name: faker.lorem.sentence(), + courseId: faker.string.uuid(), + courseGroupId: faker.string.uuid(), + hidden: faker.datatype.boolean(), + position: faker.number.int(), + contents: [lessonContentResponse], + materials: [materialResponse], + }; + + return { lessonResponse }; + }; + it('should return LessonDto', () => { + const { lessonResponse } = setup(); + + const result = LessonDtoMapper.mapToLessonDto(lessonResponse); + + expect(result).toEqual({ + lessonId: lessonResponse.id, + name: lessonResponse.name, + courseId: lessonResponse.courseId, + courseGroupId: lessonResponse.courseGroupId, + hidden: lessonResponse.hidden, + position: lessonResponse.position, + contents: [ + { + content: lessonResponse.contents[0].content, + title: lessonResponse.contents[0].title, + component: lessonResponse.contents[0].component, + hidden: lessonResponse.contents[0].hidden, + }, + ], + materials: [ + { + materialsId: lessonResponse.materials[0].id, + title: lessonResponse.materials[0].title, + relatedResources: [lessonResponse.materials[0].relatedResources[0]], + url: lessonResponse.materials[0].url, + client: lessonResponse.materials[0].client, + license: lessonResponse.materials[0].license, + merlinReference: lessonResponse.materials[0].merlinReference, + }, + ], + }); + }); + }); + }); + + describe('mapToLessonLinkedTaskDto', () => { + describe('when mapping to LessonLinkedTaskResponse', () => { + const setup = () => { + const lessonLinkedTaskResponse = { + name: faker.lorem.sentence(), + description: faker.lorem.sentence(), + descriptionInputFormat: faker.lorem.sentence(), + availableDate: faker.date.recent().toString(), + dueDate: faker.date.future().toString(), + private: faker.datatype.boolean(), + publicSubmissions: faker.datatype.boolean(), + teamSubmissions: faker.datatype.boolean(), + creator: faker.internet.email(), + courseId: faker.string.uuid(), + submissionIds: [faker.string.uuid()], + finishedIds: [faker.string.uuid()], + } as LessonLinkedTaskResponse; + + return { lessonLinkedTaskResponse }; + }; + it('should return LessonLinkedTaskDto', () => { + const { lessonLinkedTaskResponse } = setup(); + + const result = LessonDtoMapper.mapToLessonLinkedTaskDto(lessonLinkedTaskResponse); + + expect(result).toEqual({ + name: lessonLinkedTaskResponse.name, + description: lessonLinkedTaskResponse.description, + descriptionInputFormat: lessonLinkedTaskResponse.descriptionInputFormat, + availableDate: lessonLinkedTaskResponse.availableDate, + dueDate: lessonLinkedTaskResponse.dueDate, + private: lessonLinkedTaskResponse.private, + publicSubmissions: lessonLinkedTaskResponse.publicSubmissions, + teamSubmissions: lessonLinkedTaskResponse.teamSubmissions, + creator: lessonLinkedTaskResponse.creator, + courseId: lessonLinkedTaskResponse.courseId, + submissionIds: lessonLinkedTaskResponse.submissionIds, + finishedIds: lessonLinkedTaskResponse.finishedIds, + }); + }); + }); + }); +}); From a7114c096718dee9158641f1bf1a99dc722feab1 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Wed, 23 Oct 2024 14:38:07 +0200 Subject: [PATCH 14/16] resolve test cov --- .../service/common-cartridge-export.service.spec.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.spec.ts index 4a1b4b53066..93eea5852e0 100644 --- a/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.spec.ts @@ -6,6 +6,7 @@ import { BoardClientAdapter } from '../common-cartridge-client/board-client'; import { CommonCartridgeExportService } from './common-cartridge-export.service'; import { CoursesClientAdapter } from '../common-cartridge-client/course-client'; import { CourseRoomsClientAdapter } from '../common-cartridge-client/room-client'; +import { LessonClientAdapter } from '../common-cartridge-client/lesson-client/lesson-client.adapter'; describe('CommonCartridgeExportService', () => { let module: TestingModule; @@ -13,6 +14,9 @@ describe('CommonCartridgeExportService', () => { let filesStorageServiceMock: DeepMocked; let coursesClientAdapterMock: DeepMocked; let courseRoomsClientAdapterMock: DeepMocked; + // TODO: this should be removed after review testing + // eslint-disable-next-line @typescript-eslint/no-unused-vars + let lessonClientAdapterMock: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ @@ -34,6 +38,10 @@ describe('CommonCartridgeExportService', () => { provide: CourseRoomsClientAdapter, useValue: createMock(), }, + { + provide: LessonClientAdapter, + useValue: createMock(), + }, ], }).compile(); @@ -41,6 +49,7 @@ describe('CommonCartridgeExportService', () => { filesStorageServiceMock = module.get(FilesStorageClientAdapterService); coursesClientAdapterMock = module.get(CoursesClientAdapter); courseRoomsClientAdapterMock = module.get(CourseRoomsClientAdapter); + lessonClientAdapterMock = module.get(LessonClientAdapter); }); afterAll(async () => { From edc4beae932e732a9004f6b4038ce947f61f5cd8 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Thu, 24 Oct 2024 15:21:10 +0200 Subject: [PATCH 15/16] resolve review comments --- .../lesson-client/lesson-client.adapter.spec.ts | 16 ++++++++++------ .../lesson-client/lesson-client.adapter.ts | 13 ++++--------- .../lesson-client/lesson-client.module.spec.ts | 1 + .../mapper/lesson-dto.mapper.spec.ts | 9 ++++++--- .../lesson-client/mapper/lesson-dto.mapper.ts | 16 ++++++++++++---- .../common-cartridge/common-cartridge.module.ts | 6 +++--- 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts index 3b054291db4..fb2ca58ff40 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts @@ -8,12 +8,11 @@ import { Request } from 'express'; import { LessonClientAdapter } from './lesson-client.adapter'; import { LessonApi, LessonLinkedTaskResponse, LessonResponse } from './lessons-api-client'; -const jwtToken = 'someJwtToken'; - describe(LessonClientAdapter.name, () => { let module: TestingModule; let sut: LessonClientAdapter; let lessonApiMock: DeepMocked; + const jwtToken = faker.string.alphanumeric(20); beforeAll(async () => { module = await Test.createTestingModule({ @@ -91,6 +90,7 @@ describe(LessonClientAdapter.name, () => { return { lessonId: response.data.id }; }; + it('should call lessonControllerGetLesson', async () => { const { lessonId } = setup(); @@ -104,13 +104,14 @@ describe(LessonClientAdapter.name, () => { const setup = () => { const lessonResponseId = faker.string.uuid(); + lessonApiMock.lessonControllerGetLesson.mockRejectedValueOnce(new Error('error')); + return { lessonResponseId }; }; + it('should throw an error', async () => { const { lessonResponseId } = setup(); - lessonApiMock.lessonControllerGetLesson.mockRejectedValueOnce(new Error('error')); - const result = sut.getLessonById(lessonResponseId); await expect(result).rejects.toThrowError('error'); @@ -128,6 +129,7 @@ describe(LessonClientAdapter.name, () => { return { lessonResponseId, adapter }; }; + it('should throw an UnauthorizedError', async () => { const { lessonResponseId, adapter } = setup(); @@ -159,6 +161,7 @@ describe(LessonClientAdapter.name, () => { return { lessonId }; }; + it('should call lessonControllerGetLessonTasks', async () => { const { lessonId } = setup(); @@ -172,13 +175,13 @@ describe(LessonClientAdapter.name, () => { const setup = () => { const lessonResponseId = faker.string.uuid(); + lessonApiMock.lessonControllerGetLessonTasks.mockRejectedValueOnce(new Error('error')); + return { lessonResponseId }; }; it('should throw an error', async () => { const { lessonResponseId } = setup(); - lessonApiMock.lessonControllerGetLessonTasks.mockRejectedValueOnce(new Error('error')); - const result = sut.getLessonTasks(lessonResponseId); await expect(result).rejects.toThrowError('error'); @@ -196,6 +199,7 @@ describe(LessonClientAdapter.name, () => { return { lessonResponseId, adapter }; }; + it('should throw an UnauthorizedError', async () => { const { lessonResponseId, adapter } = setup(); diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.ts index 1f215baa312..22e8abf7eec 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.ts @@ -13,22 +13,17 @@ export class LessonClientAdapter { public async getLessonById(lessonId: string): Promise { const options = this.createOptionParams(); - const lessonResponse = await this.lessonApi - .lessonControllerGetLesson(lessonId, options) - .then((response) => response.data); - - const lessonDto = LessonDtoMapper.mapToLessonDto(lessonResponse); + const response = await this.lessonApi.lessonControllerGetLesson(lessonId, options); + const lessonDto = LessonDtoMapper.mapToLessonDto(response.data); return lessonDto; } public async getLessonTasks(lessonId: string): Promise { const options = this.createOptionParams(); - const lessonTasksResponse = await this.lessonApi - .lessonControllerGetLessonTasks(lessonId, options) - .then((response) => response.data); + const response = await this.lessonApi.lessonControllerGetLessonTasks(lessonId, options); - const lessonTasksDtoList = lessonTasksResponse.map((task) => LessonDtoMapper.mapToLessonLinkedTaskDto(task)); + const lessonTasksDtoList = response.data.map((task) => LessonDtoMapper.mapToLessonLinkedTaskDto(task)); return lessonTasksDtoList; } diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.spec.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.spec.ts index c513fa5c812..4761ca36add 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.spec.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.module.spec.ts @@ -22,6 +22,7 @@ describe('LessonClientModule', () => { describe('when module is initialized', () => { it('should have the LessonClientAdapter defined', () => { const lessonClientAdapter = module.get(LessonClientAdapter); + expect(lessonClientAdapter).toBeDefined(); }); }); diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.spec.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.spec.ts index 15a34c5dab8..3b294527520 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.spec.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.spec.ts @@ -4,6 +4,7 @@ import { LessonContentResponse, LessonResponse, LessonLinkedTaskResponse, + LessonLinkedTaskResponseDescriptionInputFormat, } from '../lessons-api-client'; import { LessonDtoMapper } from './lesson-dto.mapper'; @@ -45,6 +46,7 @@ describe('LessonDtoMapper', () => { return { lessonResponse }; }; + it('should return LessonDto', () => { const { lessonResponse } = setup(); @@ -84,10 +86,10 @@ describe('LessonDtoMapper', () => { describe('mapToLessonLinkedTaskDto', () => { describe('when mapping to LessonLinkedTaskResponse', () => { const setup = () => { - const lessonLinkedTaskResponse = { + const lessonLinkedTaskResponse: LessonLinkedTaskResponse = { name: faker.lorem.sentence(), description: faker.lorem.sentence(), - descriptionInputFormat: faker.lorem.sentence(), + descriptionInputFormat: LessonLinkedTaskResponseDescriptionInputFormat.PLAIN_TEXT, availableDate: faker.date.recent().toString(), dueDate: faker.date.future().toString(), private: faker.datatype.boolean(), @@ -97,10 +99,11 @@ describe('LessonDtoMapper', () => { courseId: faker.string.uuid(), submissionIds: [faker.string.uuid()], finishedIds: [faker.string.uuid()], - } as LessonLinkedTaskResponse; + }; return { lessonLinkedTaskResponse }; }; + it('should return LessonLinkedTaskDto', () => { const { lessonLinkedTaskResponse } = setup(); diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts index 39db5271899..d20cf4ec1fe 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts @@ -8,7 +8,7 @@ import { export class LessonDtoMapper { public static mapToLessonLinkedTaskDto(task: LessonLinkedTaskResponse): LessonLinkedTaskDto { - return new LessonLinkedTaskDto({ + const lessonLinkedTaskDto = new LessonLinkedTaskDto({ name: task.name, description: task.description, descriptionInputFormat: task.descriptionInputFormat, @@ -22,10 +22,12 @@ export class LessonDtoMapper { submissionIds: task.submissionIds, finishedIds: task.finishedIds, }); + + return lessonLinkedTaskDto; } public static mapToLessonDto(lessonResponse: LessonResponse): LessonDto { - return new LessonDto({ + const lessonDto = new LessonDto({ lessonId: lessonResponse.id, name: lessonResponse.name, courseId: lessonResponse.courseId, @@ -35,10 +37,12 @@ export class LessonDtoMapper { contents: lessonResponse.contents.map((content) => this.mapToLessenContentDto(content)), materials: lessonResponse.materials.map((material) => this.mapToLessonMaterialDto(material)), }); + + return lessonDto; } private static mapToLessonMaterialDto(materialResponse: MaterialResponse): LessonMaterialsDto { - return new LessonMaterialsDto({ + const lessonMaterialsDto = new LessonMaterialsDto({ materialsId: materialResponse.id, title: materialResponse.title, relatedResources: materialResponse.relatedResources.map((resource) => resource), @@ -47,14 +51,18 @@ export class LessonDtoMapper { license: materialResponse.license, merlinReference: materialResponse.merlinReference, }); + + return lessonMaterialsDto; } private static mapToLessenContentDto(lessonContentResponse: LessonContentResponse) { - return new LessonContentDto({ + const lessonContentDto = new LessonContentDto({ content: lessonContentResponse.content, title: lessonContentResponse.title, component: lessonContentResponse.component, hidden: lessonContentResponse.hidden, }); + + return lessonContentDto; } } diff --git a/apps/server/src/modules/common-cartridge/common-cartridge.module.ts b/apps/server/src/modules/common-cartridge/common-cartridge.module.ts index c89eb5d24f2..d281bc8af88 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge.module.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge.module.ts @@ -16,9 +16,6 @@ import { LessonClientModule } from './common-cartridge-client/lesson-client/less @Module({ imports: [ RabbitMQWrapperModule, - CoursesClientModule.register({ - basePath: `${Configuration.get('API_HOST') as string}/v3/`, - }), FilesStorageClientModule, MikroOrmModule.forRoot({ ...defaultMikroOrmOptions, @@ -34,6 +31,9 @@ import { LessonClientModule } from './common-cartridge-client/lesson-client/less CourseRoomsModule.register({ basePath: `${Configuration.get('API_HOST') as string}/v3/`, }), + CoursesClientModule.register({ + basePath: `${Configuration.get('API_HOST') as string}/v3/`, + }), LessonClientModule.register({ basePath: `${Configuration.get('API_HOST') as string}/v3/`, }), From d22e46f60c1b856e39eca7ace665ec302b7d744c Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Fri, 25 Oct 2024 09:59:17 +0200 Subject: [PATCH 16/16] remove test methods --- .../lesson-client/lesson-client.adapter.spec.ts | 1 + .../lesson-client/mapper/lesson-dto.mapper.ts | 2 +- .../controller/common-cartridge.controller.ts | 11 ----------- .../common-cartridge-export.service.spec.ts | 9 --------- .../service/common-cartridge-export.service.ts | 16 +--------------- .../common-cartridge/uc/common-cartridge.uc.ts | 13 ------------- 6 files changed, 3 insertions(+), 49 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts index fb2ca58ff40..fef7a941220 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/lesson-client.adapter.spec.ts @@ -179,6 +179,7 @@ describe(LessonClientAdapter.name, () => { return { lessonResponseId }; }; + it('should throw an error', async () => { const { lessonResponseId } = setup(); diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts index d20cf4ec1fe..150037ddaee 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/lesson-client/mapper/lesson-dto.mapper.ts @@ -55,7 +55,7 @@ export class LessonDtoMapper { return lessonMaterialsDto; } - private static mapToLessenContentDto(lessonContentResponse: LessonContentResponse) { + private static mapToLessenContentDto(lessonContentResponse: LessonContentResponse): LessonContentDto { const lessonContentDto = new LessonContentDto({ content: lessonContentResponse.content, title: lessonContentResponse.title, diff --git a/apps/server/src/modules/common-cartridge/controller/common-cartridge.controller.ts b/apps/server/src/modules/common-cartridge/controller/common-cartridge.controller.ts index da6a59f1a0d..bd609c4ff88 100644 --- a/apps/server/src/modules/common-cartridge/controller/common-cartridge.controller.ts +++ b/apps/server/src/modules/common-cartridge/controller/common-cartridge.controller.ts @@ -3,7 +3,6 @@ import { ApiTags } from '@nestjs/swagger'; import { CommonCartridgeUc } from '../uc/common-cartridge.uc'; import { ExportCourseParams } from './dto'; import { CourseExportBodyResponse } from './dto/course-export-body.response'; -import { LessonDto, LessonLinkedTaskDto } from '../common-cartridge-client/lesson-client/dto'; @ApiTags('common-cartridge') @Controller('common-cartridge') @@ -14,14 +13,4 @@ export class CommonCartridgeController { public async exportCourse(@Param() exportCourseParams: ExportCourseParams): Promise { return this.commonCartridgeUC.exportCourse(exportCourseParams.parentId); } - - @Get('export/lesson/:parentId') - public async exportLesson(@Param() exportCourseParams: ExportCourseParams): Promise { - return this.commonCartridgeUC.exportLesson(exportCourseParams.parentId); - } - - @Get('export/lessontasks/:parentId') - public async exportLessonTasks(@Param() exportCourseParams: ExportCourseParams): Promise { - return this.commonCartridgeUC.exportLessonTasks(exportCourseParams.parentId); - } } diff --git a/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.spec.ts index 93eea5852e0..4a1b4b53066 100644 --- a/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.spec.ts @@ -6,7 +6,6 @@ import { BoardClientAdapter } from '../common-cartridge-client/board-client'; import { CommonCartridgeExportService } from './common-cartridge-export.service'; import { CoursesClientAdapter } from '../common-cartridge-client/course-client'; import { CourseRoomsClientAdapter } from '../common-cartridge-client/room-client'; -import { LessonClientAdapter } from '../common-cartridge-client/lesson-client/lesson-client.adapter'; describe('CommonCartridgeExportService', () => { let module: TestingModule; @@ -14,9 +13,6 @@ describe('CommonCartridgeExportService', () => { let filesStorageServiceMock: DeepMocked; let coursesClientAdapterMock: DeepMocked; let courseRoomsClientAdapterMock: DeepMocked; - // TODO: this should be removed after review testing - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let lessonClientAdapterMock: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ @@ -38,10 +34,6 @@ describe('CommonCartridgeExportService', () => { provide: CourseRoomsClientAdapter, useValue: createMock(), }, - { - provide: LessonClientAdapter, - useValue: createMock(), - }, ], }).compile(); @@ -49,7 +41,6 @@ describe('CommonCartridgeExportService', () => { filesStorageServiceMock = module.get(FilesStorageClientAdapterService); coursesClientAdapterMock = module.get(CoursesClientAdapter); courseRoomsClientAdapterMock = module.get(CourseRoomsClientAdapter); - lessonClientAdapterMock = module.get(LessonClientAdapter); }); afterAll(async () => { diff --git a/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.ts b/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.ts index 33ee5e918e6..9d358dba255 100644 --- a/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/common-cartridge/service/common-cartridge-export.service.ts @@ -4,7 +4,6 @@ import { BoardClientAdapter } from '../common-cartridge-client/board-client'; import { CourseCommonCartridgeMetadataDto, CoursesClientAdapter } from '../common-cartridge-client/course-client'; import { CourseRoomsClientAdapter } from '../common-cartridge-client/room-client'; import { RoomBoardDto } from '../common-cartridge-client/room-client/dto/room-board.dto'; -import { LessonClientAdapter } from '../common-cartridge-client/lesson-client/lesson-client.adapter'; @Injectable() export class CommonCartridgeExportService { @@ -12,8 +11,7 @@ export class CommonCartridgeExportService { private readonly filesService: FilesStorageClientAdapterService, private readonly boardClientAdapter: BoardClientAdapter, private readonly coursesClientAdapter: CoursesClientAdapter, - private readonly courseRoomsClientAdapter: CourseRoomsClientAdapter, - private readonly lessonClientAdapter: LessonClientAdapter + private readonly courseRoomsClientAdapter: CourseRoomsClientAdapter ) {} public async findCourseFileRecords(courseId: string): Promise { @@ -33,16 +31,4 @@ export class CommonCartridgeExportService { return courseRooms; } - - public async getLessonById(lessonId: string) { - const lesson = await this.lessonClientAdapter.getLessonById(lessonId); - - return lesson; - } - - public async getLessonTasks(lessonId: string) { - const lessonTasks = await this.lessonClientAdapter.getLessonTasks(lessonId); - - return lessonTasks; - } } diff --git a/apps/server/src/modules/common-cartridge/uc/common-cartridge.uc.ts b/apps/server/src/modules/common-cartridge/uc/common-cartridge.uc.ts index af8bf4af2e3..8caa9381633 100644 --- a/apps/server/src/modules/common-cartridge/uc/common-cartridge.uc.ts +++ b/apps/server/src/modules/common-cartridge/uc/common-cartridge.uc.ts @@ -4,7 +4,6 @@ import { CourseFileIdsResponse } from '../controller/dto'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; import { CourseExportBodyResponse } from '../controller/dto/course-export-body.response'; import { CourseCommonCartridgeMetadataDto } from '../common-cartridge-client/course-client'; -import { LessonDto, LessonLinkedTaskDto } from '../common-cartridge-client/lesson-client/dto'; @Injectable() export class CommonCartridgeUc { @@ -23,16 +22,4 @@ export class CommonCartridgeUc { return response; } - - public async exportLesson(lessonId: string): Promise { - const lesson = await this.exportService.getLessonById(lessonId); - - return lesson; - } - - public async exportLessonTasks(lessonId: string): Promise { - const lessonLinkedTasks = await this.exportService.getLessonTasks(lessonId); - - return lessonLinkedTasks; - } }