-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ew-1009: proper mapping for all DTOs implemented
- Loading branch information
Showing
5 changed files
with
215 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 194 additions & 6 deletions
200
...dules/common-cartridge/common-cartridge-client/card-client/mapper/card-response.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,205 @@ | ||
import { CardResponse } from '../cards-api-client'; | ||
import { | ||
CardResponse, | ||
CardResponseElementsInner, | ||
VisibilitySettingsResponse, | ||
TimestampsResponse, | ||
DeletedElementResponse, | ||
SubmissionContainerElementResponse, | ||
DrawingElementResponse, | ||
ExternalToolElementResponse, | ||
FileElementResponse, | ||
LinkElementResponse, | ||
RichTextElementResponse, | ||
} from '../cards-api-client'; | ||
import { CardResponseElementsInnerDto } from '../dto/card-response-elements-inner.dto'; | ||
import { CardResponseDto } from '../dto/card-response.dto'; | ||
import { CollaborativeTextEditorElementResponseDto } from '../dto/collaborative-text-editor-element-response.dto'; | ||
import { DeletedElementResponseDto } from '../dto/deleted-element-response.dto'; | ||
import { DrawingElementContentDto } from '../dto/drawing-element-content.dto'; | ||
import { DrawingElementResponseDto } from '../dto/drawing-element-response.dto'; | ||
import { ExternalToolElementContentDto } from '../dto/external-tool-element-content.dto'; | ||
import { ExternalToolElementResponseDto } from '../dto/external-tool-element-response.dto'; | ||
import { FileElementContentDto } from '../dto/file-element-content.dto'; | ||
import { FileElementResponseDto } from '../dto/file-element-response.dto'; | ||
import { LinkElementContentDto } from '../dto/link-element-content.dto'; | ||
import { LinkElementResponseDto } from '../dto/link-element-response.dto'; | ||
import { RichTextElementContentDto } from '../dto/rich-text-element-content.dto'; | ||
import { RichTextElementResponseDto } from '../dto/rich-text-element-response.dto'; | ||
import { SubmissionContainerElementResponseDto } from '../dto/submission-container-element-response.dto'; | ||
import { ContentElementType } from '../enums/content-element-type.enum'; | ||
import { SubmissionContainerElementContentDto } from '../dto/submission-container-element-content.dto'; | ||
import { DeletedElementContentDto } from '../dto/deleted-element-content.dto'; | ||
import { VisibilitySettingsResponseDto } from '../dto/visibility-settings-response.dto'; | ||
import { TimestampResponseDto } from '../dto/timestamp-response.dto'; | ||
import { CardContentElementInner } from '../types/card-content-elements-inner.type'; | ||
|
||
export class CardResponseMapper { | ||
public static mapToCardResponseDto(cardResponse: CardResponse) { | ||
public static mapToCardResponseDto(cardResponse: CardResponse): CardResponseDto { | ||
return new CardResponseDto( | ||
cardResponse.id, | ||
cardResponse.title!, | ||
cardResponse.height, | ||
cardResponse.elements, | ||
cardResponse.visibilitySettings, | ||
cardResponse.timestamps | ||
this.mapToCardResponseElementsInnerDto(cardResponse.elements), | ||
this.mapToVisibilitySettingsDto(cardResponse.visibilitySettings), | ||
this.mapToTimestampDto(cardResponse.timestamps) | ||
); | ||
} | ||
|
||
private static mapTo | ||
private static mapToCardResponseElementsInnerDto( | ||
cardResponseElementsInner: CardResponseElementsInner[] | ||
): CardResponseElementsInnerDto[] { | ||
const elements: CardResponseElementsInnerDto[] = []; | ||
|
||
cardResponseElementsInner.forEach((element) => { | ||
switch (element.type) { | ||
case ContentElementType.COLLABORATIVE_TEXT_EDITOR: | ||
elements.push( | ||
new CollaborativeTextEditorElementResponseDto( | ||
element.id, | ||
ContentElementType.COLLABORATIVE_TEXT_EDITOR, | ||
this.mapToElementsContent(element, ContentElementType.COLLABORATIVE_TEXT_EDITOR), | ||
this.mapToTimestampDto(element.timestamps) | ||
) | ||
); | ||
break; | ||
case ContentElementType.DELETED: | ||
elements.push( | ||
new DeletedElementResponseDto( | ||
element.id, | ||
ContentElementType.DELETED, | ||
this.mapToElementsContent(element, ContentElementType.DELETED) as DeletedElementContentDto, | ||
this.mapToTimestampDto(element.timestamps) | ||
) | ||
); | ||
break; | ||
case ContentElementType.SUBMISSION_CONTAINER: | ||
elements.push( | ||
new SubmissionContainerElementResponseDto( | ||
element.id, | ||
ContentElementType.SUBMISSION_CONTAINER, | ||
this.mapToElementsContent( | ||
element, | ||
ContentElementType.SUBMISSION_CONTAINER | ||
) as SubmissionContainerElementContentDto, | ||
this.mapToTimestampDto(element.timestamps) | ||
) | ||
); | ||
break; | ||
case ContentElementType.DRAWING: | ||
elements.push( | ||
new DrawingElementResponseDto( | ||
element.id, | ||
ContentElementType.DRAWING, | ||
this.mapToElementsContent(element, ContentElementType.DRAWING) as DrawingElementContentDto, | ||
this.mapToTimestampDto(element.timestamps) | ||
) | ||
); | ||
break; | ||
case ContentElementType.EXTERNAL_TOOL: | ||
elements.push( | ||
new ExternalToolElementResponseDto( | ||
element.id, | ||
ContentElementType.EXTERNAL_TOOL, | ||
this.mapToElementsContent(element, ContentElementType.EXTERNAL_TOOL) as ExternalToolElementContentDto, | ||
this.mapToTimestampDto(element.timestamps) | ||
) | ||
); | ||
break; | ||
case ContentElementType.FILE: | ||
elements.push( | ||
new FileElementResponseDto( | ||
element.id, | ||
ContentElementType.FILE, | ||
this.mapToElementsContent(element, ContentElementType.FILE) as FileElementContentDto, | ||
this.mapToTimestampDto(element.timestamps) | ||
) | ||
); | ||
break; | ||
case ContentElementType.LINK: | ||
elements.push( | ||
new LinkElementResponseDto( | ||
element.id, | ||
ContentElementType.LINK, | ||
this.mapToElementsContent(element, ContentElementType.LINK) as LinkElementContentDto, | ||
this.mapToTimestampDto(element.timestamps) | ||
) | ||
); | ||
break; | ||
case ContentElementType.RICH_TEXT: | ||
elements.push( | ||
new RichTextElementResponseDto( | ||
element.id, | ||
ContentElementType.RICH_TEXT, | ||
this.mapToElementsContent(element, ContentElementType.RICH_TEXT) as RichTextElementContentDto, | ||
this.mapToTimestampDto(element.timestamps) | ||
) | ||
); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
return elements; | ||
} | ||
|
||
private static mapToElementsContent( | ||
response: CardResponseElementsInner, | ||
elementType: ContentElementType | ||
): CardContentElementInner { | ||
switch (elementType) { | ||
case ContentElementType.COLLABORATIVE_TEXT_EDITOR: | ||
return {}; | ||
case ContentElementType.DELETED: { | ||
const deletedElementContent: DeletedElementResponse = response as DeletedElementResponse; | ||
return new DeletedElementContentDto( | ||
deletedElementContent.content.title, | ||
ContentElementType.DELETED, | ||
deletedElementContent.content.description | ||
); | ||
} | ||
case ContentElementType.SUBMISSION_CONTAINER: { | ||
const submissionContainerResponse: SubmissionContainerElementResponse = | ||
response as SubmissionContainerElementResponse; | ||
return new SubmissionContainerElementContentDto(submissionContainerResponse.content.dueDate); | ||
} | ||
case ContentElementType.DRAWING: { | ||
const drawingResponse: DrawingElementResponse = response as DrawingElementResponse; | ||
return new DrawingElementContentDto(drawingResponse.content.description); | ||
} | ||
case ContentElementType.EXTERNAL_TOOL: { | ||
const externalToolResponse: ExternalToolElementResponse = response as ExternalToolElementResponse; | ||
return new ExternalToolElementContentDto(externalToolResponse.content.contextExternalToolId); | ||
} | ||
case ContentElementType.FILE: { | ||
const fileResponse: FileElementResponse = response as FileElementResponse; | ||
return new FileElementContentDto(fileResponse.content.caption, fileResponse.content.alternativeText); | ||
} | ||
case ContentElementType.LINK: { | ||
const linkElementResponse: LinkElementResponse = response as LinkElementResponse; | ||
return new LinkElementContentDto( | ||
linkElementResponse.content.url, | ||
linkElementResponse.content.title, | ||
linkElementResponse.content.description!, | ||
linkElementResponse.content.imageUrl as string | ||
); | ||
} | ||
case ContentElementType.RICH_TEXT: { | ||
const richTextResponse: RichTextElementResponse = response as RichTextElementResponse; | ||
return new RichTextElementContentDto(richTextResponse.content.text, richTextResponse.content.inputFormat); | ||
} | ||
default: | ||
break; | ||
} | ||
return {}; | ||
} | ||
|
||
private static mapToVisibilitySettingsDto( | ||
visibilitySettings: VisibilitySettingsResponse | ||
): VisibilitySettingsResponseDto { | ||
return new VisibilitySettingsResponseDto(visibilitySettings.publishedAt as string); | ||
} | ||
|
||
private static mapToTimestampDto(timestamp: TimestampsResponse): TimestampResponseDto { | ||
return new TimestampResponseDto(timestamp.lastUpdatedAt, timestamp.createdAt, timestamp.deletedAt!); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...n-cartridge/common-cartridge-client/card-client/types/card-content-elements-inner.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { DeletedElementContentDto } from '../dto/deleted-element-content.dto'; | ||
import { DrawingElementContentDto } from '../dto/drawing-element-content.dto'; | ||
import { ExternalToolElementContentDto } from '../dto/external-tool-element-content.dto'; | ||
import { FileElementContentDto } from '../dto/file-element-content.dto'; | ||
import { LinkElementContentDto } from '../dto/link-element-content.dto'; | ||
import { RichTextElementContentDto } from '../dto/rich-text-element-content.dto'; | ||
import { SubmissionContainerElementContentDto } from '../dto/submission-container-element-content.dto'; | ||
|
||
export type CardContentElementInner = | ||
| LinkElementContentDto | ||
| DeletedElementContentDto | ||
| DrawingElementContentDto | ||
| ExternalToolElementContentDto | ||
| FileElementContentDto | ||
| RichTextElementContentDto | ||
| SubmissionContainerElementContentDto | ||
| object; |