Rontim / MyCampus-backend

Backend for the MyCampus project
1 stars 0 forks source link

Blog Filtering Endpoints #9

Closed Mirror83 closed 6 months ago

Mirror83 commented 6 months ago

Currently, the get blogs website returns all of the blogs stored in the database. I think that there should be a way to filter them based on criteria such as:

  1. Topic
  2. Author (club or regular)
  3. Date posted
  4. Whether the blog is trending or not (this will require a new table for trending blog posts and topics, or a different way to identify whether a blog or a topic is trending)
  5. Title
  6. Time to read (This will, however, require a new field in the blog table and a way to calculate the expected reading time, so just ignore it for now)

I think that this should be done using query params to the get blogs site as exemplified below:

1. Get blogs of a specific topic

/api/v2/blogs?topic=Health+and+Wellness

2. Get blogs of a particular author.

/api/v2/blogs?author=glen - The value to the author param could be the username of the author

3. Get blogs by date.

This could be though about in different ways. Maybe it could be done by a specific date:

/api/v2/blogs?date=01/01/2024

Or maybe by tags defining specific time periods: /api/v2/blogs?period=today

/api/v2/blogs?period=last+week, or

/api/v2/blogs?period=last+month e.t.c

Or maybe only by month and year /api/v2/blogs?month=10&year=2023

Or some other mechanism.

4. Get trending blogs

/api/v2/blogs/trending or /api/v2/blogs?trending=true - This would be the same for topics

And the others would be similarly defined. The parameters can also be mixed and matched, for example if one wanted to find a trending blog belonging to a specific author.

Rontim commented 6 months ago

Update

Filtering and Searching

We have decided to use one endpoint for filtering blogs:

The agreed query params are topic, author, period, title

I have added q param for the search term

Trending Topic and Blog

Two dedicated endpoints for each

  1. GET /api/v1/topic/trending/ - A get requests to retrieve trending topics
  2. GET /api/v1/blog/trending/ - A get request to retrieve trending blogs

We will use the likes to determine trending blogs and the number of blogs with a given topic as trending topic