-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
777 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { VideosApiPath, VideoValidationMessage } from 'shared'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
4 changes: 4 additions & 0 deletions
4
backend/src/bundles/videos/validation-schemas/validation-schemas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
createVideoValidationSchema, | ||
updateVideoValidationSchema, | ||
} from 'shared'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.