diff --git a/apps/pathway-design/server/cucumber.js b/apps/pathway-design/server/cucumber.js index f5426688..58601629 100644 --- a/apps/pathway-design/server/cucumber.js +++ b/apps/pathway-design/server/cucumber.js @@ -1,8 +1,8 @@ module.exports = { default: { - paths: ['apps/pathway-design/server/src/test/**/*.feature'], + paths: ['apps/pathway-design/server/src/**/*.feature'], requireModule: ['ts-node/register', 'tsconfig-paths/register'], - require: ['apps/pathway-design/server/src/test/**/*.step.ts'], + require: ['apps/pathway-design/server/src/**/*.step.ts'], format: [ 'json:dist/reports/apps/pathway-design/server/test-feature/index.json', 'html:dist/reports/apps/pathway-design/server/test-feature/index.html', diff --git a/apps/pathway-design/server/src/app/app.module.ts b/apps/pathway-design/server/src/app/app.module.ts index 6f815ec9..02c02305 100644 --- a/apps/pathway-design/server/src/app/app.module.ts +++ b/apps/pathway-design/server/src/app/app.module.ts @@ -1,17 +1,12 @@ import { Module } from '@nestjs/common'; -import { PDSPIInitializePathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure'; import { PDSPIAInitializePathwayInterfaceAdaptersModule } from '@bewoak/pathway-design-server-pathway-interface-adapters'; import { PDSPPPathwayPresentersModule } from '@bewoak/pathway-design-server-pathway-presenters'; import { CqrsModule } from '@nestjs/cqrs'; @Module({ imports: [ - PDSPIAInitializePathwayInterfaceAdaptersModule.withPersistence( - PDSPIInitializePathwayPersistenceInfrastructureModule.use('inMemory') - ) - .withPresenter(PDSPPPathwayPresentersModule.use('toJson')) - .build(), + PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson')).build(), CqrsModule.forRoot(), ], controllers: [], diff --git a/apps/pathway-design/server/src/specs/change-title-pathway/index.feature b/apps/pathway-design/server/src/specs/change-title-pathway/index.feature new file mode 100644 index 00000000..37a38c60 --- /dev/null +++ b/apps/pathway-design/server/src/specs/change-title-pathway/index.feature @@ -0,0 +1,12 @@ +Feature: Change the title of a pathway in a memory database with json presenter + + Scenario: I want to change the title of a learning pathway + Given I am authenticated on the platform for change the title of the pathway in memory persistence and json presenter + Given I have a pathway recorded in memory with these data + | title | description | researchField | + | My Pathway | A test pathway | biology | + When I want to change the title of the pathway in memory to "My New Pathway" + Then I should receive from memory the new title of the pathway + | title | + | My New Pathway | + diff --git a/apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts b/apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts new file mode 100644 index 00000000..ca2655cb --- /dev/null +++ b/apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts @@ -0,0 +1,62 @@ +import { strict as assert } from 'node:assert'; +import type { Http2Server } from 'node:http2'; +import { + PDSPIAChangeTitlePathwayInterfaceAdaptersModule, + PDSPIAInitializePathwayInterfaceAdaptersModule, +} from '@bewoak/pathway-design-server-pathway-interface-adapters'; +import { PDSPPPathwayPresentersModule } from '@bewoak/pathway-design-server-pathway-presenters'; +import type { DataTable } from '@cucumber/cucumber'; +import type { INestApplication } from '@nestjs/common'; +import { CqrsModule } from '@nestjs/cqrs'; +import { Test } from '@nestjs/testing'; +import { binding, given, then, when } from 'cucumber-tsflow'; +import request from 'supertest'; + +@binding() +class ControllerSteps { + private app: INestApplication; + private httpServer: Http2Server; + private response: request.Response; + + @given('I am authenticated on the platform for change the title of the pathway in memory persistence and json presenter') + public async withInMemoryPeristenceAndJsonPresenter() { + const testingModule = await Test.createTestingModule({ + imports: [ + PDSPIAChangeTitlePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson')).build(), + PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson')).build(), + CqrsModule.forRoot(), + ], + }).compile(); + + this.app = testingModule.createNestApplication(); + await this.app.init(); + this.httpServer = this.app.getHttpServer(); + } + + @given('I have a pathway recorded in memory with these data') + public async givenIHaveAPathwayRecordedInMemroy(dataTable: DataTable) { + const firstRow = dataTable.hashes()[0]; + + this.response = await request(this.httpServer).post('/pathway/init').send({ + title: firstRow.title, + description: firstRow.description, + researchField: firstRow.researchField, + }); + } + + @when('I want to change the title of the pathway in memory to {string}') + public async whenIChangeTheTitleOfThePathwayTo(title: string) { + this.response = await request(this.httpServer).patch(`/pathway/change-title/${this.response.body.id}`).send({ + title, + }); + } + + @then('I should receive from memory the new title of the pathway') + public async thenIShouldReceiveTheNewTitleOfThePathway(dataTable: DataTable) { + const firstRow = dataTable.hashes()[0]; + + assert.strictEqual(this.response.body.title, firstRow.title); + } +} + +export = ControllerSteps; diff --git a/apps/pathway-design/server/src/specs/initialize-pathway/index.feature b/apps/pathway-design/server/src/specs/initialize-pathway/index.feature index 5547a5eb..28d5312f 100644 --- a/apps/pathway-design/server/src/specs/initialize-pathway/index.feature +++ b/apps/pathway-design/server/src/specs/initialize-pathway/index.feature @@ -1,7 +1,7 @@ -Feature: Initialize Pathway in a memory database +Feature: Initialize Pathway in a memory database with json presenter Scenario: I want to initialize a learning pathway - Given I am authenticated on the platform + Given I am authenticated on the platform for initialize a pathway in memory persistence and json presenter When I want to initialize a pathway with these data | title | description | researchField | | My Pathway | A test pathway | biology | @@ -10,13 +10,4 @@ Feature: Initialize Pathway in a memory database | My Pathway | A test pathway | biology | Then The pathway should be have a unique identifier - Scenario: I want to initialize another learning pathway with different data - Given I am authenticated on the platform - When I want to initialize a pathway with these data - | title | description | researchField | - | Arterial stiffness | Understand the role of the arterial stiffness | biomedical | - Then I should retrieve a pathway initialized with its data - | title | description | researchField | - | Arterial stiffness | Understand the role of the arterial stiffness | biomedical | - Then The pathway should be have a unique identifier \ No newline at end of file diff --git a/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts b/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts index 065d0414..487128eb 100644 --- a/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts +++ b/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts @@ -1,6 +1,5 @@ import { strict as assert } from 'node:assert'; import type { Http2Server } from 'node:http2'; -import { PDSPIInitializePathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure'; import { PDSPIAInitializePathwayInterfaceAdaptersModule } from '@bewoak/pathway-design-server-pathway-interface-adapters'; import { PDSPPPathwayPresentersModule } from '@bewoak/pathway-design-server-pathway-presenters'; import type { DataTable } from '@cucumber/cucumber'; @@ -13,23 +12,19 @@ import request from 'supertest'; @binding() class ControllerSteps { private app: INestApplication; - private response: request.Response; private httpServer: Http2Server; + private response: request.Response; - @given('I am authenticated on the platform') - public async givenAmIAuthenticatedOnThePlatform() { - const module = await Test.createTestingModule({ + @given('I am authenticated on the platform for initialize a pathway in memory persistence and json presenter') + public async withInMemoryPeristenceAndJsonPresenter() { + const testingModule = await Test.createTestingModule({ imports: [ - PDSPIAInitializePathwayInterfaceAdaptersModule.withPersistence( - PDSPIInitializePathwayPersistenceInfrastructureModule.use('inMemory') - ) - .withPresenter(PDSPPPathwayPresentersModule.use('toJson')) - .build(), + PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson')).build(), CqrsModule.forRoot(), ], }).compile(); - this.app = module.createNestApplication(); + this.app = testingModule.createNestApplication(); await this.app.init(); this.httpServer = this.app.getHttpServer(); } diff --git a/libs/pathway-design/server/pathway/application/src/index.ts b/libs/pathway-design/server/pathway/application/src/index.ts index 13c726b1..5634ae43 100644 --- a/libs/pathway-design/server/pathway/application/src/index.ts +++ b/libs/pathway-design/server/pathway/application/src/index.ts @@ -2,3 +2,8 @@ export { PDSPAInitializePathwayCommand } from './lib/initialize/command/initiali export { PDSPAInitializePathwayCommandHandler } from './lib/initialize/command/initialize-pathway.command-handler'; export { PDSPAInitializePathwayService } from './lib/initialize/service/initialize-pathway.service'; export { PDSPAIUInitializePathwayUsecase } from './lib/initialize/usecase/initialize-pathway.usecase'; + +export { PDSPAChangeTitlePathwayCommand } from './lib/change-title/command/change-title-pathway.command'; +export { PDSPAChangeTitlePathwayCommandHandler } from './lib/change-title/command/change-title-pathway.command-handler'; +export { PDSPAChangeTitlePathwayService } from './lib/change-title/service/change-title-pathway.service'; +export { PDSPACUChangeTitlePathwayUseCase } from './lib/change-title/usecase/change-title-pathway.usecase'; diff --git a/libs/pathway-design/server/pathway/application/src/lib/change-title/command/change-title-pathway.command-handler.ts b/libs/pathway-design/server/pathway/application/src/lib/change-title/command/change-title-pathway.command-handler.ts index 6ae47a1f..a8571cae 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/change-title/command/change-title-pathway.command-handler.ts +++ b/libs/pathway-design/server/pathway/application/src/lib/change-title/command/change-title-pathway.command-handler.ts @@ -30,7 +30,7 @@ export class PDSPAChangeTitlePathwayCommandHandler implements ICommandHandler Promise; + changeTitle: (pathwayId: string, title: string) => Promise; } export const PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT = Symbol('PDSPBPChangeTitlePathwayPersistencePort'); diff --git a/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts b/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts index dfffc23f..f305bb99 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts @@ -1,6 +1,6 @@ +import { strict as assert } from 'node:assert'; import type { DataTable } from '@cucumber/cucumber'; import { binding, given, then, when } from 'cucumber-tsflow'; -import { strict as assert } from 'node:assert'; import sinon from 'sinon'; import type { PDSPBEPathwayEntity } from '../../entities/pathway'; import { PDSPBEPathwayTitleChangedEvent } from '../../events/pathway-title-changed.event'; diff --git a/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts b/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts index 32d9215b..ce0ae639 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts @@ -1,6 +1,6 @@ +import { strict as assert } from 'node:assert'; import type { DataTable } from '@cucumber/cucumber'; import { binding, given, then, when } from 'cucumber-tsflow'; -import { strict as assert } from 'node:assert'; import sinon from 'sinon'; import { PDSPBEPathwayEntity } from '../../entities/pathway'; import { PDSPBEPathwayInitializedEvent } from '../../events/pathway-initialized.event'; diff --git a/libs/pathway-design/server/pathway/infrastructure/src/index.ts b/libs/pathway-design/server/pathway/infrastructure/src/index.ts index f158d7b4..d20115cb 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/index.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/index.ts @@ -1 +1 @@ -export { PDSPIInitializePathwayPersistenceInfrastructureModule } from './lib/persistence/initialize/initialize-pathway-persistence-infrastructure.module'; +export { PDSPIPPathwayPersistenceInfrastructureModule } from './lib/persistence/pathway-persistence-infrastructure.module'; diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/change-title-pathway-persistence-infrastructure.module.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/change-title-pathway-persistence-infrastructure.module.ts deleted file mode 100644 index 107ce43f..00000000 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/change-title-pathway-persistence-infrastructure.module.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Module } from '@nestjs/common'; -import { ChangeTitlePathwayInMemoryPersistenceModule } from './in-memory/change-title-pathway-in-memory-persistence.module'; - -const persistenceDriverModuleMap: Record<'inMemory', typeof ChangeTitlePathwayInMemoryPersistenceModule> = { - inMemory: ChangeTitlePathwayInMemoryPersistenceModule, -}; - -type PersistenceDriverAuthorized = keyof typeof persistenceDriverModuleMap; - -@Module({}) -// biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module -export class PDSPIChangeTitlePathwayPersistenceInfrastructureModule { - static use(driver: PersistenceDriverAuthorized) { - const persistenceModule = persistenceDriverModuleMap[driver]; - - return { - module: PDSPIChangeTitlePathwayPersistenceInfrastructureModule, - imports: [persistenceModule], - exports: [persistenceModule], - }; - } -} diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory-persistence.module.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory-persistence.module.ts index 134d26b7..cf7767ab 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory-persistence.module.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory-persistence.module.ts @@ -1,12 +1,10 @@ import { PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT } from '@bewoak/pathway-design-server-pathway-business'; import { Module } from '@nestjs/common'; -import { PathwayInMemoryRepository } from '../../common/in-memory/repositories/in-memory-pathway.repository'; import { ChangeTitlePathwayInMemoryPersistence } from './change-title-pathway-in-memory.persistence'; @Module({ imports: [], providers: [ - PathwayInMemoryRepository, ChangeTitlePathwayInMemoryPersistence, { provide: PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT, diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory.persistence.spec.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory.persistence.spec.ts index 2784ea13..bec4a3bd 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory.persistence.spec.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory.persistence.spec.ts @@ -1,7 +1,7 @@ +import { beforeEach, describe, expect, spyOn, test } from 'bun:test'; import { type PDSPBEPathwayEntity, pDSPBFPathwayFactory } from '@bewoak/pathway-design-server-pathway-business'; import { NotFoundException } from '@nestjs/common'; import { Test } from '@nestjs/testing'; -import { beforeEach, describe, expect, spyOn, test } from 'bun:test'; import { PathwayInMemoryRepository } from '../../common/in-memory/repositories/in-memory-pathway.repository'; import { ChangeTitlePathwayInMemoryPersistence } from './change-title-pathway-in-memory.persistence'; @@ -36,13 +36,13 @@ describe('ChangeTitlePathwayInMemoryPersistence', () => { spyOn(pathwayInMemoryRepository, 'patch'); spyOn(pathwayInMemoryRepository, 'get'); - result = await changeTitlePathwayInMemoryPersistence.changeTitle(pDSPBEPathwayEntity, newTitle); + result = await changeTitlePathwayInMemoryPersistence.changeTitle(pDSPBEPathwayEntity.id, newTitle); }); test('should call the change title method with the title of the pathway in parameter', () => { expect(changeTitlePathwayInMemoryPersistence).toBeDefined(); expect(changeTitlePathwayInMemoryPersistence.changeTitle).toHaveBeenCalledWith( - pDSPBEPathwayEntity, + pDSPBEPathwayEntity.id, 'new pathway title' ); }); @@ -82,7 +82,7 @@ describe('ChangeTitlePathwayInMemoryPersistence', () => { test('should throw an error', async () => { try { - await changeTitlePathwayInMemoryPersistence.changeTitle(pDSPBEPathwayEntity, newTitle); + await changeTitlePathwayInMemoryPersistence.changeTitle(pDSPBEPathwayEntity.id, newTitle); } catch (error) { expect(error).toBeInstanceOf(NotFoundException); expect((error as NotFoundException).message).toMatch( @@ -124,7 +124,7 @@ describe('ChangeTitlePathwayInMemoryPersistence', () => { test('should throw an error', async () => { try { - await changeTitlePathwayInMemoryPersistence.changeTitle(pDSPBEPathwayEntity, newTitle); + await changeTitlePathwayInMemoryPersistence.changeTitle(pDSPBEPathwayEntity.id, newTitle); } catch (error) { expect(error).toBeInstanceOf(NotFoundException); expect((error as NotFoundException).message).toBe('Pathway not found in memory'); diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory.persistence.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory.persistence.ts index e0ab4624..793a4118 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory.persistence.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/change-title/in-memory/change-title-pathway-in-memory.persistence.ts @@ -1,12 +1,6 @@ -import type { - PDSPBEPathwayEntity, - PDSPBPChangeTitlePathwayPersistencePort, -} from '@bewoak/pathway-design-server-pathway-business'; +import type { PDSPBPChangeTitlePathwayPersistencePort } from '@bewoak/pathway-design-server-pathway-business'; import { Inject, Injectable, NotFoundException } from '@nestjs/common'; -import { - mapPathwayEntityToInMemoryPersistence, - mapPathwayInMemoryToPathwayEntity, -} from '../../common/in-memory/mappers/in-memory-pathway.mapper'; +import { mapPathwayInMemoryToPathwayEntity } from '../../common/in-memory/mappers/in-memory-pathway.mapper'; import { PathwayInMemoryRepository } from '../../common/in-memory/repositories/in-memory-pathway.repository'; @Injectable() @@ -16,16 +10,14 @@ export class ChangeTitlePathwayInMemoryPersistence implements PDSPBPChangeTitleP private pathwayInMemoryRepository: PathwayInMemoryRepository ) {} - async changeTitle(pDSPBEPathwayEntity: PDSPBEPathwayEntity, title: string) { - const peristenceModel = mapPathwayEntityToInMemoryPersistence(pDSPBEPathwayEntity); - + async changeTitle(pathwayId: string, title: string) { try { - await this.pathwayInMemoryRepository.patch(peristenceModel.id, { title }); + await this.pathwayInMemoryRepository.patch(pathwayId, { title }); } catch (error) { throw new NotFoundException(`An error has occurred while changing the title of the pathway: ${error}`); } - const pathwayInMemory = await this.pathwayInMemoryRepository.get(peristenceModel.id); + const pathwayInMemory = await this.pathwayInMemoryRepository.get(pathwayId); if (pathwayInMemory === undefined) { throw new NotFoundException('Pathway not found in memory'); diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory-persistence.module.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory-persistence.module.ts index c234f879..2d7ac1a4 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory-persistence.module.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory-persistence.module.ts @@ -1,12 +1,10 @@ import { PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT } from '@bewoak/pathway-design-server-pathway-business'; import { Module } from '@nestjs/common'; -import { PathwayInMemoryRepository } from '../../common/in-memory/repositories/in-memory-pathway.repository'; import { InitializePathwayInMemoryPersistence } from './initialize-pathway-in-memory.persistence'; @Module({ imports: [], providers: [ - PathwayInMemoryRepository, InitializePathwayInMemoryPersistence, { provide: PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT, diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.spec.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.spec.ts index 69b0d752..ffec3225 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.spec.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.spec.ts @@ -1,7 +1,7 @@ +import { beforeEach, describe, expect, spyOn, test } from 'bun:test'; import { type PDSPBEPathwayEntity, pDSPBFPathwayFactory } from '@bewoak/pathway-design-server-pathway-business'; import { NotFoundException } from '@nestjs/common'; import { Test } from '@nestjs/testing'; -import { beforeEach, describe, expect, spyOn, test } from 'bun:test'; import { PathwayInMemoryRepository } from '../../common/in-memory/repositories/in-memory-pathway.repository'; import { InitializePathwayInMemoryPersistence } from './initialize-pathway-in-memory.persistence'; diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/initialize-pathway-persistence-infrastructure.module.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/initialize-pathway-persistence-infrastructure.module.ts deleted file mode 100644 index 6d112052..00000000 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/initialize-pathway-persistence-infrastructure.module.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Module } from '@nestjs/common'; -import { InitializePathwayInMemoryPersistenceModule } from './in-memory/initialize-pathway-in-memory-persistence.module'; - -const persistenceDriverModuleMap: Record<'inMemory', typeof InitializePathwayInMemoryPersistenceModule> = { - inMemory: InitializePathwayInMemoryPersistenceModule, -}; - -type PersistenceDriverAuthorized = keyof typeof persistenceDriverModuleMap; - -@Module({}) -// biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module -export class PDSPIInitializePathwayPersistenceInfrastructureModule { - static use(driver: PersistenceDriverAuthorized) { - const persistenceModule = persistenceDriverModuleMap[driver]; - - return { - module: PDSPIInitializePathwayPersistenceInfrastructureModule, - imports: [persistenceModule], - exports: [persistenceModule], - }; - } -} diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts new file mode 100644 index 00000000..03630adf --- /dev/null +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts @@ -0,0 +1,52 @@ +import { Module } from '@nestjs/common'; + +import { + PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT, + PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT, +} from '@bewoak/pathway-design-server-pathway-business'; +import { ChangeTitlePathwayInMemoryPersistenceModule } from './change-title/in-memory/change-title-pathway-in-memory-persistence.module'; +import { ChangeTitlePathwayInMemoryPersistence } from './change-title/in-memory/change-title-pathway-in-memory.persistence'; +import { PathwayInMemoryRepository } from './common/in-memory/repositories/in-memory-pathway.repository'; +import { InitializePathwayInMemoryPersistenceModule } from './initialize/in-memory/initialize-pathway-in-memory-persistence.module'; +import { InitializePathwayInMemoryPersistence } from './initialize/in-memory/initialize-pathway-in-memory.persistence'; + +const persistenceDriverModulesMap: Record< + 'inMemory', + [typeof InitializePathwayInMemoryPersistenceModule, typeof ChangeTitlePathwayInMemoryPersistenceModule] +> = { + inMemory: [InitializePathwayInMemoryPersistenceModule, ChangeTitlePathwayInMemoryPersistenceModule], +}; + +const persistenceProvidersMap: Record<'inMemory', [typeof PathwayInMemoryRepository]> = { + inMemory: [PathwayInMemoryRepository], +}; + +type PersistenceDriverAuthorized = keyof typeof persistenceDriverModulesMap; + +@Module({}) +// biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module +export class PDSPIPPathwayPersistenceInfrastructureModule { + static use(driver: PersistenceDriverAuthorized) { + const _persistenceModules = persistenceDriverModulesMap[driver]; + const _persistenceProviders = persistenceProvidersMap[driver]; + + return { + module: PDSPIPPathwayPersistenceInfrastructureModule, + providers: [ + InitializePathwayInMemoryPersistence, + { + provide: PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT, + useExisting: InitializePathwayInMemoryPersistence, + }, + ChangeTitlePathwayInMemoryPersistence, + { + provide: PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT, + useExisting: ChangeTitlePathwayInMemoryPersistence, + }, + PathwayInMemoryRepository, + ], + imports: [], + exports: [PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT, PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT], + }; + } +} diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/index.ts b/libs/pathway-design/server/pathway/interface-adapters/src/index.ts index b4a1c3e5..49af9863 100644 --- a/libs/pathway-design/server/pathway/interface-adapters/src/index.ts +++ b/libs/pathway-design/server/pathway/interface-adapters/src/index.ts @@ -1 +1,2 @@ +export { PDSPIAChangeTitlePathwayInterfaceAdaptersModule } from './lib/change-title/change-title-pathway-interface-adapters.module'; export { PDSPIAInitializePathwayInterfaceAdaptersModule } from './lib/initialize/initialize-pathway-interface-adapters.module'; diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/change-title-pathway-interface-adapters.module.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/change-title-pathway-interface-adapters.module.ts new file mode 100644 index 00000000..2bbca538 --- /dev/null +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/change-title-pathway-interface-adapters.module.ts @@ -0,0 +1,33 @@ +import { + PDSPACUChangeTitlePathwayUseCase, + PDSPAChangeTitlePathwayCommandHandler, + PDSPAChangeTitlePathwayService, +} from '@bewoak/pathway-design-server-pathway-application'; +import { PDSPIPPathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure'; +import { type DynamicModule, Module, type Type } from '@nestjs/common'; +import { ChangeTitlePathwayController } from './controller/change-title-pathway.controller'; + +@Module({ + controllers: [ChangeTitlePathwayController], + providers: [PDSPAChangeTitlePathwayCommandHandler, PDSPAChangeTitlePathwayService, PDSPACUChangeTitlePathwayUseCase], + exports: [PDSPAChangeTitlePathwayService], +}) +// biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module +export class PDSPIAChangeTitlePathwayInterfaceAdaptersModule { + private static imports: Array = []; + + static withPresenter(presenterModule: Type | DynamicModule) { + PDSPIAChangeTitlePathwayInterfaceAdaptersModule.imports.push(presenterModule); + return PDSPIAChangeTitlePathwayInterfaceAdaptersModule; + } + + static build() { + return { + module: PDSPIAChangeTitlePathwayInterfaceAdaptersModule, + imports: [ + PDSPIPPathwayPersistenceInfrastructureModule.use('inMemory'), + ...PDSPIAChangeTitlePathwayInterfaceAdaptersModule.imports, + ], + }; + } +} diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/controller/.keep b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/controller/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/controller/change-title-pathway.controller.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/controller/change-title-pathway.controller.ts new file mode 100644 index 00000000..545581f7 --- /dev/null +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/controller/change-title-pathway.controller.ts @@ -0,0 +1,47 @@ +// biome-ignore lint/style/useImportType: +import { + PDSPAChangeTitlePathwayCommand, + PDSPAChangeTitlePathwayService, +} from '@bewoak/pathway-design-server-pathway-application'; +import { Body, Controller, HttpStatus, Param, Patch, UsePipes, ValidationPipe } from '@nestjs/common'; +import { ApiBadRequestResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger'; +// biome-ignore lint/style/useImportType: +import { ChangeTitlePathwayRequestBodyDto } from '../dtos/request/body/request-body.dto'; +// biome-ignore lint/style/useImportType: +import { ChangeTitlePathwayRequestParamsDto } from '../dtos/request/params/request-params.dto'; +import { ChangeTitlePathwayResponseBodyDto } from '../dtos/response/body/response-body.dto'; + +@ApiTags('Pathway') +@UsePipes( + new ValidationPipe({ + whitelist: true, + forbidNonWhitelisted: true, + }) +) +@Controller({ + path: 'pathway', +}) +export class ChangeTitlePathwayController { + constructor(private readonly pDSPAChangeTitlePathwayService: PDSPAChangeTitlePathwayService) {} + + @Patch('change-title/:pathwayId') + @ApiOkResponse({ + description: 'Title of the pathway changed.', + type: ChangeTitlePathwayResponseBodyDto, + }) + @ApiBadRequestResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Cannot change the title of the pathway. Data are not valid.', + }) + execute( + @Param() changeTitlePathwayRequestParamsDto: ChangeTitlePathwayRequestParamsDto, + @Body() changeTitlePathwayRequestBodyDto: ChangeTitlePathwayRequestBodyDto + ): Promise { + return this.pDSPAChangeTitlePathwayService.execute( + new PDSPAChangeTitlePathwayCommand( + changeTitlePathwayRequestParamsDto.pathwayId, + changeTitlePathwayRequestBodyDto.title + ) + ); + } +} diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/.keep b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/request/body/request-body.dto.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/request/body/request-body.dto.ts new file mode 100644 index 00000000..6df1acd4 --- /dev/null +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/request/body/request-body.dto.ts @@ -0,0 +1,6 @@ +import { IsString } from 'class-validator'; + +export class ChangeTitlePathwayRequestBodyDto { + @IsString() + title!: string; +} diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/request/params/request-params.dto.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/request/params/request-params.dto.ts new file mode 100644 index 00000000..0e450425 --- /dev/null +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/request/params/request-params.dto.ts @@ -0,0 +1,3 @@ +export type ChangeTitlePathwayRequestParamsDto = { + pathwayId: string; +}; diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/response/body/response-body.dto.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/response/body/response-body.dto.ts new file mode 100644 index 00000000..4a0eb14f --- /dev/null +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/change-title/dtos/response/body/response-body.dto.ts @@ -0,0 +1,8 @@ +import type { PDSPBPPathwayPresenters } from '@bewoak/pathway-design-server-pathway-business'; + +export class ChangeTitlePathwayResponseBodyDto implements PDSPBPPathwayPresenters { + description!: string; + id!: string; + researchField!: string; + title!: string; +} diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts index ed4803ed..fce6ad15 100644 --- a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts @@ -3,6 +3,7 @@ import { PDSPAInitializePathwayCommandHandler, PDSPAInitializePathwayService, } from '@bewoak/pathway-design-server-pathway-application'; +import { PDSPIPPathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure'; import { type DynamicModule, Module, type Type } from '@nestjs/common'; import { InitializePathwayController } from './controller/initialize-pathway.controller'; @@ -15,11 +16,6 @@ import { InitializePathwayController } from './controller/initialize-pathway.con export class PDSPIAInitializePathwayInterfaceAdaptersModule { private static imports: Array = []; - static withPersistence(persistenceModule: Type | DynamicModule) { - PDSPIAInitializePathwayInterfaceAdaptersModule.imports.push(persistenceModule); - return PDSPIAInitializePathwayInterfaceAdaptersModule; - } - static withPresenter(presenterModule: Type | DynamicModule) { PDSPIAInitializePathwayInterfaceAdaptersModule.imports.push(presenterModule); return PDSPIAInitializePathwayInterfaceAdaptersModule; @@ -28,7 +24,10 @@ export class PDSPIAInitializePathwayInterfaceAdaptersModule { static build() { return { module: PDSPIAInitializePathwayInterfaceAdaptersModule, - imports: PDSPIAInitializePathwayInterfaceAdaptersModule.imports, + imports: [ + PDSPIPPathwayPersistenceInfrastructureModule.use('inMemory'), + ...PDSPIAInitializePathwayInterfaceAdaptersModule.imports, + ], }; } }