Skip to content

Commit

Permalink
refactor(#13): remove draft attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoamalric committed Jan 19, 2023
1 parent 5011867 commit be7b828
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 143 deletions.
48 changes: 10 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/main/modules/application/dto/video-create.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export type VideoCreateDto = {

visibility: Visibility;

draft: boolean;

source: string;

attachments?: string[]; // Optional list of attachments id
Expand Down
6 changes: 2 additions & 4 deletions src/main/modules/application/dto/video-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Visibility } from "../../infrastructure/adapters/repositories/entities/content.model";
import { VideoSource } from "../../domain/models/video.model";
import { PresignedUrlResponse } from "../../../core/types/presigned-url.type";
import { VideoSource } from "../../domain/models/video.model";
import { Watchtime } from "../../domain/models/watchtime.model";
import { Visibility } from "../../infrastructure/adapters/repositories/entities/content.model";
import { UserDto } from "./user.dto";

export type VideoPsuResponse = {
Expand All @@ -24,8 +24,6 @@ export class VideoResponse {

visibility: Visibility;

draft: boolean;

likes?: number;

views?: number;
Expand Down
2 changes: 0 additions & 2 deletions src/main/modules/application/dto/video-update.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export type VideoUpdateDto = {

visibility: Visibility;

draft: string;

source: string;

attachments?: string[]; // Optional list of attachments ids
Expand Down
4 changes: 0 additions & 4 deletions src/main/modules/domain/models/video.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export class VideoProps {

visibility: Visibility;

draft: boolean;

likes?: number;

views?: number;
Expand Down Expand Up @@ -92,7 +90,6 @@ export class Video {
public thumbnail: string,
public publisher: User,
public visibility: Visibility,
public draft: boolean,
public likes: number,
public views: number,
public sourceType: VideoSource,
Expand All @@ -112,7 +109,6 @@ export class Video {
props.thumbnail,
props.publisher,
props.visibility,
props.draft,
props.likes,
props.views,
props.sourceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class VideoApiMapper extends AbstractMapper<Video, VideoResponse> {
description: apiModel.description,
thumbnail: apiModel.thumbnail,
visibility: apiModel.visibility,
draft: apiModel.draft,
source: apiModel.source
};
if (apiModel.slug) {
Expand Down Expand Up @@ -70,7 +69,6 @@ export class VideoApiMapper extends AbstractMapper<Video, VideoResponse> {
thumbnail: formatThumbnailUri(),
publisher: entity.publisher,
visibility: entity.visibility,
draft: entity.draft,
likes: entity.likes,
views: entity.views,
sourceType: entity.sourceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class VideoEntityMapper extends AbstractMapper<VideoEntity, Video> {
thumbnail: apiModel.thumbnail,
publisherId: apiModel.publisher?.id,
visibility: apiModel.visibility,
draft: apiModel.draft,
likes: apiModel.likes,
views: apiModel.views,
sourceType: apiModel.sourceType,
Expand All @@ -41,7 +40,6 @@ export class VideoEntityMapper extends AbstractMapper<VideoEntity, Video> {
thumbnail: entity.thumbnail,
publisher: this.userEntityMapper.entityToApi(entity.publisher),
visibility: entity.visibility,
draft: entity.draft,
likes: entity.likes,
views: entity.views,
sourceType: entity.sourceType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseModel } from "./base.model";
import { IsBoolean, IsOptional, Matches } from "class-validator";
import { IsOptional, Matches } from "class-validator";
import { Column } from "typeorm";
import { BaseModel } from "./base.model";

export enum Visibility {
PUBLIC = "public",
Expand All @@ -18,9 +18,4 @@ export class ContentModel extends BaseModel {
@IsOptional({ always: true })
@Column({ enum: Visibility, type: "enum", default: Visibility.PUBLIC })
visibility?: Visibility;

@IsBoolean()
@IsOptional({ always: true })
@Column({ default: false })
draft?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ export class VideoEntity extends BaseModel {
@Column({ enum: Visibility, type: "enum", default: Visibility.PUBLIC })
visibility?: Visibility;

@Column({ default: false })
draft?: boolean;

@Column({ enum: VideoSource, type: "enum" })
sourceType: VideoSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
} from "@nestjs/common";
import { MeId, Roles } from "@polyflix/x-utils";
import { Role } from "@polyflix/x-utils/dist/types/roles.enum";
import { VideoService } from "../../services/video.service";
import { VideoApiMapper } from "../../adapters/mappers/video.api.mapper";
import { Span } from "nestjs-otel";
import { VideoParams } from "../../filters/video.params";
import { Paginate } from "../../../../core/types/pagination.dto";
import { VideoResponse } from "../../../application/dto/video-response.dto";
import { Video } from "../../../domain/models/video.model";
import { VideoUpdateDto } from "../../../application/dto/video-update.dto";
import { Video } from "../../../domain/models/video.model";
import { VideoApiMapper } from "../../adapters/mappers/video.api.mapper";
import { VideoParams } from "../../filters/video.params";
import { VideoService } from "../../services/video.service";

@Controller("admin/videos")
@Roles(Role.Admin)
Expand Down Expand Up @@ -69,17 +69,6 @@ export class AdminVideoController {
return this.videoApiMapper.entityToApi(updated_video);
}

@Put(":slug/draft")
@Span("VIDEO_ADMIN_CONTROLLER_TOGGLE_DRAFT_MODE")
async toggleVideoDraftMode(
@Param("slug") slug: string
): Promise<VideoResponse> {
const updated_video = await this.videoService.toggleVideoDraftMode(
slug
);
return this.videoApiMapper.entityToApi(updated_video);
}

@Put(":slug/visibility")
@Span("VIDEO_ADMIN_CONTROLLER_UPDATE_VISIBILITY")
async updateVideoVisibility(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { ClientKafka, EventPattern, Payload } from "@nestjs/microservices";
import { Controller, Logger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { VideoService } from "../services/video.service";
import { ClientKafka, EventPattern, Payload } from "@nestjs/microservices";
import {
InjectKafkaClient,
TriggerType,
PolyflixKafkaValue
PolyflixKafkaValue,
TriggerType
} from "@polyflix/x-utils";
import { UserDto } from "../../application/dto/user.dto";
import { VideoResponse } from "../../application/dto/video-response.dto";
import { UserService } from "../services/user.service";
import { UserDto } from "../../application/dto/user.dto";
import { VideoUpdateDto } from "../../application/dto/video-update.dto";
import { VideoService } from "../services/video.service";

@Controller()
export class MessageVideoController {
Expand Down Expand Up @@ -71,11 +70,7 @@ export class MessageVideoController {
this.videoService.create(videoResponse, null);
break;
case TriggerType.UPDATE:
const videoDTO: VideoUpdateDto = {
...videoResponse,
draft: videoResponse.draft.toString()
};
this.videoService.update(videoResponse.slug, videoDTO);
this.videoService.update(videoResponse.slug, videoResponse);
break;
case TriggerType.DELETE:
this.videoService.delete(videoResponse.slug);
Expand Down
19 changes: 4 additions & 15 deletions src/main/modules/infrastructure/filters/video.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,37 +82,26 @@ export class VideoFilter extends AbstractFilter<VideoEntity> {
}

if (isMe || isAdmin) {
if (has(params, "visibility") || has(params, "draft")) {
if (has(params, "visibility")) {
VideoFilter.buildVisibilityFilters(
queryBuilder,
params.visibility,
params.draft
params.visibility
);
}
} else {
VideoFilter.buildVisibilityFilters(
queryBuilder,
Visibility.PUBLIC,
false
);
VideoFilter.buildVisibilityFilters(queryBuilder, Visibility.PUBLIC);
}
}

private static buildVisibilityFilters(
queryBuilder: SelectQueryBuilder<VideoEntity>,
visibility?: Visibility,
draft?: boolean
visibility?: Visibility
) {
if (visibility != null) {
queryBuilder.andWhere("video.visibility = :visibility", {
visibility
});
}
if (draft != null) {
queryBuilder.andWhere("video.draft = :draft", {
draft
});
}
}

buildPaginationAndSort(
Expand Down
15 changes: 2 additions & 13 deletions src/main/modules/infrastructure/filters/video.params.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { Type } from "class-transformer";
import { IsEnum, IsInt, IsOptional, IsString } from "class-validator";
import { Pagination } from "../../../core/types/pagination.type";
import {
IsBoolean,
IsEnum,
IsInt,
IsOptional,
IsString
} from "class-validator";
import { Visibility } from "../adapters/repositories/entities/content.model";
import { Type } from "class-transformer";

export const DefaultVideoParams: VideoParams = {
page: 1,
Expand All @@ -24,11 +18,6 @@ export class VideoParams extends Pagination {
@IsOptional()
visibility?: Visibility;

@IsBoolean()
@IsOptional()
@Type(() => Boolean)
draft?: boolean;

@IsString()
@IsOptional()
title?: string;
Expand Down
Loading

0 comments on commit be7b828

Please sign in to comment.