rw-moore / SciLO

GNU General Public License v3.0
0 stars 0 forks source link

Fix: response name and API tests #47

Closed haotianzhu closed 5 years ago

haotianzhu commented 5 years ago

Check List

Comment
  1. change response.name => response.index
  2. response.index will be auto-generated by the order of response in the response list
  3. back-end will send response.index to front-end

I test following URL

  1. GET /api/questions
  2. POST /api/questions
  3. GET/DELETE/PATCH /api/questions/{id}

They are good now

There is a detailed document about Question's URLs in the wiki https://github.com/rw-moore/SciLO/wiki/Question-API

Put 'closes #.' in your comment to auto-close the issue that your PR fixes (if such).

haotianzhu commented 5 years ago

You can always update the whole question byPATCH. Since PATCH is a partially updating method, If you want to set some fields as null, you always need to provide null value. For example, you want to reset question.responses as [ ] you need to

{
...
"responses" : [ ]
...
}

NOTE: you can partially update question. For example, you can

{
"title": "Mock Question 2 new",
}

to change the title only.

BUT for the nested field like TAG, RESPONSE You can partially update the whole RESPONSE field but not a specific sub-field in RESPONSE For example, currently question.tags has two TAG, one is fun another is color. You can

  "tags": [
    {
      "name": "fun new"
    },
    {
      "name": "color"
    }
  ],

to partial update whole question.tags only. 👍

But you can't partially update the tag fun to fun new, even you give the id (id will be ignored)

  "tags": [
    {
     "id": 1,
      "name": "fun new"
    }
  ],

This will make question.tags only contains one tag 👎

@TianqiCS