Skip to content

Commit

Permalink
Merge pull request #58 from VentionCapstone/feature/108-full-view-acc…
Browse files Browse the repository at this point in the history
…omodation

Feature/108 full view accomodation
  • Loading branch information
JamshidMirzakhmedov authored Jan 22, 2024
2 parents c503754 + e4d520e commit 7532fab
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/accommodation/accommodation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { LangQuery } from 'src/customDecorators/langQuery.decorator';
import ErrorsTypes from 'src/errors/errors.enum';
import { ReviewDto } from 'src/reviews/dto/review-response.dto';
import { AccommodationService } from './accommodation.service';
import { MediaAllDto } from './dto/accommodation-media.dto';
import AccommodationResponseDto, { AccommodationDto } from './dto/accommodation-response.dto';
import CreateAccommodationDto from './dto/create-accommodation.dto';
import { OrderAndFilterReviewDto } from './dto/get-review.dto';
Expand Down Expand Up @@ -393,4 +394,27 @@ export class AccommodationController {
const { accommodation, owner } = await this.accommodationService.getOneAccommodation(id);
return { success: true, data: { ...accommodation, owner } };
}

@ApiOperation({ summary: 'get all media of single accommodation' })
@ApiResponse({
status: 200,
description: 'Accommodation with provided id',
type: MediaAllDto,
})
@ApiResponse({
status: 500,
description: 'Internal Server Error',
})
@ApiParam({
name: 'id',
type: String,
description: 'Accommodation ID',
required: true,
})
@Get('/:id/media')
async getMedia(@Param('id') id: string) {
const media = await this.accommodationService.getAllMedia(id);

return { succes: true, data: media };
}
}
12 changes: 12 additions & 0 deletions src/accommodation/accommodation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ export class AccommodationService {
}
}

async getAllMedia(id: string) {
try {
const allMedia = await this.prisma.media.findMany({
where: { accommodationId: id },
});

return allMedia;
} catch (error) {
throw new GlobalException(ErrorsTypes.ACCOMMODATION_FAILED_TO_GET_IMAGES, error.message);
}
}

async uploadImageToS3(file: Express.Multer.File): Promise<UploadImageResponse> {
const requestBody: UploadImageType = {
mimetype: file.mimetype,
Expand Down
6 changes: 6 additions & 0 deletions src/accommodation/dto/accommodation-media.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import MediaResponseDto from 'src/media/dto/media.dto';

export class MediaAllDto {
success: boolean;
media: MediaResponseDto[];
}
1 change: 1 addition & 0 deletions src/errors/errors.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum ErrorsTypes {
ACCOMMODATION_FAILED_TO_DELETE = 'ACCOMMODATION_FAILED_TO_DELETE',
ACCOMMODATION_FAILED_GET_DELETING = 'ACCOMMODATION_FAILED_GET_DELETING',
ACCOMMODATION_FAILED_TO_GET = 'ACCOMMODATION_FAILED_TO_GET',
ACCOMMODATION_FAILED_TO_GET_IMAGES = 'ACCOMMODATION_FAILED_TO_GET_IMAGES',
ACCOMMODATION_FAILED_TO_GET_LIST = 'ACCOMMODATION_FAILED_TO_GET_LIST',
ACCOMMODATION_FAILED_TO_GET_RESTORING = 'ACCOMMODATION_FAILED_TO_GET_RESTORING',
ACCOMMODATION_FAILED_TO_RESTORE = 'ACCOMMODATION_FAILED_TO_RESTORE',
Expand Down
1 change: 1 addition & 0 deletions src/media/dto/media.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default class MediaResponseDto {
id: string;
imageUrl: string;
thumbnailUrl: string;
accommodationId: string;
Expand Down

0 comments on commit 7532fab

Please sign in to comment.