Skip to content

Commit

Permalink
#fix: thuanvv fix response routes
Browse files Browse the repository at this point in the history
  • Loading branch information
VanThuan76 committed Jan 10, 2025
1 parent 66bc54f commit 68ba11c
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 84 deletions.
23 changes: 6 additions & 17 deletions src/web/routes/classes.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { FastifyRequest } from 'fastify';

import { makeClassessUseCases } from '@application/classes';
import ResponseBase from '@application/common/response-base';

interface ListHightlightClassesQuery {
language: string
size?: number
page?: number
}

interface ListShortClassesQuery {
language: string
}
import { ListHightlightClassesQuery } from '@application/classes/queries/list-highlight-classes';
import { GetClassByIdQuery } from '@application/classes/queries/get-class-by-id';
import { ListShortClassesQuery } from '@application/classes/queries/list-short-classes';

interface GetClassByIdQuery {
language: string
id: number
}
import ResponseBase from '@application/common/response-base';

export default async function classRoutes(fastify: FastifyRouteInstance) {
const classes = makeClassessUseCases(fastify.diContainer.cradle);
Expand Down Expand Up @@ -45,7 +34,7 @@ export default async function classRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
title: { type: 'string' },
name: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
image: { type: 'string' },
Expand Down Expand Up @@ -130,7 +119,7 @@ export default async function classRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
title: { type: 'string' },
name: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
image: { type: 'string' },
Expand Down
8 changes: 2 additions & 6 deletions src/web/routes/components.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { FastifyRequest } from 'fastify';

import { makeComponentsUseCases } from '@application/components';
import { GetBySectionQuery } from '@application/components/queries/get-by-section';
import ResponseBase from '@application/common/response-base';

interface ListComponentsByPageQuery {
language: string
section_id: string
}

export default async function componentRoutes(fastify: FastifyRouteInstance) {
const components = makeComponentsUseCases(fastify.diContainer.cradle);

Expand Down Expand Up @@ -60,7 +56,7 @@ export default async function componentRoutes(fastify: FastifyRouteInstance) {
tags: ['sections'],
},
async handler(
req: FastifyRequest<{ Body: ListComponentsByPageQuery }>,
req: FastifyRequest<{ Body: GetBySectionQuery }>,
res
) {
try {
Expand Down
5 changes: 1 addition & 4 deletions src/web/routes/document-types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { FastifyRequest } from 'fastify';

import { makeDocumentTypesUseCases } from '@application/document-types';
import { ListDocumentTypesQuery } from '@application/document-types/queries/list-document-types';
import ResponseBase from '@application/common/response-base';

interface ListDocumentTypesQuery {
language: string
}

export default async function documentTypeRoutes(fastify: FastifyRouteInstance) {
const documentTypes = makeDocumentTypesUseCases(fastify.diContainer.cradle);

Expand Down
95 changes: 81 additions & 14 deletions src/web/routes/documents.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { FastifyRequest } from 'fastify';

import { GetByIdQuery } from '@application/documents/queries/get-by-id';
import { GetByDocumentTypeQuery } from '@application/documents/queries/get-by-document-type';
import { makeDocumentsUseCases } from '@application/documents';
import ResponseBase from '@application/common/response-base';

interface ListDocumentsQuery {
language: string;
document_type_id: number;
size?: number;
page?: number;
}

export default async function documentRoutes(fastify: FastifyRouteInstance) {
const documents = makeDocumentsUseCases(fastify.diContainer.cradle);

Expand All @@ -36,15 +31,13 @@ export default async function documentRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
document_type_id: { type: 'integer' },
title: { type: 'string' },
description: { type: 'string' },
content: { type: 'string' },
image: { type: 'string' },
image_2: { type: 'string' },
image_3: { type: 'string' },
image_4: { type: 'string' },
image_5: { type: 'string' },
image_6: { type: 'string' },
image_7: { type: 'string' },
link_file: { type: 'string' },
downloaded: { type: 'integer' },
order: { type: 'integer' },
status: { type: 'integer' },
created_at: { type: 'string', format: 'date-time' },
Expand All @@ -62,7 +55,7 @@ export default async function documentRoutes(fastify: FastifyRouteInstance) {
tags: ['sections'],
},
async handler(
req: FastifyRequest<{ Body: ListDocumentsQuery }>,
req: FastifyRequest<{ Body: GetByDocumentTypeQuery }>,
res
) {
try {
Expand Down Expand Up @@ -97,4 +90,78 @@ export default async function documentRoutes(fastify: FastifyRouteInstance) {
}
},
});

fastify.route({
method: 'POST',
url: '/api/document/get-by-id',
schema: {
body: {
type: 'object',
properties: {
language: { type: 'string', description: 'Language code (e.g., vi, en, etc.)' },
id: { type: 'string', description: 'ID of records' }
},
required: ['language', 'id'],
},
response: {
200: {
type: 'object',
properties: {
status_code: { type: 'integer', example: 200 },
data: {
type: 'object',
properties: {
id: { type: 'integer' },
document_type_id: { type: 'integer' },
title: { type: 'string' },
description: { type: 'string' },
content: { type: 'string' },
image: { type: 'string' },
link_file: { type: 'string' },
downloaded: { type: 'integer' },
order: { type: 'integer' },
status: { type: 'integer' },
created_at: { type: 'string', format: 'date-time' },
updated_at: { type: 'string', format: 'date-time' },
created_by: { type: 'string' },
updated_by: { type: 'string' },
},
},
message: { type: 'string', example: 'Components fetched successfully' },
},
},
400: { $ref: 'ExceptionResponse#' },
},
tags: ['sections'],
},
async handler(
req: FastifyRequest<{ Body: GetByIdQuery }>,
res
) {
try {
const data = await documents.queries.getById({
language: req.body.language,
id: req.body.id,
});

const response = ResponseBase.formatBaseResponse(
200,
data,
'Document fetched successfully',
);

res.status(200).send(response);
} catch (error) {
fastify.log.error(error);

const errorResponse = ResponseBase.formatBaseResponse(
400,
null,
'Failed to fetch document',
);

res.status(400).send(errorResponse);
}
},
});
}
18 changes: 10 additions & 8 deletions src/web/routes/feedbacks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { FastifyRequest } from 'fastify';

import { makeFeedbacksUseCases } from '@application/feedbacks';
import { ListFeedbacksQuery } from '@application/feedbacks/queries/list-feedbacks';
import ResponseBase from '@application/common/response-base';
interface ListFeedbacksByPageQuery {
language: string
size?: number
page?: number
}

export default async function feedbackRoutes(fastify: FastifyRouteInstance) {
const feedbacks = makeFeedbacksUseCases(fastify.diContainer.cradle);
Expand Down Expand Up @@ -35,10 +31,16 @@ export default async function feedbackRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
title: { type: 'string' },
name: { type: 'string' },
address: { type: 'string' },
avatar: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
image: { type: 'string' },
image_2: { type: 'string' },
image_3: { type: 'string' },
image_4: { type: 'string' },
image_5: { type: 'string' },
image_6: { type: 'string' },
order: { type: 'integer' },
status: { type: 'integer' },
created_at: { type: 'string', format: 'date-time' },
Expand All @@ -60,7 +62,7 @@ export default async function feedbackRoutes(fastify: FastifyRouteInstance) {
tags: ['classes'],
},
async handler(
req: FastifyRequest<{ Body: ListFeedbacksByPageQuery }>,
req: FastifyRequest<{ Body: ListFeedbacksQuery }>,
res
) {
try {
Expand Down
5 changes: 1 addition & 4 deletions src/web/routes/lecture-types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { FastifyRequest } from 'fastify';

import { makeLectureTypesUseCases } from '@application/lecture-types';
import { ListLectureTypesQuery } from '@application/lecture-types/queries/list-lecture-types';
import ResponseBase from '@application/common/response-base';

interface ListLectureTypesQuery {
language: string
}

export default async function lectureTypeRoutes(fastify: FastifyRouteInstance) {
const lectureTypes = makeLectureTypesUseCases(fastify.diContainer.cradle);

Expand Down
13 changes: 4 additions & 9 deletions src/web/routes/lecturers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { FastifyRequest } from 'fastify';

import { makeLecturersUseCases } from '@application/lecturers';
import { ListLecturersQuery } from '@application/lecturers/queries/list-lecturers';
import ResponseBase from '@application/common/response-base';

interface ListLecturersByPageQuery {
language: string
size?: number
page?: number
}

export default async function lecturerRoutes(fastify: FastifyRouteInstance) {
const lecturers = makeLecturersUseCases(fastify.diContainer.cradle);

Expand Down Expand Up @@ -36,10 +31,10 @@ export default async function lecturerRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
name: { type: 'string' },
avatar: { type: 'string' },
title: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
image: { type: 'string' },
order: { type: 'integer' },
status: { type: 'integer' },
created_at: { type: 'string', format: 'date-time' },
Expand All @@ -61,7 +56,7 @@ export default async function lecturerRoutes(fastify: FastifyRouteInstance) {
tags: ['classes'],
},
async handler(
req: FastifyRequest<{ Body: ListLecturersByPageQuery }>,
req: FastifyRequest<{ Body: ListLecturersQuery }>,
res
) {
try {
Expand Down
10 changes: 8 additions & 2 deletions src/web/routes/lectures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ export default async function lectureRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
lecture_type_id: { type: 'integer' },
associcate_link: { type: 'string' },
viewer: { type: 'integer' },
title: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
content: { type: 'string' },
image: { type: 'string' },
order: { type: 'integer' },
status: { type: 'integer' },
Expand Down Expand Up @@ -119,9 +122,12 @@ export default async function lectureRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
lecture_type_id: { type: 'integer' },
associcate_link: { type: 'string' },
viewer: { type: 'integer' },
title: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
content: { type: 'string' },
image: { type: 'string' },
order: { type: 'integer' },
status: { type: 'integer' },
Expand Down
8 changes: 7 additions & 1 deletion src/web/routes/news-categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ export default async function newsCategoryRoutes(fastify: FastifyRouteInstance)
type: 'object',
properties: {
id: { type: 'integer' },
title: { type: 'string' },
name: { type: 'string' },
description: { type: 'string' },
order: { type: 'integer' },
status: { type: 'integer' },
created_at: { type: 'string', format: 'date-time' },
updated_at: { type: 'string', format: 'date-time' },
created_by: { type: 'string' },
updated_by: { type: 'string' },
},
},
},
Expand Down
11 changes: 10 additions & 1 deletion src/web/routes/news.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FastifyRequest } from 'fastify';

import { makeNewsUseCases } from '@application/news';
import ResponseBase from '@application/common/response-base';
import { GetRelatedQuery } from '@application/news/queries/get-related';
import { GetByCategoryQuery } from '@application/news/queries/get-by-category';
import { GetBySlugQuery } from '@application/news/queries/get-by-slug';
import ResponseBase from '@application/common/response-base';

export default async function newsRoutes(fastify: FastifyRouteInstance) {
const news = makeNewsUseCases(fastify.diContainer.cradle);
Expand Down Expand Up @@ -35,6 +35,9 @@ export default async function newsRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
news_category_id: { type: 'integer' },
slug: { type: 'string' },
read_time: { type: 'integer' },
title: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
Expand Down Expand Up @@ -126,6 +129,9 @@ export default async function newsRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
news_category_id: { type: 'integer' },
slug: { type: 'string' },
read_time: { type: 'integer' },
title: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
Expand Down Expand Up @@ -212,6 +218,9 @@ export default async function newsRoutes(fastify: FastifyRouteInstance) {
type: 'object',
properties: {
id: { type: 'integer' },
news_category_id: { type: 'integer' },
slug: { type: 'string' },
read_time: { type: 'integer' },
title: { type: 'string' },
content: { type: 'string' },
description: { type: 'string' },
Expand Down
Loading

0 comments on commit 68ba11c

Please sign in to comment.