0

I have two tables: courses and users. These entities are associated by the @ManyToMany annotation. In the course view (picture below) I have a purple button - after clicking this button, I want to get courses that are associated with users associated with this course (the one in the view). In other words I want to show other courses of this course participants(users). course view

The important thing about this view is that I have all the participant IDs in state(react state). I am sending it as the body of the request because I need to know user IDs to download users courses. I know that it's not good but I have no idea how I can avoid it

Monoxyd
  • 406
  • 1
  • 7
  • 18
  • If it is rest then it might be `/user/{id}/courses` -- the `id` goes in the url. You must not send it in the body of a GET. – Software Engineer Aug 27 '21 at 14:50
  • But this id can be a list? – Monoxyd Aug 27 '21 at 14:58
  • No, but you can call it once per participant and aggregate the results. Or, you can write another API like `/course/{course-id}/participants/other-course` and do the work there. Your server can look up who is on the course then look up the other courses they're booked on, aggregate the results and respond. You don't have to send the list of participants back to the server because it already knows them. – Software Engineer Aug 27 '21 at 15:03
  • "you can call it once per participant" - won't it cause too much round trip time between client and server ? With that in mind, I think your second suggestion is better. – Monoxyd Aug 27 '21 at 17:36
  • The number of requests depends on the length of the course participant list and the volume you expect the site to have. If you have a low-volume site with 4-participants per course, then it shouldn't be a problem. If you are doing this for Coursera then this is a bad idea and the 2nd suggestion is better. – Software Engineer Aug 27 '21 at 17:41
  • I don't know what a "volume" actually is, but since it's just my home project with little data, that's not a problem for me. Anyway, I'll use the more flexible second suggestion just to follow best practices. Thank you :-) – Monoxyd Aug 27 '21 at 17:46
  • Volume is the volume of visitors -- the number of visitors to your site at the same time. You're welcome, good luck with it and if you have any trouble with the code come back and ask more questions. – Software Engineer Aug 27 '21 at 19:08

0 Answers0