Skip to content

Commit

Permalink
Improved initial banner support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaakko Heusala committed Jan 21, 2024
1 parent 328301b commit 4032cd6
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 3 deletions.
8 changes: 8 additions & 0 deletions banner/types/Banner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024. Sendanor <info@sendanor.fi>. All rights reserved.

import { Entity } from "../../entities/types/Entity";
import { BannerDTO } from "./BannerDTO";

export interface Banner extends Entity<BannerDTO> {

}
7 changes: 4 additions & 3 deletions banner/types/BannerModel.ts → banner/types/BannerDTO.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) 2021-2024. Sendanor <info@sendanor.fi>. All rights reserved.

import { DTO } from "../../entities/types/DTO";
import { BannerLanguage } from "./BannerLanguage";
import { BannerLocation } from "./BannerLocation";
import { BannerState } from "./BannerState";
import { BannerType } from "./BannerType";

export interface BannerModel {
export interface BannerDTO extends DTO {

/**
* The state of the banner
Expand Down Expand Up @@ -41,8 +42,8 @@ export interface BannerModel {
readonly imageUrl : string;
readonly imageAlt : string;

readonly languages ?: BannerLanguage[];
readonly locations ?: BannerLocation[];
readonly languages ?: readonly BannerLanguage[];
readonly locations ?: readonly BannerLocation[];

readonly draftTime ?: string;
readonly startTime ?: string;
Expand Down
104 changes: 104 additions & 0 deletions banner/types/BannerEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright (c) 2024. Sendanor <info@sendanor.fi>. All rights reserved.

import { EntityFactoryImpl } from "../../entities/types/EntityFactoryImpl";
import { VariableType } from "../../entities/types/VariableType";
import { Banner } from "./Banner";
import { BannerDTO } from "./BannerDTO";
import { BannerLanguage } from "./BannerLanguage";
import { BannerLocation } from "./BannerLocation";
import { BannerState } from "./BannerState";
import { BannerType } from "./BannerType";

export const BannerEntityFactory = (
EntityFactoryImpl.create<BannerDTO, Banner>('Banner')
.add( EntityFactoryImpl.createProperty("state").setTypes(BannerState) )
.add( EntityFactoryImpl.createProperty("type").setTypes(BannerType) )
.add( EntityFactoryImpl.createProperty("addTitleText").setTypes(VariableType.BOOLEAN) )
.add( EntityFactoryImpl.createProperty("addAltText").setTypes(VariableType.BOOLEAN) )
.add( EntityFactoryImpl.createProperty("title").setTypes(VariableType.STRING) )
.add( EntityFactoryImpl.createProperty("url").setTypes(VariableType.STRING) )
.add( EntityFactoryImpl.createProperty("imageUrl").setTypes(VariableType.STRING) )
.add( EntityFactoryImpl.createProperty("imageAlt").setTypes(VariableType.STRING) )
.add( EntityFactoryImpl.createOptionalArrayProperty("languages").setTypes(BannerLanguage) )
.add( EntityFactoryImpl.createOptionalArrayProperty("locations").setTypes(BannerLocation) )
.add( EntityFactoryImpl.createProperty("draftTime").setTypes(VariableType.STRING, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("startTime").setTypes(VariableType.STRING, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("publishTime").setTypes(VariableType.STRING, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("endTime").setTypes(VariableType.STRING, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("started").setTypes(VariableType.BOOLEAN, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("published").setTypes(VariableType.BOOLEAN, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("ended").setTypes(VariableType.BOOLEAN, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("owner").setTypes(VariableType.STRING, VariableType.UNDEFINED) )
);

export const isBannerDTO = BannerEntityFactory.createTestFunctionOfDTO();

export const isBanner = BannerEntityFactory.createTestFunctionOfInterface();

export const explainBannerDTO = BannerEntityFactory.createExplainFunctionOfDTO();

export const isBannerDTOOrUndefined = BannerEntityFactory.createTestFunctionOfDTOorOneOf(VariableType.UNDEFINED);

export const explainBannerDTOOrUndefined = BannerEntityFactory.createExplainFunctionOfDTOorOneOf(VariableType.UNDEFINED);

export const BaseBannerEntity = BannerEntityFactory.createEntityType();

/**
* Banner entity.
*/
export class BannerEntity
extends BaseBannerEntity
implements Banner
{

/**
* Creates a Banner entity.
*
* @param value The optional DTO of Banner
*/
public static create (
value ?: BannerDTO,
) : BannerEntity {
return new BannerEntity(value);
}

/**
* Creates a Banner entity from DTO.
*
* @param dto The optional DTO of Banner
*/
public static createFromDTO (
dto : BannerDTO,
) : BannerEntity {
return new BannerEntity(dto);
}

/**
* Normalizes the value as a DTO.
*/
public static toDTO (
value: BannerDTO | Banner | BannerEntity,
) : BannerDTO {
if (isBannerEntity(value)) {
return value.getDTO();
} else if (isBanner(value)) {
return value.getDTO();
} else {
return value;
}
}

/**
* Construct an entity of BannerEntity.
*/
public constructor (
dto ?: BannerDTO | undefined,
) {
super(dto);
}

}

export function isBannerEntity (value: unknown): value is BannerEntity {
return value instanceof BannerEntity;
}

0 comments on commit 4032cd6

Please sign in to comment.