Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EW-1079 Commom Cartridge microservice can create colums in a board #5482

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe(BoardsClientAdapter.name, () => {
layout: 'columns',
columns: [],
isVisible: true,
features: [],
timestamps: {
createdAt: faker.date.recent().toISOString(),
lastUpdatedAt: faker.date.recent().toISOString(),
Expand Down
15 changes: 14 additions & 1 deletion apps/server/src/infra/boards-client/boards-client.adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Injectable } from '@nestjs/common';
import { BoardApi, BoardResponse, CreateBoardBodyParams, CreateBoardResponse } from './generated';
import {
BoardApi,
BoardResponse,
ColumnResponse,
CreateBoardBodyParams,
CreateBoardResponse,
CreateColumnBodyParams,
} from './generated';

@Injectable()
export class BoardsClientAdapter {
Expand All @@ -11,6 +18,12 @@ export class BoardsClientAdapter {
return response.data;
}

public async createBoardColumns(boardId: string, params: CreateColumnBodyParams): Promise<ColumnResponse[]> {
const response = await this.boardApi.boardControllerCreateColumns(boardId, params);

return response.data;
}

public async getBoardSkeletonById(boardId: string): Promise<BoardResponse> {
const response = await this.boardApi.boardControllerGetBoardSkeleton(boardId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ models/card-skeleton-response.ts
models/column-response.ts
models/create-board-body-params.ts
models/create-board-response.ts
models/create-column-body-params.ts
models/index.ts
models/timestamps-response.ts
97 changes: 97 additions & 0 deletions apps/server/src/infra/boards-client/generated/api/board-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ import type { ApiValidationError } from '../models';
// @ts-ignore
import type { BoardResponse } from '../models';
// @ts-ignore
import type { ColumnResponse } from '../models';
// @ts-ignore
import type { CreateBoardBodyParams } from '../models';
// @ts-ignore
import type { CreateBoardResponse } from '../models';
// @ts-ignore
import type { CreateColumnBodyParams } from '../models';
/**
* BoardApi - axios parameter creator
* @export
Expand Down Expand Up @@ -75,6 +79,50 @@ export const BoardApiAxiosParamCreator = function (configuration?: Configuration
options: localVarRequestOptions,
};
},
/**
*
* @summary Create multiple columns on a board.
* @param {string} boardId The id of the board.
* @param {CreateColumnBodyParams} createColumnBodyParams
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
boardControllerCreateColumns: async (boardId: string, createColumnBodyParams: CreateColumnBodyParams, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'boardId' is not null or undefined
assertParamExists('boardControllerCreateColumns', 'boardId', boardId)
// verify required parameter 'createColumnBodyParams' is not null or undefined
assertParamExists('boardControllerCreateColumns', 'createColumnBodyParams', createColumnBodyParams)
const localVarPath = `/boards/{boardId}/columns/bulk`
.replace(`{${"boardId"}}`, encodeURIComponent(String(boardId)));
// 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: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication bearer required
// http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration)



localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(createColumnBodyParams, localVarRequestOptions, configuration)

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Get the skeleton of a a board.
Expand Down Expand Up @@ -136,6 +184,20 @@ export const BoardApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['BoardApi.boardControllerCreateBoard']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary Create multiple columns on a board.
* @param {string} boardId The id of the board.
* @param {CreateColumnBodyParams} createColumnBodyParams
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async boardControllerCreateColumns(boardId: string, createColumnBodyParams: CreateColumnBodyParams, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<ColumnResponse>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.boardControllerCreateColumns(boardId, createColumnBodyParams, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['BoardApi.boardControllerCreateColumns']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary Get the skeleton of a a board.
Expand Down Expand Up @@ -169,6 +231,17 @@ export const BoardApiFactory = function (configuration?: Configuration, basePath
boardControllerCreateBoard(createBoardBodyParams: CreateBoardBodyParams, options?: any): AxiosPromise<CreateBoardResponse> {
return localVarFp.boardControllerCreateBoard(createBoardBodyParams, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Create multiple columns on a board.
* @param {string} boardId The id of the board.
* @param {CreateColumnBodyParams} createColumnBodyParams
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
boardControllerCreateColumns(boardId: string, createColumnBodyParams: CreateColumnBodyParams, options?: any): AxiosPromise<Array<ColumnResponse>> {
return localVarFp.boardControllerCreateColumns(boardId, createColumnBodyParams, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Get the skeleton of a a board.
Expand Down Expand Up @@ -198,6 +271,17 @@ export interface BoardApiInterface {
*/
boardControllerCreateBoard(createBoardBodyParams: CreateBoardBodyParams, options?: RawAxiosRequestConfig): AxiosPromise<CreateBoardResponse>;

/**
*
* @summary Create multiple columns on a board.
* @param {string} boardId The id of the board.
* @param {CreateColumnBodyParams} createColumnBodyParams
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof BoardApiInterface
*/
boardControllerCreateColumns(boardId: string, createColumnBodyParams: CreateColumnBodyParams, options?: RawAxiosRequestConfig): AxiosPromise<Array<ColumnResponse>>;

/**
*
* @summary Get the skeleton of a a board.
Expand Down Expand Up @@ -229,6 +313,19 @@ export class BoardApi extends BaseAPI implements BoardApiInterface {
return BoardApiFp(this.configuration).boardControllerCreateBoard(createBoardBodyParams, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Create multiple columns on a board.
* @param {string} boardId The id of the board.
* @param {CreateColumnBodyParams} createColumnBodyParams
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof BoardApi
*/
public boardControllerCreateColumns(boardId: string, createColumnBodyParams: CreateColumnBodyParams, options?: RawAxiosRequestConfig) {
return BoardApiFp(this.configuration).boardControllerCreateColumns(boardId, createColumnBodyParams, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Get the skeleton of a a board.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/


// May contain unused imports in some cases
// @ts-ignore
import type { BoardFeature } from './board-feature';
// May contain unused imports in some cases
// @ts-ignore
import type { ColumnResponse } from './column-response';
Expand Down Expand Up @@ -62,5 +65,11 @@ export interface BoardResponse {
* @memberof BoardResponse
*/
'layout': string;
/**
*
* @type {Array<BoardFeature>}
* @memberof BoardResponse
*/
'features': Array<BoardFeature>;
}

Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export interface CreateBoardBodyParams {
*/
'parentId': string;
/**
*
* The type of the parent
* @type {BoardParentType}
* @memberof CreateBoardBodyParams
*/
'parentType': BoardParentType;
/**
*
* The layout of the board
* @type {BoardLayout}
* @memberof CreateBoardBodyParams
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* 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 CreateColumnBodyParams
*/
export interface CreateColumnBodyParams {
/**
* The title of the column.
* @type {Array<string>}
* @memberof CreateColumnBodyParams
*/
'titles': Array<string>;
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export * from './card-skeleton-response';
export * from './column-response';
export * from './create-board-body-params';
export * from './create-board-response';
export * from './create-column-body-params';
export * from './timestamps-response';
21 changes: 21 additions & 0 deletions apps/server/src/modules/board/controller/board.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ForbiddenException,
Get,
HttpCode,
HttpStatus,
NotFoundException,
Param,
Patch,
Expand All @@ -22,6 +23,7 @@ import {
ColumnResponse,
CreateBoardBodyParams,
CreateBoardResponse,
CreateColumnBodyParams,
LayoutBodyParams,
UpdateBoardTitleParams,
VisibilityBodyParams,
Expand Down Expand Up @@ -132,6 +134,25 @@ export class BoardController {
return response;
}

@ApiOperation({ summary: 'Create multiple columns on a board.' })
@ApiResponse({ status: 201, type: [ColumnResponse] })
@ApiResponse({ status: 400, type: ApiValidationError })
@ApiResponse({ status: 403, type: ForbiddenException })
@ApiResponse({ status: 404, type: NotFoundException })
@HttpCode(HttpStatus.CREATED)
@Post(':boardId/columns/bulk')
public async createColumns(
@Param() urlParams: BoardUrlParams,
@Body() bodyParams: CreateColumnBodyParams,
@CurrentUser() currentUser: ICurrentUser
): Promise<ColumnResponse[]> {
const columns = await this.boardUc.createColumns(currentUser.userId, urlParams.boardId, bodyParams.titles);

const response = columns.map((column) => ColumnResponseMapper.mapToResponse(column));

return response;
}

@ApiOperation({ summary: 'Create a board copy.' })
@ApiResponse({ status: 201, type: CopyApiResponse })
@ApiResponse({ status: 400, type: ApiValidationError })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export class BoardUrlParams {
required: true,
nullable: false,
})
boardId!: string;
public boardId!: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty } from 'class-validator';

export class CreateColumnBodyParams {
@IsString()
@IsNotEmpty()
@ApiProperty({
description: 'The title of the column.',
type: [String],
required: true,
nullable: false,
})
public titles!: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './rename.body.params';
export * from './update-board-title.body.params';
export * from './visibility.body.params';
export * from './layout.body.params';
export * from './create-column.body.params';
21 changes: 14 additions & 7 deletions apps/server/src/modules/board/domain/board-node.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,38 @@ import { RichTextElement } from './rich-text-element.do';
import { SubmissionContainerElement } from './submission-container-element.do';
import { SubmissionItem } from './submission-item.do';
import { handleNonExhaustiveSwitch } from './type-mapping';
import { AnyContentElement, BoardExternalReference, BoardLayout, BoardNodeProps, ContentElementType } from './types';
import {
AnyContentElement,
BoardExternalReference,
BoardLayout,
BoardNodeProps,
ColumnProps,
ContentElementType,
} from './types';
import { VideoConferenceElement } from './video-conference-element.do';

@Injectable()
export class BoardNodeFactory {
buildColumnBoard(props: { context: BoardExternalReference; title: string; layout: BoardLayout }): ColumnBoard {
public buildColumnBoard(props: { context: BoardExternalReference; title: string; layout: BoardLayout }): ColumnBoard {
const columnBoard = new ColumnBoard({ ...this.getBaseProps(), isVisible: false, ...props });

return columnBoard;
}

buildColumn(): Column {
const column = new Column({ ...this.getBaseProps() });
public buildColumn(props?: Partial<ColumnProps>): Column {
const column = new Column({ ...this.getBaseProps(), ...props });

return column;
}

buildCard(children: AnyContentElement[] = []): Card {
public buildCard(children: AnyContentElement[] = []): Card {
// TODO right way to specify default card height?
const card = new Card({ ...this.getBaseProps(), height: 150, children });

return card;
}

buildContentElement(type: ContentElementType): AnyContentElement {
public buildContentElement(type: ContentElementType): AnyContentElement {
let element!: AnyContentElement;

switch (type) {
Expand Down Expand Up @@ -104,7 +111,7 @@ export class BoardNodeFactory {
return element;
}

buildSubmissionItem(props: { completed: boolean; userId: EntityId }): SubmissionItem {
public buildSubmissionItem(props: { completed: boolean; userId: EntityId }): SubmissionItem {
const submissionItem = new SubmissionItem({ ...this.getBaseProps(), ...props });

return submissionItem;
Expand Down
Loading
Loading