Catalog request for main page
This commit is contained in:
parent
980d0956cf
commit
fd4bf757fa
|
|
@ -3,7 +3,13 @@ import { CatalogService } from './catalog.service';
|
|||
import { CatalogResponseDto } from './dto/catalog-response.dto';
|
||||
import { CatalogItemDto } from './dto/catalog-item.dto';
|
||||
import { CatalogParamsDto } from './dto/catalog-params.dto';
|
||||
import { ApiQuery, ApiResponse, ApiOperation } from '@nestjs/swagger';
|
||||
import {
|
||||
ApiQuery,
|
||||
ApiResponse,
|
||||
ApiOperation,
|
||||
ApiProperty,
|
||||
} from '@nestjs/swagger';
|
||||
import { MainPageCatalogResponseDto } from './dto/main-page-catalog-response.dto';
|
||||
|
||||
@Controller('catalog')
|
||||
export class CatalogController {
|
||||
|
|
@ -38,6 +44,13 @@ export class CatalogController {
|
|||
return this.catalogService.getCatalog(params);
|
||||
}
|
||||
|
||||
@Get('main-page')
|
||||
@ApiOperation({ summary: 'Get catalog for main page' })
|
||||
@ApiProperty({ type: MainPageCatalogResponseDto })
|
||||
async getMainPageCatalog(): Promise<MainPageCatalogResponseDto | null> {
|
||||
return this.catalogService.getMainPageCatalog();
|
||||
}
|
||||
|
||||
@Get('all')
|
||||
@ApiOperation({ summary: 'Get all catalog items without filters' })
|
||||
@ApiResponse({
|
||||
|
|
|
|||
|
|
@ -2,84 +2,288 @@ import { Injectable } from '@nestjs/common';
|
|||
import { CatalogItemDto } from './dto/catalog-item.dto';
|
||||
import { CatalogParamsDto } from './dto/catalog-params.dto';
|
||||
import { CatalogResponseDto } from './dto/catalog-response.dto';
|
||||
import { MainPageCatalogResponseDto } from './dto/main-page-catalog-response.dto';
|
||||
|
||||
@Injectable()
|
||||
export class CatalogService {
|
||||
private catalogItems: CatalogItemDto[] = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Item 1',
|
||||
length: 10,
|
||||
speed: 100,
|
||||
minCost: 50,
|
||||
name: 'Azimut 55',
|
||||
length: 16.7,
|
||||
speed: 32,
|
||||
minCost: 85000,
|
||||
mainImageUrl: '/api/uploads/1765727362318-238005198.jpg',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765727362318-238005198.jpg',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: true,
|
||||
pictureUrl: 'https://example.com/item1.jpg',
|
||||
isFeatured: true,
|
||||
mainImageUrl: '',
|
||||
galleryUrls: [],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Item 2',
|
||||
length: 10,
|
||||
speed: 100,
|
||||
minCost: 50,
|
||||
name: 'Sunseeker Manhattan 52',
|
||||
length: 15.8,
|
||||
speed: 34,
|
||||
minCost: 92000,
|
||||
mainImageUrl: '/api/uploads/1765728068963-634185622.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728068963-634185622.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: false,
|
||||
pictureUrl: 'https://example.com/item1.jpg',
|
||||
isFeatured: false,
|
||||
mainImageUrl: '',
|
||||
galleryUrls: [],
|
||||
topText: '🔥 Лучшее предложение',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Item 3',
|
||||
length: 10,
|
||||
speed: 100,
|
||||
minCost: 50,
|
||||
name: 'Princess V55',
|
||||
length: 16.7,
|
||||
speed: 33,
|
||||
minCost: 78000,
|
||||
mainImageUrl: '/api/uploads/1765728152179-305707681.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728152179-305707681.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: true,
|
||||
pictureUrl: 'https://example.com/item1.jpg',
|
||||
isFeatured: false,
|
||||
mainImageUrl: '',
|
||||
galleryUrls: [],
|
||||
topText: '🍷 Идеальна для заката с бокалом вина',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Item 4',
|
||||
length: 10,
|
||||
speed: 100,
|
||||
minCost: 50,
|
||||
name: 'Ferretti 500',
|
||||
length: 15.2,
|
||||
speed: 31,
|
||||
minCost: 68000,
|
||||
mainImageUrl: '/api/uploads/1765728169750-667674217.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728169750-667674217.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: true,
|
||||
pictureUrl: 'https://example.com/item1.jpg',
|
||||
isFeatured: false,
|
||||
mainImageUrl: '',
|
||||
galleryUrls: [],
|
||||
topText: '⏳ Часто бронируется - успей',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Item 4',
|
||||
length: 10,
|
||||
speed: 100,
|
||||
minCost: 50,
|
||||
hasQuickRent: true,
|
||||
pictureUrl: 'https://example.com/item1.jpg',
|
||||
id: 5,
|
||||
name: 'Sea Ray 510 Sundancer',
|
||||
length: 15.5,
|
||||
speed: 35,
|
||||
minCost: 72000,
|
||||
mainImageUrl: '/api/uploads/1765728190017-763752836.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728190017-763752836.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: false,
|
||||
isFeatured: false,
|
||||
mainImageUrl: '',
|
||||
galleryUrls: [],
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Item 4',
|
||||
length: 10,
|
||||
speed: 100,
|
||||
minCost: 50,
|
||||
id: 6,
|
||||
name: 'Bavaria SR41',
|
||||
length: 12.5,
|
||||
speed: 28,
|
||||
minCost: 45000,
|
||||
mainImageUrl: '/api/uploads/1765728208376-854378188.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728208376-854378188.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: true,
|
||||
isFeatured: false,
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: 'Jeanneau Merry Fisher 895',
|
||||
length: 8.9,
|
||||
speed: 25,
|
||||
minCost: 32000,
|
||||
mainImageUrl: '/api/uploads/1765728227998-695635756.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728227998-695635756.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: true,
|
||||
isFeatured: false,
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: 'Beneteau Swift Trawler 41',
|
||||
length: 12.5,
|
||||
speed: 22,
|
||||
minCost: 55000,
|
||||
mainImageUrl: '/api/uploads/1765728068963-634185622.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728068963-634185622.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: false,
|
||||
isFeatured: false,
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
name: 'Lagoon 450',
|
||||
length: 13.5,
|
||||
speed: 20,
|
||||
minCost: 65000,
|
||||
mainImageUrl: '/api/uploads/1765728152179-305707681.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728152179-305707681.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: true,
|
||||
isFeatured: false,
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
name: 'Fountaine Pajot Lucia 40',
|
||||
length: 11.7,
|
||||
speed: 18,
|
||||
minCost: 58000,
|
||||
mainImageUrl: '/api/uploads/1765728169750-667674217.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728169750-667674217.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: true,
|
||||
isFeatured: false,
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
name: 'Dufour 460',
|
||||
length: 14.1,
|
||||
speed: 26,
|
||||
minCost: 62000,
|
||||
mainImageUrl: '/api/uploads/1765728190017-763752836.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728190017-763752836.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: false,
|
||||
isFeatured: false,
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
name: 'Grand Banks 60',
|
||||
length: 18.3,
|
||||
speed: 24,
|
||||
minCost: 125000,
|
||||
mainImageUrl: '/api/uploads/1765728208376-854378188.webp',
|
||||
galleryUrls: [
|
||||
'/api/uploads/1765728208376-854378188.webp',
|
||||
'/api/uploads/1765727637471-474231444.webp',
|
||||
'/api/uploads/1765727743466-187581713.webp',
|
||||
'/api/uploads/1765727819793-158598111.webp',
|
||||
'/api/uploads/1765727903961-559930753.webp',
|
||||
'/api/uploads/1765727928577-55944164.webp',
|
||||
'/api/uploads/1765727948691-389175954.webp',
|
||||
'/api/uploads/1765727961591-243584836.webp',
|
||||
'/api/uploads/1765727992064-37229339.webp',
|
||||
],
|
||||
hasQuickRent: true,
|
||||
pictureUrl: 'https://example.com/item1.jpg',
|
||||
isFeatured: false,
|
||||
mainImageUrl: '',
|
||||
galleryUrls: [],
|
||||
},
|
||||
];
|
||||
|
||||
async getMainPageCatalog(): Promise<MainPageCatalogResponseDto | null> {
|
||||
const clonedCatalog = [...this.catalogItems];
|
||||
const filteredCatalog = clonedCatalog.filter(
|
||||
({ isFeatured }) => !isFeatured,
|
||||
);
|
||||
|
||||
const featuredYacthIndex = clonedCatalog.findIndex(
|
||||
(item) => item.isFeatured === true,
|
||||
);
|
||||
|
||||
if (featuredYacthIndex !== -1) {
|
||||
return {
|
||||
featuredYacht: clonedCatalog[featuredYacthIndex],
|
||||
restYachts: filteredCatalog.slice(0, 6),
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async getCatalog(params?: CatalogParamsDto): Promise<CatalogResponseDto> {
|
||||
let filteredItems = [...this.catalogItems];
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ export class CatalogItemDto {
|
|||
length: number;
|
||||
speed: number;
|
||||
minCost: number;
|
||||
hasQuickRent: boolean;
|
||||
pictureUrl: string;
|
||||
isFeatured: boolean;
|
||||
mainImageUrl: string;
|
||||
galleryUrls: string[];
|
||||
hasQuickRent: boolean;
|
||||
isFeatured: boolean;
|
||||
topText?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
import { CatalogItemDto } from './catalog-item.dto';
|
||||
|
||||
export class MainPageCatalogResponseDto {
|
||||
featuredYacht: CatalogItemDto;
|
||||
restYachts: CatalogItemDto[];
|
||||
}
|
||||
Loading…
Reference in New Issue