Skip to content

Commit

Permalink
feat: update images methods to v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwitr0 committed Nov 18, 2023
1 parent 1d0c5bf commit 7e03e46
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 13 deletions.
11 changes: 11 additions & 0 deletions src/client-request.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ClientRequest } from './client-request';
import { VERSION } from './enums/version.enum';
import { KinopoiskDev,} from './kinopoiskdev';
import { ImageTypeV1_4, WithQueryStrategyV1_4 } from './interfaces/dto/image/image-request.dto';
const fetchMock = require('jest-fetch-mock');
fetchMock.enableMocks();

const Exclude = <T>(value: T) => `!${value}` as unknown as WithQueryStrategyV1_4<T>;

describe('ClientRequest', () => {
let clientRequest: ClientRequest;

Expand Down Expand Up @@ -62,6 +66,13 @@ describe('ClientRequest', () => {
{ headers: { 'X-API-KEY': 'test_key' } },
);
expect(response.data).toEqual(testResponse);

const client = new KinopoiskDev('test_key');

client.image.getByFilters({
page: 1,
type: [ImageTypeV1_4.cover, Exclude(ImageTypeV1_4.cover)],
});
});
});
});
38 changes: 38 additions & 0 deletions src/interfaces/dto/image/image-docs-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Image } from './image';
/**
*
* @export
* @interface ImageDocsResponseDtoV1_4
*/
export interface ImageDocsResponseDtoV1_4 {
/**
*
* @type {Array<Image>}
* @memberof ImageDocsResponseDtoV1_4
*/
docs: Array<Image>;
/**
* Общее количество результатов
* @type {number}
* @memberof ImageDocsResponseDtoV1_4
*/
total: number;
/**
* Количество результатов на странице
* @type {number}
* @memberof ImageDocsResponseDtoV1_4
*/
limit: number;
/**
* Текущая страница
* @type {number}
* @memberof ImageDocsResponseDtoV1_4
*/
page: number;
/**
* Сколько страниц всего
* @type {number}
* @memberof ImageDocsResponseDtoV1_4
*/
pages: number;
}
154 changes: 154 additions & 0 deletions src/interfaces/dto/image/image-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import { SortType } from "../../../enums";

export enum ImageFieldV1_4 {
'movieId' = 'movieId',
'type' = 'type',
'language' = 'language',
'url' = 'url',
'previewUrl' = 'previewUrl',
'height' = 'height',
'width' = 'width',
updatedAt = 'updatedAt',
createdAt = 'createdAt',
}

export enum ImageSelectFieldV1_4 {
'movieId' = 'movieId',
'type' = 'type',
'language' = 'language',
'url' = 'url',
'previewUrl' = 'previewUrl',
'height' = 'height',
'width' = 'width',
updatedAt = 'updatedAt',
createdAt = 'createdAt',
}

export enum ImageTypeV1_4 {
'backdrops' = 'backdrops',
'cover' = 'cover',
'frame' = 'frame',
'promo' = 'promo',
'screenshot' = 'screenshot',
'shooting' = 'shooting',
'still' = 'still',
'wallpaper' = 'wallpaper',
}

export enum ImageLanguageV1_4 {
'ab' = 'ab',
'af' = 'af',
'am' = 'am',
'ar' = 'ar',
'as' = 'as',
'av' = 'av',
'ba' = 'ba',
'be' = 'be',
'bg' = 'bg',
'bn' = 'bn',
'ca' = 'ca',
'ce' = 'ce',
'cn' = 'cn',
'cs' = 'cs',
'cu' = 'cu',
'cv' = 'cv',
'da' = 'da',
'de' = 'de',
}

export type QueryStrategyV1_4 = '!' | '+' | '';
export type WithQueryStrategyV1_4<T> = T extends string ? `${QueryStrategyV1_4}${T}` : never;

export interface ImageRequestV1_4 {
/**
* Номер страницы
* @type {number}
* @memberof ImageRequestV1_4
*/
page?: number;

/**
* Количество элементов на странице
* @type {number}
* @memberof ImageRequestV1_4
*/
limit?: number;

/**
* Список полей требуемых в ответе из модели
* @type {Array<ImageSelectFieldV1_4>}
* @memberof ImageRequestV1_4
*/
selectFields?: Array<ImageSelectFieldV1_4>;

/**
* Список полей которые не должны быть null или пусты
* @type {Array<ImageFieldV1_4>}
* @memberof ImageRequestV1_4
*/
notNullFields?: Array<ImageFieldV1_4>;

/**
* Сортировка по полям из модели
* @type {Array<ImageFieldV1_4>}
* @memberof ImageRequestV1_4
*/
sortField?: Array<ImageFieldV1_4>;

/**
* Тип сортировки применительно к полям из sortField (пример: `"1", "-1"`)
* @type {Array<SortType>}
* @memberof ImageRequestV1_4
*/

sortType?: Array<SortType>;

/**
* Поиск картинок по id фильма (пример: `"666", "!666"`)
* @type {Array<WithQueryStrategyV1_4<string>>}
* @memberof ImageRequestV1_4
*/
movieId?: Array<WithQueryStrategyV1_4<string>>;

/**
* Поиск картинок по типу (пример: `"cover", "!cover"`)
* @type {Array<WithQueryStrategyV1_4<ImageTypeV1_4>>}
* @memberof ImageRequestV1_4
*/
type?: Array<WithQueryStrategyV1_4<ImageTypeV1_4>>;

/**
* Поиск картинок по языку (пример: `"en", "!de"`)
* @type {Array<ImageLanguageV1_4>}
* @memberof ImageRequestV1_4
*/
language?: Array<ImageLanguageV1_4>;

/**
* Поиск картинок по высоте (пример: `"1920", "360-1920"`)
* @type {Array<WithQueryStrategyV1_4<string>>}
* @memberof ImageRequestV1_4
*/
height?: Array<WithQueryStrategyV1_4<string>>;

/**
* Поиск картинок по ширине (пример: `"1080", "320-1080"`)
* @type {Array<WithQueryStrategyV1_4<string>>}
* @memberof ImageRequestV1_4
*/
width?: Array<WithQueryStrategyV1_4<string>>;

/**
* Поиск по дате обновления в базе (пример: `01.01.2020, 01.01.2020-31.12.2020`)
* @type {Array<WithQueryStrategyV1_4<string>>}
* @memberof ImageRequestV1_4
*/
updatedAt?: Array<WithQueryStrategyV1_4<string>>;

/**
* Поиск по дате добавления в базу (пример: `01.01.2020, 01.01.2020-31.12.2020`)
* @type {Array<WithQueryStrategyV1_4<string>>}
* @memberof ImageRequestV1_4
*/
createdAt?: Array<WithQueryStrategyV1_4<string>>;
}
61 changes: 61 additions & 0 deletions src/interfaces/dto/image/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
*
* @export
* @interface Image
*/
export interface Image {
/**
*
* @type {number}
* @memberof Image
*/
movieId: number;
/**
*
* @type {string}
* @memberof Image
*/
type?: string;
/**
*
* @type {string}
* @memberof Image
*/
language?: string;
/**
*
* @type {string}
* @memberof Image
*/
url?: string;
/**
*
* @type {string}
* @memberof Image
*/
previewUrl?: string;
/**
*
* @type {number}
* @memberof Image
*/
height?: number;
/**
*
* @type {number}
* @memberof Image
*/
width?: number;
/**
*
* @type {Date}
* @memberof Image
*/
updatedAt: Date;
/**
*
* @type {Date}
* @memberof Image
*/
createdAt: Date;
}
3 changes: 3 additions & 0 deletions src/interfaces/dto/image/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './image';
export * from './image-docs-response.dto';
export * from './image-request.dto';
7 changes: 3 additions & 4 deletions src/interfaces/query-builder.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IQueryFields } from './query-fields.interface';
import { SORT_TYPE } from '../enums/sort-type.enum';
import { SortType } from '../enums/sort-type.enum';
import { SPECIAL_VALUE } from '../enums/special-value.enum';

export type AllFields<T extends IQueryFields> =
Expand All @@ -16,8 +16,7 @@ export type FiltersValue =
| string
| number
| boolean
| SPECIAL_VALUE
| (string | number | boolean | SPECIAL_VALUE)[];
| (string | number | boolean )[];

export type Filter<T extends IQueryFields> = Partial<{
[key in
Expand All @@ -35,7 +34,7 @@ export type SearchFilter = Partial<{

export interface IQueryBuilder<T extends IQueryFields> {
select(fields: SelectFields<T>[]): IQueryBuilder<T>;
sort(field: AllFields<T>, sortType: SORT_TYPE | '1' | '-1'): IQueryBuilder<T>;
sort(field: AllFields<T>, sortType: SortType | '1' | '-1'): IQueryBuilder<T>;
filterExact(
field: AllFields<T>,
value: string | number | boolean | SPECIAL_VALUE,
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/services/image-service.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ClientRequest } from '../../client-request';
import { IResponse } from '../response.interface';
import { ImageDocsResponseDto } from '../api.interface';
import { ImageRequestV1_4 } from '../dto/image/image-request.dto';
import { ImageDocsResponseDtoV1_4 } from '../dto/image/image-docs-response.dto';

export interface IImageService {
getByFilters(
filters: Record<string, string>,
): Promise<IResponse<ImageDocsResponseDto>>;
filters: ImageRequestV1_4 | Record<string, string>,
): Promise<IResponse<ImageDocsResponseDtoV1_4>>
}
14 changes: 9 additions & 5 deletions src/services/image.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { KinopoiskDev } from '../index';
import { ClientRequest } from '../client-request';
import { IResponse } from '../interfaces/response.interface';
import { ImageDocsResponseDto } from '../interfaces/api.interface';
import { VERSION } from '../enums/version.enum';
import { IImageService } from '../interfaces/services/image-service.interface';
import { ImageRequestV1_4 } from '../interfaces/dto/image/image-request.dto';
import { ImageDocsResponseDtoV1_4 } from '../interfaces/dto/image/image-docs-response.dto';

export class ImageService implements IImageService {
constructor(private readonly request: ClientRequest) {}

async getByFilters(
filters: Record<string, string>,
): Promise<IResponse<ImageDocsResponseDto>> {
return await this.request.get(VERSION.V1, `/image`, filters);
filters: ImageRequestV1_4 | Record<string, string>,
): Promise<IResponse<ImageDocsResponseDtoV1_4>> {
return await this.request.get<ImageDocsResponseDtoV1_4, typeof filters>(
VERSION.V1_4,
`/image`,
filters,
);
}
}

0 comments on commit 7e03e46

Please sign in to comment.