Commit 9da6ea30 authored by Fence's avatar Fence 🌈

proper output of mongoengine documents,

thought I solved this dumb thing yesterday...
parent 8f81df1d
......@@ -7,7 +7,7 @@ from werkzeug.utils import secure_filename
from mutagen.mp3 import MP3
from minor.decorators import json_required, auth_required
from minor.model import Song
from minor.util import get_ext
from minor.util import get_ext, transform_mongo_dict
@route("/api/music")
class MusicController(FlaskController):
......@@ -46,8 +46,9 @@ class MusicController(FlaskController):
songs = Song.objects.skip(start).limit(limit)
count = Song.objects.count()
# ech mongo_engine is garbage
songs = list(map(lambda x : json.loads(x.to_json()), songs))
# ech mongoengine is garbage
songs_dict_arr = json.loads(songs.to_json())
songs = list(map(lambda x: transform_mongo_dict(x), songs_dict_arr))
# check if songs is empty
if songs:
......@@ -61,7 +62,8 @@ class MusicController(FlaskController):
song = Song.objects.get(id=id)
if song is not None:
return jsonify({"code": 200, "message": "ok", "data": json.loads(song.to_json())}), 200
song = transform_mongo_dict(json.loads(song.to_json()))
return jsonify({"code": 200, "message": "ok", "data": song}), 200
else:
return jsonify({"code": 400, "message": "bad_request"}), 400
......
......@@ -6,3 +6,9 @@ def get_ext(filename):
return filename.rsplit('.', 1)[1].lower()
else:
return None
def transform_mongo_dict(mongo_dict):
mongo_dict["id"] = mongo_dict["_id"]["$oid"]
del mongo_dict["_id"]
return mongo_dict
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment