Follow / unFollow button in a lsitView populated by a request to a REST Webservice

0

So guys, my question is this:

I have ListView which is popular for a request to my Web service REST. Each item of this ListView has a button. By clicking this button, the user logged in to the application will be able to "follow" or "discontinue" the entity represented in the item (something similar to what happens when you "follow" a profile in Instagram, for example) p>

My question is, how do I keep the status of the button on ListView (if the user is following, type "following", if not type "follow"). Is the best way would I already send whether the user follows that entity in the request itself's response to the Web service that populates the list by manipulating the returned JSON?

I accept suggestions =)

    
asked by anonymous 05.07.2015 / 18:25

1 answer

1

I do not see a problem in already sending in the response of the webservice the status "following" of each item ( true or false , 1 or 0 , or whichever you prefer). Do you see any problems with this?

When the user touches an item's "Follow" or "Unfollow" button), it's up to you to decide how to implement state change. For simplicity you can do a webservice that does toggle state, that is, it switches from one state to another without worrying about the initial state. It is called, checks on the server what the current state is and changes that state, returning the new state so you can update your view .

Or you make a more demanding webservice regarding data consistency: it receives the current state ( true or false ), valid on the server if the state is the same, changes the state, and returns the new status, otherwise returns HTTP 400 - Bad Request , for example).

    
05.07.2015 / 22:02