# Multi-etapes

## Introduction

This following explanation introduce the way to manage multi-etapes inside a same project.

## Backend

- update proprerties `application.properties`. For example:

```diff
- gesdem.application=100003
+ gesdem.applications.100003=100003
+ gesdem.applications.101028=101028
...
server.contextPath=/100003
```

The new `contextPath` has to match with the prestation ID (In theory it is equal to "étape" 0)

- Adapt controller routing and add function `getApplicationKey`. For example:

```diff
@RestController
- @RequestMapping(value = "/api", consumes = "*/*", produces =     MediaType.APPLICATION_JSON_VALUE)
+ @RequestMapping(value = "/api/" + EsproCreationController.APPLICATION_KEY, consumes = "*/*", produces =     MediaType.APPLICATION_JSON_VALUE)
public class EsproCreationController extends AbstractSdkController<EsproCreationForm> {
+    final static String APPLICATION_KEY = "100003";
...
+ @Override
+ protected String getApplicationKey() {
+     return APPLICATION_KEY;
+ }
```

- Create the new controller

## Frontend

- Routing update : duplicate main route in `app.routing.module.ts`

current:

```typescript
{
    path: '',
    data: { root: true },
    ...
}
```

changed to:

```typescript
{
    path: '100003',
    data: { root: true, appCode: '100003' },
    ...
}, {
    path: '101028',
    data: { root: true, appCode: '101028'},
    ...
}
```

- Warning on potential impacts: `ApplicationInfo` will contain multiple `etapesInfos`. This will make `getEtapeInfo()` unusable.

- You need to verify that `basehref` corresponds to the prestation ID in `index.html`.

```html
<base href="/100003/" />
```

- Verify the redirection for local restart: `proxy.conf.json`.

```json
"/100003/api/*": {
...
"/100003/*": {
```

The context has to be identical: in properties (backend), in the `index.html` for `href` attribute and in proxy configuration (frontend)

To get prestation title and ID ("étape" 0) for support alerts, you will need the following pattern:

```typescript
ngOnInit(): void {
  this.applicationInfosSubscription = combineLatest(
      this.activatedRoute.data,
      this.applicationInfoService.data
  ).pipe(
      // Depending on the appCode defined in the routing, we get the proper etapeInfo in the
      // etapeInfos in applicationInfo, not just the first one.
      map(([routeData, applicationInfo]) => applicationInfo.etapeInfos[routeData.appCode]),
      filter(etapeInfo => !!etapeInfo),
  ).subscribe(etapeInfo => {
      const { titreEtape, idMetierEtape } = etapeInfo;

      this.breadcrumbService.setConfiguration({
          prestationCode: idMetierEtape,
      });

      this.appTitle = titreEtape;
      this.etapeId = idMetierEtape;
  });
}
```

## Postfinance payment

- If Postfinance is used for payment you must not use `EPaymentConfiguration` available in `prestations-be`. You have to explicitly indicate the application key for each prestation in contrary of one prestation where that value must be `null`.

- You have to create all needed beans manually:
    1. `EPaymentController`,
    2. `EPaymentService`,
    3. `HashService`,
    4. `IntegrityStringProvider`,
    5. `DefaultAmountProvider`,
    6. `DefaultPspidProvider`,
    7. `DefaultParamPlusProvider`.
