jacob-macleod / Dolphin-Flashcard-App

http://www.dolphinflashcards.com
MIT License
1 stars 3 forks source link

get-flashcard endpoint is returning None, regardless of given data #93

Closed jaymeklein closed 3 months ago

jaymeklein commented 3 months ago

I was starting to test the /api/get-flashcard endpoint, which is returning None regardless of given data: Valid data json:

valid_data = {
    "userID": "1",
    "flashcardName": "My new set"
}

And this is is the current data in data.json:

{
  "users": {
    "1": {
      "userID": "1",
      "name": "Dummy",
      "statistics": {
        "streak": "0",
        "totalXP": "0",
        "weeklyXP": "0",
        "lastStreak": "03/03/2024"
      },
      "heatmapData": {},
      "flashcards": {
        "109048371178679571656833207928626960824600184952382683242495299362286693266526": {
          "flashcardID": "109048371178679571656833207928626960824600184952382683242495299362286693266526",
          "flashcardName": "My new set",
          "flashcardDescription": "This is\nmy description",
          "cards": [
            {
              "front": "Front 1",
              "back": "Back 1",
              "reviewStatus": "0.0",
              "lastReview": "01/01/1969"
            },
            {
              "front": "Front 2",
              "back": "Back 2",
              "reviewStatus": "0.0",
              "lastReview": "01/01/1969"
            }
          ]
        }
      }
    }
  }
}

This is the path argument passed in Database.get method: /users/1/flashcards/109048371178679571656833207928626960824600184952382683242495299362286693266526

The LocalDatabase.get method returns the expected data:

{
  "flashcardID": "109048371178679571656833207928626960824600184952382683242495299362286693266526",
  "flashcardName": "My new set",
  "flashcardDescription": "This is\nmy description",
  "cards": [
    {
      "front": "Front 1",
      "back": "Back 1",
      "reviewStatus": "0.0",
      "lastReview": "01/01/1969"
    },
    {
      "front": "Front 2",
      "back": "Back 2",
      "reviewStatus": "0.0",
      "lastReview": "01/01/1969"
    }
  ]
}

But when it comes to the Database.get method, his return is always None.

I changed the line 126 from return jsonify(db.get("/users/" + user_id + "/flashcards/" + flashcard_id)) in two different lines, just for purpose of debugging:

data = db.get("/users/" + user_id + "/flashcards/" + flashcard_id)
return jsonify(data)

Does the data value from db.get shouldn't be the same as LocalDatabase.get?

After adding the return statement to the Database.get method, the endpoint properly returned the requested data.

Should i keep this change for the next commit?

jacob-macleod commented 3 months ago

Yeah, you can keep that change. By, "After adding the return statement to the Database.get method, the endpoint properly returned the requested data", do you mean changing the following section of code in backend/database/database.py: From:

    def get(self, path):
        """ Get data from database """
        self.db.get(path)

To:

    def get(self, path):
        """ Get data from database """
        return self.db.get(path)

Or do you mean splitting line 126 into two lines as you mentioned before?

jaymeklein commented 3 months ago

First option. The change on line 126 was just for debugging purposes. The change that actually solved the problem was the return statement on these lines, as you said:

return self.db.get(path)

Should i mention this issue on my future api-testing PR? Or should i open a PR just for this change?

jacob-macleod commented 3 months ago

You can mention it in the future PR... there's probably less need to make a PR for that one thing just yet