Overview
Need of Batch status attribute in response of {{url}}/course/v1/user/enrollment/list/{{userId}} API for each batch in which user is enrolled.
Terminology :
- Metadata : This term refers the data related to course batch which will be added in response specifically in batchMetaData.
- Standard supported Metadata : This term refers the standard data which will be provided irrespective of the query parameter for "batchDetails". For example we can consider batchName, batchStartDate,bacthEndDate as standard metadata for batchDetails.
- Standard supported fields : This term refers field which are supported by API to get in "batchMetaData " map . Standard supported fields can be the fields which exist in course batch objects and are not sensitive for exposure.
Approaches
Approach 1
API will accept a new query parameter as batchDetails=status and based on that it will add batch status inside response.
Pros | Cons |
---|---|
Separation of the query param. Ex: OrgDetails is for org and batchDetails is for batch | |
response will have separate metadata as "batchMetaData", So that later we can add more attribute. |
Solution:
Implementation details :
- Before returning the response , we will iterate over courses objects.
- Get batchId and call API to get batch Details.
- create and populate batchMetaData Map with the requested metadata attributes.
- Append it to the coursesObject.
- Do it for all courses Object.
- return the response.
API to get user course enrollment list
Get ../course/v1/user/enrollment/list/{{userId}}&orgdetails=name,status&batchDetails=name,startDate,EndDate,status.
Resopnse :
{ "id": "api.user.courses.list", "ver": "v1", "ts": "2018-11-15 09:17:31:909+0000", "params": { "resmsgid": null, "msgid": "9db786d3-45c2-447d-b657-f9768da15652", "err": null, "status": "success", "errmsg": null }, "responseCode": "OK", "result": { "courses": [ { "dateTime": "2018-07-04 09:31:22:294+0000", "status": 1, ... "batchMetaData": { "name": "batchName", "startDate": "2018-01-02", "endDate": "2018-01-22", "status": "1" } }, { ... } } ] } }
Approach 2
Not accepting any attribute value in request parameters , returning standard supported fields for the course batches in which user is enrolled.
Pros | Cons |
---|---|
|
|
|
|
Solution:
Implementation details :
- Before returning the response , we will iterate over courses objects.
- Get batchId and call API to get batch Details.
- Create and populate batchMetaData Map with the standard supported metadata fields.
- Standard metadata fields can be cached in DataCacheHandler . DataCacheHandler will be initialized from a database query from cassandra.
- Using cassandra will give us freedom to add or remove fields from standard metadata fields.
- Append it to the coursesObject.
- Do it for all courses Object.
- Return the response.
Instead of making API call for getting batchDetails on at a time we can do it by sending list of coursebatchIds so only one API call will be there but it can increase complexity of code and performance also.
API to get user course enrollment list
Get ../course/v1/user/enrollment/list/{{userId}}?orgDetails=orgName
Response :
{ "id": "api.user.courses.list", "ver": "v1", "ts": "2018-11-15 09:17:31:909+0000", "params": { "resmsgid": null, "msgid": "9db786d3-45c2-447d-b657-f9768da15652", "err": null, "status": "success", "errmsg": null }, "responseCode": "OK", "result": { "courses": [ { "dateTime": "2018-07-04 09:31:22:294+0000", ... "batchMetaData": { "name": "batchName", "startDate": "2018-01-02", "endDate": "2018-01-22", "status": "1", } }, { } ] } }
Approach 3
Accepting attributes in request parameters and also providing standard metadata. If request parameter contains any other attribute different from standard meta data , the meta data map will also have the requested attributes with standard meta data.
Pros | Cons |
---|---|
|
|
|
|
Solution
API to get user course enrollment list
1.Get ../course/v1/user/enrollment/list/{{userId}}?orgDetails=name response will same as approach 2 in which only standard meta data will be return as no other attribute is mentioned in this request.
2. Get ../course/v1/user/enrollment/list/{{userId}}?orgDetails=name,status&batchDetails=name,someUnsupportedField. Here we already have batch start date , end date and status is standard meta data.
Implementation details :
- Before returning the response , we will iterate over courses objects.
- Get batchId and call API to get batch Details.
- Create and populate batchMetaData Map with the standard supported metadata fields.
- Standard metadata fields can be cached in DataCacheHandler . DataCacheHandler will be initialized from a database query from cassandra.
- Using cassandra will give us freedom to add or remove fields from standard metadata fields.
- Add the other requested data in the batchMetaData map , if some unsupported field is in request neglect it or put some error message.(NOT_SUPPORTED).
- Append it to the coursesObject.
- Do it for all courses Object.
- Return the response.
Instead of making API call for getting batchDetails on at a time we can do it by sending list of coursebatchIds so only one API call will be there but it can increase complexity of code and performance also.
Responses
{ "id": "api.user.courses.list", "ver": "v1", "ts": "2018-11-15 09:17:31:909+0000", "params": { "resmsgid": null, "msgid": "9db786d3-45c2-447d-b657-f9768da15652", "err": null, "status": "success", "errmsg": null }, "responseCode": "OK", "result": { "courses": [ { "lastReadContentId": "do_21253529011637452811543", "courseId": "do_21253534443347968011561", "status": 1, "batchMetaData" :{ "startDate":"2018-01-02", "endDate":"2018-01-22", "status" :"1", "name":"batchName", "someUnsupportedField":"NOT_SUPPORTED", "someOtherKey": "someOtherValue" } }, { } ] } }