Add /get_quest, /get_side_quest
This commit is contained in:
parent
2a5ae51d71
commit
aa0b388126
46
server.py
46
server.py
|
@ -48,7 +48,7 @@ def player(db):
|
||||||
app.add_url_rule('/player', '/player', lambda: player(db), methods=['GET'])
|
app.add_url_rule('/player', '/player', lambda: player(db), methods=['GET'])
|
||||||
|
|
||||||
|
|
||||||
def objectify(quest):
|
def dictify_quest(quest):
|
||||||
return {
|
return {
|
||||||
"id": quest.QID,
|
"id": quest.QID,
|
||||||
"name": quest.name,
|
"name": quest.name,
|
||||||
|
@ -63,7 +63,7 @@ def get_quests(db):
|
||||||
player = get_player(db)
|
player = get_player(db)
|
||||||
if player is False:
|
if player is False:
|
||||||
return jsonify(errors._401), 401
|
return jsonify(errors._401), 401
|
||||||
quests = list(map(objectify, player.get_quests()))
|
quests = list(map(dictify_quest, player.get_quests()))
|
||||||
return jsonify(quests)
|
return jsonify(quests)
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,9 +76,49 @@ def get_side_quests(db):
|
||||||
player = get_player(db)
|
player = get_player(db)
|
||||||
if player is False:
|
if player is False:
|
||||||
return jsonify(errors._401), 401
|
return jsonify(errors._401), 401
|
||||||
side_quests = list(map(objectify, player.get_side_quests()))
|
side_quests = list(map(dictify_quest, player.get_side_quests()))
|
||||||
return jsonify(side_quests)
|
return jsonify(side_quests)
|
||||||
|
|
||||||
|
|
||||||
app.add_url_rule('/get_side_quests', '/get_side_quests',
|
app.add_url_rule('/get_side_quests', '/get_side_quests',
|
||||||
lambda: get_side_quests(db), methods=['GET'])
|
lambda: get_side_quests(db), methods=['GET'])
|
||||||
|
|
||||||
|
|
||||||
|
# /get_quest
|
||||||
|
def get_quest(db):
|
||||||
|
player = get_player(db)
|
||||||
|
if player is False:
|
||||||
|
return jsonify(errors._401), 401
|
||||||
|
try:
|
||||||
|
qid = request.args['qid']
|
||||||
|
except(KeyError):
|
||||||
|
return jsonify(errors._400), 400
|
||||||
|
|
||||||
|
quest = player.get_quest(qid)
|
||||||
|
if quest is False:
|
||||||
|
return jsonify(errors._404), 404
|
||||||
|
return jsonify(dictify_quest(quest))
|
||||||
|
|
||||||
|
|
||||||
|
app.add_url_rule('/get_quest', '/get_quest', lambda: get_quest(db),
|
||||||
|
methods=['GET'])
|
||||||
|
|
||||||
|
|
||||||
|
# /get_side_quest
|
||||||
|
def get_side_quest(db):
|
||||||
|
player = get_player(db)
|
||||||
|
if player is False:
|
||||||
|
return jsonify(errors._401), 401
|
||||||
|
try:
|
||||||
|
qid = request.args['id']
|
||||||
|
except(KeyError):
|
||||||
|
return jsonify(errors._400), 400
|
||||||
|
|
||||||
|
side_quest = player.get_side_quest(qid)
|
||||||
|
if side_quest is False:
|
||||||
|
return jsonify(errors._404), 404
|
||||||
|
return jsonify(dictify_quest(side_quest))
|
||||||
|
|
||||||
|
|
||||||
|
app.add_url_rule('/get_side_quest', '/get_side_quest',
|
||||||
|
lambda: get_side_quest(db), methods=['GET'])
|
||||||
|
|
Loading…
Reference in New Issue