D
D
Dmitry Samoilov2021-11-29 22:25:02
Backend
Dmitry Samoilov, 2021-11-29 22:25:02

How is adding an article to favorites implemented?

Hello, I don’t know which tag this question belongs to, I wonder how it works in general. I am now making a news site, writing in react and express. There, the user will have the ability to add articles to favorites, I seem to understand how to implement this, but I would like to clarify with knowledgeable people, so I want to get answers to a few questions

1) Do I need to add selected articles to the user's scheme on the backend?

2) How does adding on the front work? when you click, you change the user's favorites by adding this article there, and when you click again, make another deletion request?

It seems to be all questions, I did not often implement this function, so I would like to get advice from knowledgeable people

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Dubrovin, 2021-11-30
@distCom

This is how I would implement it.
1) When you click add favorites, you send a request for a back with the id of the news
2) On the back, you process and add this article to your favorites for this user.
When deleting, you just delete the same thing.
You can also drop your favorites to local storage.
We throw a request for backing.
If they do not match, then redraw. Otherwise, we do nothing.
It follows from this
1) Yes, it is necessary. All important data must be stored on the server. And he must be the source of truth.
I mean. If it's like this on the server, it's different on the front. The data from the server is correct.
2) Yes, that's right.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question