Normal-OJ / Back-End

Mozilla Public License 2.0
3 stars 4 forks source link

Homework structure is different for normal users and admins #284

Open laporchen opened 6 months ago

laporchen commented 6 months ago

This is the object normal users got from homework query

{
  "end": 1710604800,
  "id": "65e2e099e55a6f38e62ee9e4",
  "markdown": "Homework #0.5 供同學測試使用,沒有計分,亦不佔用金牌。\n\nIf there is any question, please let us know.\n\nEmail: [algota@noj.tw](mailto:algota@noj.tw)",
  "name": "HW #0.5",
  "problemIds": [
    562
  ],
  "start": 1709395200,
  "studentStatus": {
    "562": {
      "problemStatus": null,
      "score": 0,
      "submissionIds": []
    }
  }
}

And this is what admins got

{
  "end": 1710604800,
  "id": "65e2e099e55a6f38e62ee9e4",
  "markdown": "Homework #0.5 供同學測試使用,沒有計分,亦不佔用金牌。\n\nIf there is any question, please let us know.\n\nEmail: [algota@noj.tw](mailto:algota@noj.tw)",
  "name": "HW #0.5",
  "problemIds": [
    562
  ],
  "start": 1709395200,
  "studentStatus": {
    "40711016e": {
      "562": {
        "problemStatus": null,
        "score": 0,
        "submissionIds": []
      }
    },
    "40747008s": {
      "562": {
        "problemStatus": null,
        "score": 0,
        "submissionIds": []
      }
    },
    // and so on......
  }
}

Currently frontend for homework is using the admin structure for data displaying, which breaks score displaying for normal users.

Proposed solution

I prefer user using the same structure for both roles. We should change the structure for normal user into

{
  "end": 1710604800,
  "id": "65e2e099e55a6f38e62ee9e4",
  "markdown": "Homework #0.5 供同學測試使用,沒有計分,亦不佔用金牌。\n\nIf there is any question, please let us know.\n\nEmail: [algota@noj.tw](mailto:algota@noj.tw)",
  "name": "HW #0.5",
  "problemIds": [
    562
  ],
  "start": 1709395200,
  "studentStatus": {
    "STUDENT_ACCOUNT": {
      "562": {
        "problemStatus": null,
        "score": 0,
        "submissionIds": []
      }
    }
  }
}

By nesting the problems status into their relative username, we could have normal users and admins sharing the same structure for homework object.

Related code

https://github.com/Normal-OJ/Back-End/blob/b82175ab76f6449708c5c7a484b247d61788c117/model/homework.py#L123-L129