Skip to content

Homework structure is different for normal users and admins #284

@laporchen

Description

@laporchen

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

Back-End/model/homework.py

Lines 123 to 129 in b82175a

if user.role < 2:
new.update({'studentStatus': homework.student_status})
else:
new.update({
'studentStatus':
homework.student_status.get(user.username)
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions