Hi Wasura,
IMO, the response for the GET should be intuitive.
For example:
[
{
"id":"12434",
"comment":"this is a parenth comment",
"timestamp":"xxxxx01",
"replies":[
{
"id":"12435",
"comment":"this is a reply",
"timestamp":"xxxxx02"
},
{
"id":"12436",
"comment":"this is another reply",
"timestamp":"xxxxx03"
}
]
},
{
"id":"12438",
"comment":"this is another parent comment",
"timestamp":"xxxxx02"
}
]
So you will have to write the logic to compose this response at the
backend.
On Sat, Oct 27, 2018 at 12:05 PM Wasura Wattearachchi <[email protected]>
wrote:
> 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.
>
>
> Thanks!
>
> On Sat, Oct 27, 2018 at 12:00 PM Wasura Wattearachchi <[email protected]>
> wrote:
>
>>
>> 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.
>>
>
This also has 2 network calls which is costlier than the 1st case.
Anyway, this will be easiler when you move the logic to the backend as I
suggested above.
Thanks,
Bhathiya
> 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>
>
--
*Bhathiya Jayasekara*
*Technical Lead,*
*WSO2 inc., http://wso2.com <http://wso2.com>*
*Phone: +94715478185*
*LinkedIn: http://www.linkedin.com/in/bhathiyaj
<http://www.linkedin.com/in/bhathiyaj>*
*Twitter: https://twitter.com/bhathiyax <https://twitter.com/bhathiyax>*
*Blog: http://movingaheadblog.blogspot.com
<http://movingaheadblog.blogspot.com/>*
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev