Skip to content

Commit

Permalink
Merge pull request #19 from mwrooth/add-museum_id_param
Browse files Browse the repository at this point in the history
add-museum_id_param
  • Loading branch information
AhmedMabrouk22 authored Jun 28, 2024
2 parents 19c983b + 449256a commit 17c1de3
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions src/collections/collections.controller.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
import { Body, Controller, Delete, Get, HttpStatus, Param, ParseFilePipeBuilder, Post, Put, Query, UploadedFile, UseGuards, UseInterceptors } from '@nestjs/common';
import { ApiBearerAuth, ApiConsumes, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
Body,
Controller,
Delete,
Get,
HttpStatus,
Param,
ParseFilePipeBuilder,
Post,
Put,
Query,
UploadedFile,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import {
ApiBearerAuth,
ApiConsumes,
ApiOperation,
ApiTags,
} from '@nestjs/swagger';
import { CreateCollectionDto } from './dto/create-collection.dto';
import { CollectionsService } from './collections.service';
import { AuthGuard } from 'src/guards/auth.guard';
import { UserTypeGuard } from 'src/guards/user-type.guard';
import { UserTypes } from 'src/decorators/userTypes.decorator';
import { AzureBlobService } from 'src/services/azure-blob.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { UpdateCollectionImageDto, UpdateCollectionNameDto } from './dto/update-collection.dto';
import {
UpdateCollectionImageDto,
UpdateCollectionNameDto,
} from './dto/update-collection.dto';
import { Collection } from '@prisma/client';
import { Pagination } from 'src/shared/dto/pagination';
import { MuseumIdDto } from 'src/museums/dto/museum-id.dto';

@ApiTags('collections')
@Controller('/museums/:museumId/collections')
export class CollectionsController {
constructor(
private readonly service: CollectionsService,
private readonly azureService: AzureBlobService,
) { }
) {}

@Post()
@UseGuards(AuthGuard, UserTypeGuard)
Expand All @@ -39,7 +62,7 @@ export class CollectionsController {
@ApiConsumes('multipart/form-data')
async create(
@Body() data: CreateCollectionDto,
@Param('museumId') museumId,
@Param() museumId: MuseumIdDto,
@UploadedFile(
new ParseFilePipeBuilder()
.addFileTypeValidator({
Expand All @@ -54,7 +77,7 @@ export class CollectionsController {
const imageName = await this.azureService.uploadFile(file, 'Collection');
const imageUrl = this.azureService.getBlobUrl(imageName);
data.image = imageUrl;
data.museumId = +museumId;
data.museumId = +museumId.id;
const collection = await this.service.create(data);
return collection;
}
Expand All @@ -74,7 +97,7 @@ export class CollectionsController {
})
async findAll(
@Param('museumId') museumId: number,
@Query() pagination: Pagination
@Query() pagination: Pagination,
): Promise<Collection[]> {
const collections = await this.service.findAll(museumId, pagination);
return collections;
Expand All @@ -100,12 +123,12 @@ export class CollectionsController {
description: 'Collection id',
required: true,
schema: { type: 'number' },
}
},
],
})
async delete(
@Param('museumId') museumId: number,
@Param('id') id: number
@Param('id') id: number,
): Promise<{ message: string }> {
await this.service.delete(museumId, id);
return {
Expand Down Expand Up @@ -133,7 +156,7 @@ export class CollectionsController {
description: 'Collection id',
required: true,
schema: { type: 'number' },
}
},
],
})
@ApiBearerAuth()
Expand All @@ -142,11 +165,7 @@ export class CollectionsController {
@Param('museumId') museumId: number,
@Param('id') id: number,
): Promise<Collection> {
const res = await this.service.updateCollectionName(
museumId,
id,
name,
);
const res = await this.service.updateCollectionName(museumId, id, name);
return res;
}

Expand All @@ -171,7 +190,7 @@ export class CollectionsController {
description: 'Collection id',
required: true,
schema: { type: 'number' },
}
},
],
})
async updateCollectionImage(
Expand All @@ -192,12 +211,7 @@ export class CollectionsController {
const imageName = await this.azureService.uploadFile(file, 'Collection');
const imageUrl = this.azureService.getBlobUrl(imageName);
image.image = imageUrl;
const res = await this.service.updateCollectionImage(
museumId,
id,
image,
);
const res = await this.service.updateCollectionImage(museumId, id, image);
return res;
}

}
}

0 comments on commit 17c1de3

Please sign in to comment.