Skip to content

Commit

Permalink
OV-52: + merge
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiy4 committed Aug 28, 2024
2 parents 70f9652 + eff3c86 commit 9c5488e
Show file tree
Hide file tree
Showing 36 changed files with 777 additions and 16 deletions.
10 changes: 5 additions & 5 deletions backend/src/bundles/users/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Entity } from '~/common/types/types.js';

class UserEntity implements Entity {
private 'id': number | null;
private 'id': string | null;

private 'email': string;

Expand All @@ -18,7 +18,7 @@ class UserEntity implements Entity {
passwordHash,
passwordSalt,
}: {
id: number | null;
id: string | null;
email: string;
fullName: string;
passwordHash: string;
Expand All @@ -38,7 +38,7 @@ class UserEntity implements Entity {
passwordHash,
passwordSalt,
}: {
id: number;
id: string;
email: string;
fullName: string;
passwordHash: string;
Expand Down Expand Up @@ -74,12 +74,12 @@ class UserEntity implements Entity {
}

public toObject(): {
id: number;
id: string;
email: string;
fullName: string;
} {
return {
id: this.id as number,
id: this.id as string,
email: this.email,
fullName: this.fullName,
};
Expand Down
1 change: 1 addition & 0 deletions backend/src/bundles/videos/enums/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { VideosApiPath, VideoValidationMessage } from 'shared';
7 changes: 7 additions & 0 deletions backend/src/bundles/videos/types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export {
type CreateVideoRequestDto,
type UpdateVideoRequestDto,
type VideoGetAllItemResponseDto,
type VideoGetAllResponseDto,
type VideoGetOneRequestDto,
} from 'shared';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
createVideoValidationSchema,
updateVideoValidationSchema,
} from 'shared';
316 changes: 316 additions & 0 deletions backend/src/bundles/videos/video.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
import { type VideoService } from '~/bundles/videos/video.service.js';
import {
type ApiHandlerOptions,
type ApiHandlerResponse,
BaseController,
} from '~/common/controller/controller.js';
import { ApiPath } from '~/common/enums/enums.js';
import { HttpCode } from '~/common/http/http.js';
import { type Logger } from '~/common/logger/logger.js';

import { VideosApiPath } from './enums/enums.js';
import {
type CreateVideoRequestDto,
type UpdateVideoRequestDto,
type VideoGetOneRequestDto,
} from './types/types.js';
import {
createVideoValidationSchema,
updateVideoValidationSchema,
} from './validation-schemas/validation-schemas.js';

/**
* @swagger
* components:
* schemas:
* Video:
* type: object
* properties:
* id:
* type: string
* format: uuid
* userId:
* type: string
* format: uuid
* name:
* type: string
* url:
* type: string
* format: url
*/
class VideoController extends BaseController {
private videoService: VideoService;

public constructor(logger: Logger, videoService: VideoService) {
super(logger, ApiPath.VIDEOS);

this.videoService = videoService;

this.addRoute({
path: VideosApiPath.ROOT,
method: 'GET',
handler: () => this.findAll(),
});

this.addRoute({
path: VideosApiPath.ID,
method: 'GET',
handler: (options) =>
this.find(
options as ApiHandlerOptions<{
params: VideoGetOneRequestDto;
}>,
),
});

this.addRoute({
path: VideosApiPath.ROOT,
method: 'POST',
validation: {
body: createVideoValidationSchema,
},
handler: (options) =>
this.create(
options as ApiHandlerOptions<{
body: CreateVideoRequestDto;
}>,
),
});

this.addRoute({
path: VideosApiPath.ID,
method: 'PATCH',
validation: {
body: updateVideoValidationSchema,
},
handler: (options) =>
this.update(
options as ApiHandlerOptions<{
params: VideoGetOneRequestDto;
body: UpdateVideoRequestDto;
}>,
),
});

this.addRoute({
path: VideosApiPath.ID,
method: 'DELETE',
handler: (options) =>
this.delete(
options as ApiHandlerOptions<{
params: VideoGetOneRequestDto;
}>,
),
});
}

/**
* @swagger
* /videos:
* get:
* description: Get all videos
* responses:
* 200:
* description: Successful operation
* content:
* application/json:
* schema:
* type: object
* properties:
* items:
* type: array
* description: A list of video objects
* items:
* $ref: '#/components/schemas/Video'
*/

private async findAll(): Promise<ApiHandlerResponse> {
return {
status: HttpCode.OK,
payload: await this.videoService.findAll(),
};
}

/**
* @swagger
* /videos/{id}:
* get:
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* description: The video id
* description: Get video by id
* responses:
* 200:
* description: Successful operation
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Video'
* 404:
* description: Failed operation. The resource was not found.
* content:
* application/json:
* schema:
* type: object
* $ref: '#/components/schemas/Error'
*/

private async find(
options: ApiHandlerOptions<{
params: VideoGetOneRequestDto;
}>,
): Promise<ApiHandlerResponse> {
return {
status: HttpCode.OK,
payload: await this.videoService.find(options.params.id),
};
}

/**
* @swagger
* /videos:
* post:
* description: Create new video
* requestBody:
* description: Video data
* required: true
* content:
* application/json:
* schema:
* type: object
* required: [userId, name, url]
* properties:
* userId:
* type: string
* format: uuid
* name:
* type: string
* url:
* type: string
* format: url
* responses:
* 201:
* description: Successful operation
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Video'
*/

private async create(
options: ApiHandlerOptions<{
body: CreateVideoRequestDto;
}>,
): Promise<ApiHandlerResponse> {
return {
status: HttpCode.CREATED,
payload: await this.videoService.create(options.body),
};
}

/**
* @swagger
* /videos/{id}:
* patch:
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* description: The video id
* description: Update video by id
* requestBody:
* description: Video data
* content:
* application/json:
* schema:
* type: object
* properties:
* userId:
* type: string
* format: uuid
* name:
* type: string
* url:
* type: string
* format: url
* responses:
* 200:
* description: Successful operation
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Video'
* 404:
* description: Failed operation. The resource was not found.
* content:
* application/json:
* schema:
* type: object
* $ref: '#/components/schemas/Error'
*/

private async update(
options: ApiHandlerOptions<{
params: VideoGetOneRequestDto;
body: UpdateVideoRequestDto;
}>,
): Promise<ApiHandlerResponse> {
return {
status: HttpCode.OK,
payload: await this.videoService.update(
options.params.id,
options.body,
),
};
}

/**
* @swagger
* /videos/{id}:
* delete:
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* description: The video id
* description: Delete video by id
* responses:
* 200:
* description: Successful operation
* content:
* application/json:
* schema:
* type: boolean
* 404:
* description: Failed operation. The resource was not found.
* content:
* application/json:
* schema:
* type: object
* $ref: '#/components/schemas/Error'
*/

private async delete(
options: ApiHandlerOptions<{
params: VideoGetOneRequestDto;
}>,
): Promise<ApiHandlerResponse> {
return {
status: HttpCode.OK,
payload: await this.videoService.delete(options.params.id),
};
}
}

export { VideoController };
Loading

0 comments on commit 9c5488e

Please sign in to comment.