30 lines
No EOL
776 B
Python
30 lines
No EOL
776 B
Python
from app import app, db
|
|
from models import User, Achievement
|
|
|
|
from flask import request
|
|
from flask_login import current_user, login_required
|
|
|
|
import json
|
|
|
|
@app.route("/users/<id>/add_achievement")
|
|
@login_required
|
|
def add_achievement(id):
|
|
name = request.args.get("name")
|
|
if not name:
|
|
return "No name supplied"
|
|
achievement = Achievement(name=name, achieved_by=id)
|
|
achievement.endorsed_by.append(current_user)
|
|
db.session.add(achievement)
|
|
db.session.commit()
|
|
return "OK"
|
|
|
|
@app.route("/users/<id>")
|
|
def get_user(id):
|
|
user = User.query.filter_by(id=id).first()
|
|
if not user:
|
|
return "{}"
|
|
return json.dumps(user.to_obj())
|
|
|
|
@app.route("/users/")
|
|
def all_users():
|
|
return json.dumps([user.to_obj() for user in User.query.all()]) |