fenya123 / forum123

Flask application written for educational purposes.
http://193.124.115.171/
1 stars 1 forks source link

107: Add REST endpoint to get list of topics #108

Closed EugeneTurkin closed 1 year ago

EugeneTurkin commented 1 year ago

We are going to add REST API interface to our forum, and we decided to begin with creating endpoints without authentication. It won't be secure but it will make development process easier. We will add authentication to these endpoints in the future.

We need an endpoint which will return the list of topics with abitily to sort results. Sorting will be specified via order_by query parameter. order_by should accept a string with two words separated by comma. First word is the name of the sorting field (only created_at, title are acceptable for now). Second word is the sorting direction (asc or desc). If there were no order_by provided, then return topics ordered by created_at ascending.

Request example:

GET /api/topics?order_by=created_at,desc

Response example:

[
    {
        "id": 12,
        "authorId": 21,
        "createdAt": "2023-04-08 19:51:43.986889".
        "description": "Some topic description",
        "title": "Some topic title"
    },
    {
        "id": 10,
        "authorId": 1,
        "createdAt": "2023-04-08 19:51:37.503064",
        "description": "Another topic description",
        "title": "Another topic title"
    }
]

So in the scope of this task we need to create an endpoint GET /api/topics which will return list of topics info in json format, or 400 if request is not valid.

birthdaysgift commented 1 year ago

Will change branch name and create another PR.