stablediffusionapi / post_methods.py
yusufgundogdu's picture
Update post_methods.py
ddba67b verified
raw
history blame
844 Bytes
from flask import jsonify, request
from database import get_db
def add_user():
"""Yeni kullanıcı ekler"""
try:
if not request.json or "name" not in request.json:
return jsonify({"error": "İsim zorunlu alan"}), 400
db = get_db()
cursor = db.cursor()
cursor.execute(
'INSERT INTO users (name, score) VALUES (?, ?)',
(request.json["name"], request.json.get("score", 0))
)
db.commit()
return jsonify({
"message": "Kullanıcı eklendi",
"user": {
"id": cursor.lastrowid,
"name": request.json["name"],
"score": request.json.get("score", 0)
}
}), 201
except Exception as e:
return jsonify({"error": str(e)}), 500