Hi all, Sorry for the inconvenience. The methods that I have already implemented are not visible in the above mail. Check below for the methods.
[image: Capture.PNG] Thanks! On Sat, Oct 27, 2018 at 12:00 PM Wasura Wattearachchi <[email protected]> wrote: > Hi all, > > This is related to the mail thread subjected as “[Architecture] Project > 240: Communication channel between API Providers and API Consumers”. > Currently, I use below methods to manage comments in the back-end. > > [image: image.png] > > To list the comments in UI, I use *GET /apis/{apiId}/comments* function. > So the comments can be listed down as follows. > > > But in here, both comments and replies will be listed in one level. But > for each comment, we need another level to list down the replies like > below. > > > If I use above GET method, I will get an array of comments as the response > and each array element will consist a comment (or a reply) with the fields > (column names as attributes) from the database table. > So, to list down the comments I used a loop and to list down the replies > by checking whether what are the comments which have the parentCommentId of > the parent comment. > > *Pseudocode* > >> commentList = call GET /apis/{apiId}/comments >> For each comment in commentList{ >> Display comment; >> If (comment[parentCommentId] != null){ >> For each commentReply in commentList{ >> If (comment[parentCommentId] == >> commentReply[parentCommentId]){ >> Display commentReply; >> } >> } >> } >> } > > > IMHO, I think above approach of using 2 nested loops is not efficient. So, > how about we use another GET method to get the comments which have a > particular parentCommentId and use it instead of the second loop? (check > the method in red colour) > > *Pseudocode* > >> commentList = call GET /apis/{apiId}/comments >> For each comment in commentList{ >> Display comment; >> If (comment[parentCommentId] != null){ >> replyList = call GET /apis/{apiId}/comments/{parentCommentId} >> For each commentReply in replyList{ >> Display commentReply; >> } >> } >> } > > > But the drawback in here is that there will be two database calls when > listing a single comment with replies. > What do you think about this? > > Thank you! > > -- > Wasura Wattearachchi | Software Engineer Intern | WSO2 Inc. > (m) +94775396038 | (e) [email protected] > <http://wso2.com/signature> > -- Wasura Wattearachchi | Software Engineer Intern | WSO2 Inc. (m) +94775396038 | (e) [email protected] <http://wso2.com/signature>
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
