File tree 3 files changed +37
-1
lines changed
example03/src/application
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -16,5 +16,5 @@ export interface RouterNetworkUseCase {
16
16
* - And CIDR이 유효하다
17
17
* - Then 라우터에 네트워크를 추가한다
18
18
*/
19
- addNetworkToRouter ( routerId : RouterId , network : Network ) : Router ;
19
+ addNetworkToRouter ( routerId : RouterId , network : Network ) : Promise < Router > ;
20
20
}
You can’t perform that action at this time.
0 commit comments