Skip to content

Commit 56b172a

Browse files
committed
feat: application/usecase router-network port 추가
- router-network input port 추가 - router-network output port 추가 - router-network usecase 반환형 promise로 변경
1 parent 080b357 commit 56b172a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { RouterNetworkOutputPort } from 'src/application/port/output/router-network.output-port';
2+
import { RouterNetworkUseCase } from 'src/application/usecase/router-network.usecase';
3+
import { Router } from 'src/domain/entity/router';
4+
import { NetworkOperation } from 'src/domain/service/network.operation';
5+
import { Network } from 'src/domain/vo/network';
6+
import { RouterId } from 'src/domain/vo/router.id';
7+
8+
export class RouterNetworkInputPort implements RouterNetworkUseCase {
9+
public constructor(private readonly _routerNetworkOutputPort: RouterNetworkOutputPort) {}
10+
11+
async addNetworkToRouter(routerId: RouterId, network: Network): Promise<Router> {
12+
const router = await this.fetchRouter(routerId);
13+
return await this.createNetwork(router, network);
14+
}
15+
16+
private async fetchRouter(routerId: RouterId): Promise<Router> {
17+
return await this._routerNetworkOutputPort.fetchRouterById(routerId);
18+
}
19+
20+
private async createNetwork(router: Router, network: Network): Promise<Router> {
21+
const newRouter = NetworkOperation.createNewNetwork(router, network);
22+
23+
return (await this.persistNetwork(router)) ? newRouter : router;
24+
}
25+
26+
private async persistNetwork(router: Router): Promise<boolean> {
27+
return await this._routerNetworkOutputPort.persistRouter(router);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Router } from 'src/domain/entity/router';
2+
import { RouterId } from 'src/domain/vo/router.id';
3+
4+
export interface RouterNetworkOutputPort {
5+
fetchRouterById(routerId: RouterId): Promise<Router>;
6+
persistRouter(router: Router): Promise<boolean>;
7+
}

example03/src/application/usecase/router-network.usecase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export interface RouterNetworkUseCase {
1616
* - And CIDR이 유효하다
1717
* - Then 라우터에 네트워크를 추가한다
1818
*/
19-
addNetworkToRouter(routerId: RouterId, network: Network): Router;
19+
addNetworkToRouter(routerId: RouterId, network: Network): Promise<Router>;
2020
}

0 commit comments

Comments
 (0)