> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/extra-module-4-file-management/file-logic/product-related-logic/controller-routes.md).

# Controller routes

Finishing the file-related routes in the products controller.

Great, let's now concentrate on the remaining routes in the <mark style="color:blue;">`ProductsController`</mark>, and after that, start implementing the logic in the <mark style="color:blue;">`ProductsService`</mark>.

Well, the <mark style="color:blue;">`uploadImages()`</mark> route is almost done, we just need to extract the <mark style="color:blue;">`id`</mark> of the entity.

```typescript
@Param() { id }: IdDto,
```

And call the service's method, yet to be created.

```typescript
return this.productsService.uploadImages(id, files);
```

Now, the <mark style="color:blue;">`downloadImage()`</mark> route. However, a new problem arises. In this route, two path params will be used: the <mark style="color:blue;">`id`</mark> of the <mark style="color:blue;">`product`</mark> and the <mark style="color:blue;">`filename`</mark> of the <mark style="color:blue;">`image`</mark>. When using DTOs to validate path params, only a single DTO can be used, as was explained previously. Then, how do we solve this matter?

First, we'll create a very simple DTO for the <mark style="color:blue;">`filename`</mark> in <mark style="color:purple;">files</mark>/<mark style="color:purple;">dto</mark>/<mark style="color:purple;">filename.dto</mark>.

```typescript
export class FilenameDto {
  @IsString()
  readonly filename: string;
}
```

We have the two necessary DTOs. Now, let's combine them into a single DTO. We can achieve that with the <mark style="color:blue;">`IntersectionType`</mark>. In the same place, let's also create the file <mark style="color:purple;">id-filename.dto</mark>, where we'll have a DTO that is the combination of both.

```typescript
export class IdFilenameDto extends IntersectionType(IdDto, FilenameDto) {}
```

{% hint style="info" %}
Remember to import the <mark style="color:blue;">`mapped-types`</mark> from **swagger**, from now on.
{% endhint %}

Perfect, let's now return to the <mark style="color:blue;">`ProductsController`</mark> and add the route to download an image.

```typescript
@Get(':id/images/:filename')
downloadImage(@Param() { id, filename }: IdFilenameDto) {
  return this.productsService.downloadImage(id, filename);
}
```

And finally, the route to delete an image.

```typescript
@Delete(':id/images/:filename')
deleteImage(@Param() { id, filename }: IdFilenameDto) {
  return this.productsService.deleteImage(id, filename);
}
```

As a last step, let's consider that the routes <mark style="color:blue;">`uploadImages()`</mark> and <mark style="color:blue;">`deleteImage()`</mark> should only be accessible to a <mark style="color:blue;">manager</mark>, and that the route <mark style="color:blue;">`downloadImage()`</mark> is **public**.

With this, we have finished the routes in the controller. Let's then go to the service in order to implement these methods.

<mark style="color:green;">**Commit**</mark> - Finishing file related routes in controller
