简体   繁体   English

如何为同一实体之间的多个关系选择 API 端点?

[英]How to pick API end-points for multiple relationships between the same entities?

I'm having trouble picking end points for two similar queries.我无法为两个类似的查询选择端点。 So my db entities are User and Course, they have 2 relationships between them.所以我的数据库实体是用户和课程,它们之间有 2 个关系。 The first relationship is M to M: A user is learning many courses and a course can be learned by many users.第一个关系是 M 到 M:一个用户正在学习许多课程,而一个课程可以被许多用户学习。 The second relationship is 1 to M: a course can be edited by one user and a user can edit many courses.第二个关系是1到M:一个用户可以编辑一个课程,一个用户可以编辑多个课程。 Now for the API endpoints, I need to get:现在对于 API 端点,我需要得到:

  1. all the courses a user is learning用户正在学习的所有课程
  2. all the courses a user can edit用户可以编辑的所有课程

I can only see /users/me/courses as a potential endpoint, but how do I distinguish between the relationships that I want the query based on in the end-point?我只能将/users/me/courses视为潜在的端点,但是如何区分我希望查询基于端点的关系?

What about:关于什么:

/users/me/editable-courses
/users/me/joined-courses

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM