diff --git a/apps/server/src/modules/school/api/controller/mapper/federal-state.mapper.ts b/apps/server/src/modules/school/api/controller/mapper/federal-state.mapper.ts new file mode 100644 index 00000000000..5abf41317b9 --- /dev/null +++ b/apps/server/src/modules/school/api/controller/mapper/federal-state.mapper.ts @@ -0,0 +1,33 @@ +import { County } from '@src/modules/school/domain'; +import { FederalStateDto } from '@src/modules/school/domain/dto'; +import { FederalStateResponse } from '../response'; +import { CountyResponse } from '../response/county.response'; + +export class FederalStateMapper { + public static mapToResponse(federalState: FederalStateDto): FederalStateResponse { + const counties = federalState.counties && this.mapToCountyResponses(federalState.counties); + + const res = new FederalStateResponse({ + ...federalState, + counties, + }); + + return res; + } + + private static mapToCountyResponses(counties: County[]): CountyResponse[] { + const res = counties.map((county) => this.mapToCountyResponse(county)); + + return res; + } + + private static mapToCountyResponse(county: County): CountyResponse { + const res = new CountyResponse({ + name: county.name, + countyId: county.countyId, + antaresKey: county.antaresKey, + }); + + return res; + } +} diff --git a/apps/server/src/modules/school/api/controller/mapper/school-response.mapper.ts b/apps/server/src/modules/school/api/controller/mapper/school-response.mapper.ts index b5ed1bade8c..c99402a44f1 100644 --- a/apps/server/src/modules/school/api/controller/mapper/school-response.mapper.ts +++ b/apps/server/src/modules/school/api/controller/mapper/school-response.mapper.ts @@ -1,39 +1,28 @@ import { PaginationParams } from '@shared/controller'; -import { SlimSchoolDto } from '@src/modules/school/domain/dto'; -import { County, FederalState, School, SchoolYear, System } from '../../../domain'; -import { SlimSchoolListResponse, SchoolResponse } from '../response'; -import { CountyResponse } from '../response/county.response'; -import { FederalStateResponse } from '../response/federal-state.response'; +import { SchoolDto, SlimSchoolDto } from '@src/modules/school/domain/dto'; +import { SchoolResponse, SlimSchoolListResponse } from '../response'; import { SlimSchoolResponse } from '../response/school-reduced.response'; -import { SchoolYearResponse } from '../response/school-year.response'; -import { SystemResponse } from '../response/system.response'; +import { FederalStateMapper } from './federal-state.mapper'; +import { SchoolYearMapper } from './school-year.mapper'; +import { SystemMapper } from './system.mapper'; export class SchoolResponseMapper { - public static mapToResponse(school: School): SchoolResponse { - const schoolProps = school.getProps(); - - const federalState = this.mapToFederalStateResponse(schoolProps.federalState); - const currentYear = schoolProps.currentYear && this.mapToSchoolYearResponse(schoolProps.currentYear); - const features = schoolProps.features && Array.from(schoolProps.features); - const systems = schoolProps.systems?.map((system) => this.mapToSystemResponse(system)); + public static mapToResponse(school: SchoolDto): SchoolResponse { + const federalState = FederalStateMapper.mapToResponse(school.federalState); + const currentYear = school.currentYear && SchoolYearMapper.mapToResponse(school.currentYear); + const features = school.features && Array.from(school.features); + const systems = school.systems?.map((system) => SystemMapper.mapToResponse(system)); // TODO: Do we want to access the props via getProps() here or do we want getters? // I added getters for federalState and schoolYear because there are conditions with them below // and then the code is a easier to read. But I wasn't really sure. // Do we want any fixed criteria for when to add getters? const res = new SchoolResponse({ - id: school.id, - name: schoolProps.name, - officialSchoolNumber: schoolProps.officialSchoolNumber, - currentYear, + ...school, federalState, - county: schoolProps.county, - purpose: schoolProps.purpose, + currentYear, features, systems, - inMaintenance: school.isInMaintenance(), - isExternal: school.isExternal(), - logo_dataUrl: schoolProps.logo_dataUrl, }); return res; @@ -52,69 +41,4 @@ export class SchoolResponseMapper { return res; } - - // TODO: Create own mappers for other DOs! - private static mapToFederalStateResponse(federalState: FederalState): FederalStateResponse { - const federalStateProps = federalState.getProps(); - - const counties = federalStateProps.counties && this.mapToCountyResponses(federalStateProps.counties); - - const res = new FederalStateResponse({ - id: federalState.id, - name: federalStateProps.name, - abbreviation: federalStateProps.abbreviation, - logoUrl: federalStateProps.logoUrl, - counties, - }); - - return res; - } - - private static mapToCountyResponses(counties: County[]): CountyResponse[] { - const res = counties.map((county) => this.mapToCountyResponse(county)); - - return res; - } - - private static mapToCountyResponse(county: County): CountyResponse { - const res = new CountyResponse({ - name: county.name, - countyId: county.countyId, - antaresKey: county.antaresKey, - }); - - return res; - } - - private static mapToSchoolYearResponse(schoolYear: SchoolYear): SchoolYearResponse { - const schoolYearProps = schoolYear.getProps(); - - const res = new SchoolYearResponse({ - id: schoolYear.id, - name: schoolYearProps.name, - startDate: schoolYearProps.startDate, - endDate: schoolYearProps.endDate, - }); - - return res; - } - - private static mapToSystemResponse(system: System) { - const systemProps = system.getProps(); - - const res = new SystemResponse({ - id: system.id, - type: systemProps.type, - url: systemProps.url, - alias: systemProps.alias, - displayName: systemProps.displayName, - oauthConfig: systemProps.oauthConfig, - oidcConfig: systemProps.oidcConfig, - ldapConfig: systemProps.ldapConfig, - provisioningStrategy: systemProps.provisioningStrategy, - provisioningUrl: systemProps.provisioningUrl, - }); - - return res; - } } diff --git a/apps/server/src/modules/school/api/controller/mapper/school-year.mapper.ts b/apps/server/src/modules/school/api/controller/mapper/school-year.mapper.ts new file mode 100644 index 00000000000..bb58b9111d1 --- /dev/null +++ b/apps/server/src/modules/school/api/controller/mapper/school-year.mapper.ts @@ -0,0 +1,10 @@ +import { SchoolYearDto } from '@src/modules/school/domain'; +import { SchoolYearResponse } from '../response'; + +export class SchoolYearMapper { + public static mapToResponse(schoolYear: SchoolYearDto): SchoolYearResponse { + const res = new SchoolYearResponse(schoolYear); + + return res; + } +} diff --git a/apps/server/src/modules/school/api/controller/mapper/system.mapper.ts b/apps/server/src/modules/school/api/controller/mapper/system.mapper.ts new file mode 100644 index 00000000000..f2aac187511 --- /dev/null +++ b/apps/server/src/modules/school/api/controller/mapper/system.mapper.ts @@ -0,0 +1,10 @@ +import { SystemDto } from '@src/modules/school/domain'; +import { SystemResponse } from '../response'; + +export class SystemMapper { + public static mapToResponse(system: SystemDto): SystemResponse { + const res = new SystemResponse(system); + + return res; + } +} diff --git a/apps/server/src/modules/school/api/controller/response/index.ts b/apps/server/src/modules/school/api/controller/response/index.ts index c9fbbb037aa..cc4b77d4eb6 100644 --- a/apps/server/src/modules/school/api/controller/response/index.ts +++ b/apps/server/src/modules/school/api/controller/response/index.ts @@ -1,2 +1,5 @@ +export * from './federal-state.response'; export * from './school.response'; export * from './school-list.response'; +export * from './school-year.response'; +export * from './system.response'; diff --git a/apps/server/src/modules/school/api/controller/school.controller.ts b/apps/server/src/modules/school/api/controller/school.controller.ts index b555cd9e3f4..4d30c554a23 100644 --- a/apps/server/src/modules/school/api/controller/school.controller.ts +++ b/apps/server/src/modules/school/api/controller/school.controller.ts @@ -15,10 +15,11 @@ export class SchoolController { // TODO: Do we have a convention for the casing of routes? @Get('/slim-list') - public async getAllSchools( + public async getSlimSchoolsList( @Query() query: SchoolQueryParams, @Query() pagination: PaginationParams ): Promise { + // TODO: Think about consistent naming here: What comes first "Slim" or "List"? const schools = await this.schoolUc.getListOfSlimSchools(query, pagination); const res = SchoolResponseMapper.mapToSlimListResponse(schools, pagination); diff --git a/apps/server/src/modules/school/domain/dto/federal-state.dto.ts b/apps/server/src/modules/school/domain/dto/federal-state.dto.ts new file mode 100644 index 00000000000..830bf2d276c --- /dev/null +++ b/apps/server/src/modules/school/domain/dto/federal-state.dto.ts @@ -0,0 +1,21 @@ +import { County } from '../type'; + +export class FederalStateDto { + constructor({ id, name, abbreviation, logoUrl, counties }: FederalStateDto) { + this.id = id; + this.name = name; + this.abbreviation = abbreviation; + this.logoUrl = logoUrl; + this.counties = counties; + } + + id: string; + + name: string; + + abbreviation: string; + + logoUrl: string; + + counties?: County[]; +} diff --git a/apps/server/src/modules/school/domain/dto/index.ts b/apps/server/src/modules/school/domain/dto/index.ts index ade8bd83f7b..9f263d2754b 100644 --- a/apps/server/src/modules/school/domain/dto/index.ts +++ b/apps/server/src/modules/school/domain/dto/index.ts @@ -1 +1,5 @@ +export * from './federal-state.dto'; +export * from './school.dto'; +export * from './school-year.dto'; export * from './slim-school.dto'; +export * from './system.dto'; diff --git a/apps/server/src/modules/school/domain/dto/school-year.dto.ts b/apps/server/src/modules/school/domain/dto/school-year.dto.ts new file mode 100644 index 00000000000..570aca95d3d --- /dev/null +++ b/apps/server/src/modules/school/domain/dto/school-year.dto.ts @@ -0,0 +1,16 @@ +export class SchoolYearDto { + constructor({ id, name, startDate, endDate }: SchoolYearDto) { + this.id = id; + this.name = name; + this.startDate = startDate; + this.endDate = endDate; + } + + id: string; + + name: string; + + startDate: Date; + + endDate: Date; +} diff --git a/apps/server/src/modules/school/domain/dto/school.dto.ts b/apps/server/src/modules/school/domain/dto/school.dto.ts new file mode 100644 index 00000000000..297d5b5e107 --- /dev/null +++ b/apps/server/src/modules/school/domain/dto/school.dto.ts @@ -0,0 +1,58 @@ +import { County, SchoolFeature, SchoolPurpose } from '../type'; +import { FederalStateDto } from './federal-state.dto'; +import { SchoolYearDto } from './school-year.dto'; +import { SystemDto } from './system.dto'; + +export class SchoolDto { + constructor({ + id, + name, + officialSchoolNumber, + federalState, + currentYear, + purpose, + features, + county, + systems, + inMaintenance, + isExternal, + logo_dataUrl, + }: SchoolDto) { + this.id = id; + this.name = name; + this.officialSchoolNumber = officialSchoolNumber; + this.federalState = federalState; + this.currentYear = currentYear; + this.purpose = purpose; + this.features = features; + this.county = county; + this.systems = systems; + this.inMaintenance = inMaintenance; + this.isExternal = isExternal; + this.logo_dataUrl = logo_dataUrl; + } + + id: string; + + name: string; + + officialSchoolNumber?: string; + + currentYear?: SchoolYearDto; + + federalState: FederalStateDto; + + county?: County; + + purpose?: SchoolPurpose; + + features?: SchoolFeature[]; + + systems?: SystemDto[]; + + inMaintenance: boolean; + + isExternal: boolean; + + logo_dataUrl?: string; +} diff --git a/apps/server/src/modules/school/domain/dto/system.dto.ts b/apps/server/src/modules/school/domain/dto/system.dto.ts new file mode 100644 index 00000000000..31dad32cf29 --- /dev/null +++ b/apps/server/src/modules/school/domain/dto/system.dto.ts @@ -0,0 +1,48 @@ +import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; +import { LdapConfig, OauthConfig, OidcConfig } from '../type'; + +export class SystemDto { + constructor({ + id, + type, + url, + alias, + displayName, + oauthConfig, + oidcConfig, + ldapConfig, + provisioningStrategy, + provisioningUrl, + }: SystemDto) { + this.id = id; + this.type = type; + this.url = url; + this.alias = alias; + this.displayName = displayName; + this.oauthConfig = oauthConfig; + this.oidcConfig = oidcConfig; + this.ldapConfig = ldapConfig; + this.provisioningStrategy = provisioningStrategy; + this.provisioningUrl = provisioningUrl; + } + + id: string; + + type: string; + + url?: string; + + alias?: string; + + displayName?: string; + + oauthConfig?: OauthConfig; + + oidcConfig?: OidcConfig; + + ldapConfig?: LdapConfig; + + provisioningStrategy?: SystemProvisioningStrategy; + + provisioningUrl?: string; +} diff --git a/apps/server/src/modules/school/domain/index.ts b/apps/server/src/modules/school/domain/index.ts index 093f0e9723f..4c8d544c453 100644 --- a/apps/server/src/modules/school/domain/index.ts +++ b/apps/server/src/modules/school/domain/index.ts @@ -1,4 +1,5 @@ export * from './do'; +export * from './dto'; export * from './interface'; export * from './service'; export * from './uc'; diff --git a/apps/server/src/modules/school/domain/mapper/federal-state.mapper.ts b/apps/server/src/modules/school/domain/mapper/federal-state.mapper.ts new file mode 100644 index 00000000000..b640f733140 --- /dev/null +++ b/apps/server/src/modules/school/domain/mapper/federal-state.mapper.ts @@ -0,0 +1,18 @@ +import { FederalState } from '../do'; +import { FederalStateDto } from '../dto'; + +export class FederalStateMapper { + public static mapToDto(federalState: FederalState): FederalStateDto { + const federalStateProps = federalState.getProps(); + + const dto = new FederalStateDto({ + id: federalState.id, + name: federalStateProps.name, + abbreviation: federalStateProps.abbreviation, + logoUrl: federalStateProps.logoUrl, + counties: federalStateProps.counties, + }); + + return dto; + } +} diff --git a/apps/server/src/modules/school/domain/mapper/school-year.mapper.ts b/apps/server/src/modules/school/domain/mapper/school-year.mapper.ts new file mode 100644 index 00000000000..01aaa8ce0d3 --- /dev/null +++ b/apps/server/src/modules/school/domain/mapper/school-year.mapper.ts @@ -0,0 +1,17 @@ +import { SchoolYear } from '../do'; +import { SchoolYearDto } from '../dto'; + +export class SchoolYearMapper { + public static mapToDto(schoolYear: SchoolYear): SchoolYearDto { + const schoolYearProps = schoolYear.getProps(); + + const dto = new SchoolYearDto({ + id: schoolYear.id, + name: schoolYearProps.name, + startDate: schoolYearProps.startDate, + endDate: schoolYearProps.endDate, + }); + + return dto; + } +} diff --git a/apps/server/src/modules/school/domain/mapper/school.mapper.ts b/apps/server/src/modules/school/domain/mapper/school.mapper.ts index 2dc2118c700..3c831a378ea 100644 --- a/apps/server/src/modules/school/domain/mapper/school.mapper.ts +++ b/apps/server/src/modules/school/domain/mapper/school.mapper.ts @@ -1,7 +1,36 @@ import { School } from '../do'; -import { SlimSchoolDto } from '../dto'; +import { SchoolDto, SlimSchoolDto } from '../dto'; +import { FederalStateMapper } from './federal-state.mapper'; +import { SchoolYearMapper } from './school-year.mapper'; +import { SystemMapper } from './system.mapper'; export class SchoolMapper { + public static mapToDto(school: School): SchoolDto { + const schoolProps = school.getProps(); + + const federalState = FederalStateMapper.mapToDto(schoolProps.federalState); + const currentYear = schoolProps.currentYear && SchoolYearMapper.mapToDto(schoolProps.currentYear); + const features = schoolProps.features && Array.from(schoolProps.features); + const systems = schoolProps.systems?.map((system) => SystemMapper.mapToDto(system)); + + const dto = new SchoolDto({ + id: school.id, + name: schoolProps.name, + officialSchoolNumber: schoolProps.officialSchoolNumber, + currentYear, + federalState, + county: schoolProps.county, + purpose: schoolProps.purpose, + features, + systems, + inMaintenance: school.isInMaintenance(), + isExternal: school.isExternal(), + logo_dataUrl: schoolProps.logo_dataUrl, + }); + + return dto; + } + public static mapToListOfSlimDtos(schools: School[]): SlimSchoolDto[] { const dtos = schools.map((school) => this.mapToSlimDto(school)); diff --git a/apps/server/src/modules/school/domain/mapper/system.mapper.ts b/apps/server/src/modules/school/domain/mapper/system.mapper.ts new file mode 100644 index 00000000000..1c8a2f877f0 --- /dev/null +++ b/apps/server/src/modules/school/domain/mapper/system.mapper.ts @@ -0,0 +1,23 @@ +import { System } from '../do'; +import { SystemDto } from '../dto'; + +export class SystemMapper { + public static mapToDto(system: System): SystemDto { + const systemProps = system.getProps(); + + const dto = new SystemDto({ + id: system.id, + type: systemProps.type, + url: systemProps.url, + alias: systemProps.alias, + displayName: systemProps.displayName, + oauthConfig: systemProps.oauthConfig, + oidcConfig: systemProps.oidcConfig, + ldapConfig: systemProps.ldapConfig, + provisioningStrategy: systemProps.provisioningStrategy, + provisioningUrl: systemProps.provisioningUrl, + }); + + return dto; + } +} diff --git a/apps/server/src/modules/school/domain/uc/school.uc.ts b/apps/server/src/modules/school/domain/uc/school.uc.ts index 51131c71cec..be276b0d53b 100644 --- a/apps/server/src/modules/school/domain/uc/school.uc.ts +++ b/apps/server/src/modules/school/domain/uc/school.uc.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common'; import { EntityId, IPagination } from '@shared/domain'; import { School } from '../do'; +import { SchoolDto } from '../dto'; import { SlimSchoolDto } from '../dto/slim-school.dto'; import { SchoolMapper } from '../mapper'; import { SchoolService } from '../service'; @@ -24,9 +25,11 @@ export class SchoolUc { return schools; } - public async getSchool(schoolId: EntityId): Promise { + public async getSchool(schoolId: EntityId): Promise { const school = await this.schoolService.getSchool(schoolId); - return school; + const dto = SchoolMapper.mapToDto(school); + + return dto; } }