Skip to content

Commit

Permalink
Merge pull request #40 from sudeeppr1998/all-1.3-dev
Browse files Browse the repository at this point in the history
API changes in getcontent for mechanics feature
  • Loading branch information
sudeeppr1998 authored Oct 10, 2024
2 parents 95819d0 + e6cbb8a commit 096f7bd
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: DEV DEPLOYMENT

on:
push:
branches: [ all-1.1-dev ]
branches: [ all-1.3-dev ]

jobs:
build:
Expand Down
284 changes: 274 additions & 10 deletions src/controllers/content.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,16 +888,29 @@ export class contentController {
async getContent(@Res() response: FastifyReply, @Body() queryData: any) {
try {
const Batch: any = queryData.limit || 5;
const contentCollection = await this.contentService.search(
queryData.tokenArr,
queryData.language,
queryData.contentType,
parseInt(Batch),
queryData.tags,
queryData.cLevel,
queryData.complexityLevel,
queryData.graphemesMappedObj,
);

let contentCollection;

if(queryData.mechanics_id === undefined){
contentCollection = await this.contentService.search(
queryData.tokenArr,
queryData.language,
queryData.contentType,
parseInt(Batch),
queryData.tags,
queryData.cLevel,
queryData.complexityLevel,
queryData.graphemesMappedObj,
);
}else{
contentCollection = await this.contentService.getMechanicsContentData(
queryData.contentType,
queryData.mechanics_id,
parseInt(Batch),
queryData.language
);
}

return response.status(HttpStatus.CREATED).send({
status: 'success',
data: contentCollection,
Expand Down Expand Up @@ -1231,4 +1244,255 @@ export class contentController {
deleted,
});
}

@ApiExcludeEndpoint(true)
@ApiBody({
description: 'Request body parameters for get content',
required: true,
schema: {
type: 'object',
properties: {
tokenArr: {
type: 'array',
description: 'Array of tokens',
items: {
type: 'string',
example: 'c'
}
},
language: {
type: 'string',
description: 'Language code',
example: 'en'
},
contentType: {
type: 'string',
description: 'Type of content',
example: 'Word'
},
limit: {
type: 'number',
description: 'Limit on the number of items',
example: 5
},
cLevel: {
type: 'string',
description: 'Content level',
example: 'L2'
},
complexityLevel: {
type: 'array',
description: 'Array of complexity levels',
items: {
type: 'string',
example: 'C1'
}
},
graphemesMappedObj: {
type: 'object',
description: 'Object mapping graphemes to their representations',
additionalProperties: {
type: 'array',
items: {
type: 'string',
example: 'ch'
}
},
example: {
"c": ["ch"],
"o": ["o"],
"a": ["a"],
"v": ["v", "ve"],
"w": ["w", "wh"],
"æ": ["a", "ai", "au"],
"n": ["n"],
"i": ["i"],
"θ": ["th"]
}
}
}
}
})
@ApiResponse({
status: 200,
description: 'Successful response',
schema: {
type: 'object',
properties: {
status: { type: 'string', example: 'success' },
data: {
type: 'object',
properties: {
wordsArr: {
type: 'array',
items: {
type: 'object',
properties: {
_id: { type: 'string', example: '660f9545367a62b3902dd58b' },
contentId: { type: 'string', example: 'f8dd7c97-53f7-4676-b597-4a52aaface5c' },
collectionId: { type: 'string', example: '6a519951-8635-4d89-821a-d3eb60f6e1ec' },
name: { type: 'string', example: 'L2_new_3' },
contentType: { type: 'string', example: 'Word' },
contentSourceData: {
type: 'array',
items: {
type: 'object',
properties: {
language: { type: 'string', example: 'en' },
audioUrl: { type: 'string', example: '' },
text: { type: 'string', example: 'five' },
phonemes: {
type: 'array',
items: { type: 'string', example: 'f' }
},
wordCount: { type: 'number', example: 1 },
wordFrequency: {
type: 'object',
additionalProperties: { type: 'number', example: 1 }
},
syllableCount: { type: 'number', example: 4 },
syllableCountMap: {
type: 'object',
additionalProperties: { type: 'number', example: 4 }
},
syllableCountArray: {
type: 'array',
items: {
type: 'object',
properties: {
k: { type: 'string', example: 'five' },
v: { type: 'number', example: 4 }
}
}
}
}
}
},
status: { type: 'string', example: 'live' },
publisher: { type: 'string', example: 'ekstep' },
language: { type: 'string', example: 'en' },
contentIndex: { type: 'number', example: 141 },
tags: {
type: 'array',
items: { type: 'string' }
},
createdAt: { type: 'string', example: '2024-04-05T05:45:55.335Z' },
updatedAt: { type: 'string', example: '2024-04-05T05:45:55.335Z' },
__v: { type: 'number', example: 0 },
matchedChar: {
type: 'array',
items: { type: 'string', example: 'v' }
}
}
}
},
contentForToken: {
type: 'object',
additionalProperties: {
type: 'array',
items: {
type: 'object',
properties: {
_id: { type: 'string', example: '660f9545367a62b3902dd58b' },
contentId: { type: 'string', example: 'f8dd7c97-53f7-4676-b597-4a52aaface5c' },
collectionId: { type: 'string', example: '6a519951-8635-4d89-821a-d3eb60f6e1ec' },
name: { type: 'string', example: 'L2_new_3' },
contentType: { type: 'string', example: 'Word' },
contentSourceData: {
type: 'array',
items: {
type: 'object',
properties: {
language: { type: 'string', example: 'en' },
audioUrl: { type: 'string', example: '' },
text: { type: 'string', example: 'five' },
phonemes: {
type: 'array',
items: { type: 'string', example: 'f' }
},
wordCount: { type: 'number', example: 1 },
wordFrequency: {
type: 'object',
additionalProperties: { type: 'number', example: 1 }
},
syllableCount: { type: 'number', example: 4 },
syllableCountMap: {
type: 'object',
additionalProperties: { type: 'number', example: 4 }
},
syllableCountArray: {
type: 'array',
items: {
type: 'object',
properties: {
k: { type: 'string', example: 'five' },
v: { type: 'number', example: 4 }
}
}
}
}
}
},
status: { type: 'string', example: 'live' },
publisher: { type: 'string', example: 'ekstep' },
language: { type: 'string', example: 'en' },
contentIndex: { type: 'number', example: 141 },
tags: {
type: 'array',
items: { type: 'string' }
},
createdAt: { type: 'string', example: '2024-04-05T05:45:55.335Z' },
updatedAt: { type: 'string', example: '2024-04-05T05:45:55.335Z' },
__v: { type: 'number', example: 0 },
matchedChar: {
type: 'array',
items: { type: 'string', example: 'v' }
}
}
}
}
}
}
}
}
}
})
@ApiResponse({
status: 500,
description: 'Error while fetching data from the content table',
schema: {
type: 'object',
properties: {
status: { type: 'string', example: 'error' },
msg: { type: 'string', example: 'Server error - error message' },
},
},
})
@ApiOperation({
summary: 'Get all data from the content table'
})
@Get('/getMeachnicsContent')
async getMechanicsContent(
@Res() response: FastifyReply,
@Query('contentType') contentType: string,@Query('mechanics_id') mechanics_id: string, @Query() { contentlimit = 5 }, @Query('language') language: string
) {
try {
const Batch: any = contentlimit || 5;
const contentCollection = await this.contentService.getMechanicsContentData(
contentType,
mechanics_id,
Batch,
language
);
return response.status(HttpStatus.CREATED).send({
status: 200,
contentCollection,
});
} catch (error) {
return response.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
status: 500,
message: 'Server error - ' + error,
});
}
}
}
11 changes: 8 additions & 3 deletions src/schemas/content.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ export class content {
@Prop({ required: false, type: Array })
@IsOptional()
@IsArray()
mechnics_data: [
mechanics_data: [
{
mechnics_id: string;
mechanics_id: string;
language:string;
jumbled_text: string;
text: string;
audio_url: string;
image_url: string;
options: [
{
text: string;
Expand All @@ -52,7 +57,7 @@ export class content {
};
time_limit: number;
correctness: {
"50%": [String],
"50%": [string],
}
}
];
Expand Down
33 changes: 33 additions & 0 deletions src/services/content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,4 +1621,37 @@ export class contentService {
return [];
}
}

async getMechanicsContentData(
contentType,
mechanics_id,
limit = 5,
language
) {

const wordsArr = await this.content.aggregate([
{
$match: {
contentType: contentType,
language: language,
mechanics_data: {
$elemMatch: { mechanics_id: mechanics_id, language: language}
}
}
},
{ $sample: { size: limit } },
]);

wordsArr.map((content) => {
const { mechanics_data } = content;
const mechanicData = mechanics_data.find(
(mechanic) => {return mechanic.mechanics_id === mechanics_id}
);
content.mechanics_data = [];
content.mechanics_data.push(mechanicData);
return content;
});

return { wordsArr: wordsArr };
}
}

0 comments on commit 096f7bd

Please sign in to comment.