-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from companieshouse/fix/lp-317-name-page-type
Fix/lp 317 name page type
- Loading branch information
Showing
20 changed files
with
476 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Session } from "@companieshouse/node-session-handler"; | ||
|
||
import ICacheRepository from "../domain/ICacheRepository"; | ||
|
||
class CacheService { | ||
cacheRepository: ICacheRepository; | ||
|
||
constructor(cacheRepository: ICacheRepository) { | ||
this.cacheRepository = cacheRepository; | ||
} | ||
|
||
getDataFromCache(session: Session): Promise<Record<string, any>> { | ||
return this.cacheRepository.getData(session); | ||
} | ||
|
||
async addDataToCache( | ||
session: Session, | ||
data: Record<string, any> | ||
): Promise<void> { | ||
await this.cacheRepository.addData(session, data); | ||
} | ||
|
||
async removeDataFromCache(session: Session, key: string): Promise<void> { | ||
await this.cacheRepository.deleteData(session, key); | ||
} | ||
} | ||
|
||
export default CacheService; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
import GlobalController from "../presentation/controller/global/Controller"; | ||
import RegistrationService from "../application/registration/Service"; | ||
import RegistrationInMemoryGateway from "../infrastructure/gateway/RegistrationInMemoryGateway"; | ||
import RegistrationInMemoryGateway from "../infrastructure/gateway/registration/RegistrationInMemoryGateway"; | ||
import CacheInMemoryRepository from "../infrastructure/repository/CacheInMemoryRepository"; | ||
import RegistrationController from "../presentation/controller/registration/Controller"; | ||
import CacheService from "../application/CacheService"; | ||
|
||
const globalController: GlobalController = new GlobalController(); | ||
|
||
const registrationGateway: RegistrationInMemoryGateway = | ||
new RegistrationInMemoryGateway(); | ||
|
||
const registrationService: RegistrationService = new RegistrationService( | ||
registrationGateway | ||
); | ||
|
||
const cacheRepository = new CacheInMemoryRepository(); | ||
const cacheService = new CacheService(cacheRepository); | ||
|
||
const registrationController: RegistrationController = | ||
new RegistrationController(registrationService); | ||
new RegistrationController(registrationService, cacheService); | ||
|
||
export const appDevDependencies = { | ||
globalController, | ||
registrationGateway, | ||
cacheRepository, | ||
registrationService, | ||
registrationController, | ||
}; |
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,9 @@ | ||
import { Session } from "@companieshouse/node-session-handler"; | ||
|
||
interface ICacheRepository { | ||
getData(session: Session): Promise<Record<string, any>>; | ||
addData(session: Session, data: Record<string, any>): Promise<void>; | ||
deleteData(session: Session, key: string): Promise<void>; | ||
} | ||
|
||
export default ICacheRepository; |
4 changes: 2 additions & 2 deletions
4
...teway/LimitedPartnershipGatewayBuilder.ts → ...ation/LimitedPartnershipGatewayBuilder.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable */ | ||
|
||
import { Session } from "@companieshouse/node-session-handler"; | ||
|
||
import { APPLICATION_CACHE_KEY } from "../../config/constants"; | ||
import ICacheRepository from "../../domain/ICacheRepository"; | ||
|
||
class CacheInMemoryRepository implements ICacheRepository { | ||
cache: { [APPLICATION_CACHE_KEY]: Record<string, any> } | null = null; | ||
|
||
feedCache(value: Record<string, any> | null) { | ||
this.cache = value ? { [APPLICATION_CACHE_KEY]: value } : value; | ||
} | ||
|
||
async getData(session: Session): Promise<Record<string, any>> { | ||
return this.cache?.[APPLICATION_CACHE_KEY] ?? {}; | ||
} | ||
|
||
async addData(session: Session, data: Record<string, any>): Promise<void> { | ||
if (this.cache?.[APPLICATION_CACHE_KEY]) { | ||
this.cache = { | ||
[APPLICATION_CACHE_KEY]: { | ||
...this.cache?.[APPLICATION_CACHE_KEY], | ||
...data, | ||
}, | ||
}; | ||
|
||
return; | ||
} | ||
|
||
this.cache = { | ||
[APPLICATION_CACHE_KEY]: { | ||
...data, | ||
}, | ||
}; | ||
} | ||
|
||
async deleteData(session: Session, key: string): Promise<void> { | ||
const data = await this.getData(session); | ||
|
||
delete data[key]; | ||
|
||
this.cache = { | ||
[APPLICATION_CACHE_KEY]: { | ||
...data, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
export default CacheInMemoryRepository; |
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,30 @@ | ||
import { Session } from "@companieshouse/node-session-handler"; | ||
import ICacheRepository from "../../domain/ICacheRepository"; | ||
import { APPLICATION_CACHE_KEY } from "../../config/constants"; | ||
|
||
class CacheRepository implements ICacheRepository { | ||
async getData(session: Session): Promise<Record<string, any>> { | ||
return (await session?.getExtraData(APPLICATION_CACHE_KEY)) ?? {}; | ||
} | ||
|
||
async addData(session: Session, data: Record<string, any>): Promise<void> { | ||
const cache = await this.getData(session); | ||
|
||
const updatedCache = { | ||
...cache, | ||
...data, | ||
}; | ||
|
||
session?.setExtraData(APPLICATION_CACHE_KEY, updatedCache); | ||
} | ||
|
||
async deleteData(session: Session, key: string): Promise<void> { | ||
const cache = await this.getData(session); | ||
|
||
delete cache[key]; | ||
|
||
session?.setExtraData(APPLICATION_CACHE_KEY, cache); | ||
} | ||
} | ||
|
||
export default CacheRepository; |
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
Oops, something went wrong.