From 3cb6c59d7b58f23eacd31564a345c3d8a33e5772 Mon Sep 17 00:00:00 2001 From: Sergiy Date: Thu, 26 Sep 2024 14:38:13 +0300 Subject: [PATCH 1/3] OV-439: + imageService --- backend/src/bundles/templates/templates.service.ts | 11 +++++++++-- backend/src/bundles/templates/templates.ts | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/src/bundles/templates/templates.service.ts b/backend/src/bundles/templates/templates.service.ts index a63087dbc..2c386284b 100644 --- a/backend/src/bundles/templates/templates.service.ts +++ b/backend/src/bundles/templates/templates.service.ts @@ -1,4 +1,5 @@ import { HTTPCode, HttpError } from '~/common/http/http.js'; +import { type ImageService } from '~/common/services/image/image.service.js'; import { type Service } from '~/common/types/types.js'; import { type UpdateVideoRequestDto } from '../videos/types/types.js'; @@ -14,9 +15,14 @@ import { class TemplateService implements Service { private templateRepository: TemplateRepository; + private imageService: ImageService; - public constructor(templateRepository: TemplateRepository) { + public constructor( + templateRepository: TemplateRepository, + imageService: ImageService, + ) { this.templateRepository = templateRepository; + this.imageService = imageService; } public async findById(id: string): Promise { @@ -54,7 +60,8 @@ class TemplateService implements Service { const { composition, name, userId } = payload; // TODO: CREATE PREVIEW - const compositionPreviewUrl = composition.scenes[0]?.avatar?.url ?? ''; + const compositionPreviewUrl = + await this.imageService.generatePreview(composition); const user = await this.templateRepository.create( TemplateEntity.initializeNew({ diff --git a/backend/src/bundles/templates/templates.ts b/backend/src/bundles/templates/templates.ts index 38ddbeeb4..244cb083b 100644 --- a/backend/src/bundles/templates/templates.ts +++ b/backend/src/bundles/templates/templates.ts @@ -1,4 +1,5 @@ import { logger } from '~/common/logger/logger.js'; +import { imageService } from '~/common/services/services.js'; import { TemplateController } from './templates.controller.js'; import { TemplateModel } from './templates.model.js'; @@ -6,7 +7,7 @@ import { TemplateRepository } from './templates.repository.js'; import { TemplateService } from './templates.service.js'; const templateRepository = new TemplateRepository(TemplateModel); -const templateService = new TemplateService(templateRepository); +const templateService = new TemplateService(templateRepository, imageService); const templateController = new TemplateController(logger, templateService); export { templateController }; From f0667b9ae5b2ac8f280f4bba3fa126a7a2ecae26 Mon Sep 17 00:00:00 2001 From: Sergiy Date: Thu, 26 Sep 2024 15:23:00 +0300 Subject: [PATCH 2/3] OV-439: + imageService --- .../src/bundles/templates/templates.service.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/src/bundles/templates/templates.service.ts b/backend/src/bundles/templates/templates.service.ts index 2c386284b..bf97c4e1b 100644 --- a/backend/src/bundles/templates/templates.service.ts +++ b/backend/src/bundles/templates/templates.service.ts @@ -2,7 +2,10 @@ import { HTTPCode, HttpError } from '~/common/http/http.js'; import { type ImageService } from '~/common/services/image/image.service.js'; import { type Service } from '~/common/types/types.js'; -import { type UpdateVideoRequestDto } from '../videos/types/types.js'; +import { + type Scene, + type UpdateVideoRequestDto, +} from '../videos/types/types.js'; import { templateErrorMessage } from './enums/enums.js'; import { TemplateEntity } from './templates.entity.js'; import { type TemplateRepository } from './templates.repository.js'; @@ -60,8 +63,9 @@ class TemplateService implements Service { const { composition, name, userId } = payload; // TODO: CREATE PREVIEW - const compositionPreviewUrl = - await this.imageService.generatePreview(composition); + const compositionPreviewUrl = await this.imageService.generatePreview( + composition.scenes[0] as Scene, + ); const user = await this.templateRepository.create( TemplateEntity.initializeNew({ @@ -77,7 +81,7 @@ class TemplateService implements Service { public async updateTemplate( id: string, - payload: UpdateVideoRequestDto, + payload: UpdateVideoRequestDto & { previewUrl?: string }, userId: string, ): Promise