Update post_methods.py
Browse files- post_methods.py +11 -10
post_methods.py
CHANGED
|
@@ -1,28 +1,29 @@
|
|
| 1 |
from flask import jsonify, request
|
| 2 |
from database import get_db
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
"""Yeni
|
| 6 |
try:
|
| 7 |
-
if not request.json or "
|
| 8 |
-
return jsonify({"error": "
|
| 9 |
|
| 10 |
db = get_db()
|
| 11 |
cursor = db.cursor()
|
| 12 |
cursor.execute(
|
| 13 |
-
'INSERT INTO
|
| 14 |
-
(request.json["
|
| 15 |
)
|
| 16 |
db.commit()
|
| 17 |
|
| 18 |
return jsonify({
|
| 19 |
-
"message": "
|
| 20 |
-
"
|
| 21 |
"id": cursor.lastrowid,
|
| 22 |
-
"
|
| 23 |
-
"score": request.json.get("score", 0)
|
| 24 |
}
|
| 25 |
}), 201
|
| 26 |
|
|
|
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return jsonify({"error": str(e)}), 500
|
|
|
|
| 1 |
from flask import jsonify, request
|
| 2 |
from database import get_db
|
| 3 |
|
| 4 |
+
def add_new_udid():
|
| 5 |
+
"""Yeni UDID ekler"""
|
| 6 |
try:
|
| 7 |
+
if not request.json or "udid" not in request.json:
|
| 8 |
+
return jsonify({"error": "UDID is required"}), 400
|
| 9 |
|
| 10 |
db = get_db()
|
| 11 |
cursor = db.cursor()
|
| 12 |
cursor.execute(
|
| 13 |
+
'INSERT INTO udids (udid) VALUES (?)',
|
| 14 |
+
(request.json["udid"],)
|
| 15 |
)
|
| 16 |
db.commit()
|
| 17 |
|
| 18 |
return jsonify({
|
| 19 |
+
"message": "UDID added",
|
| 20 |
+
"udid": {
|
| 21 |
"id": cursor.lastrowid,
|
| 22 |
+
"udid": request.json["udid"]
|
|
|
|
| 23 |
}
|
| 24 |
}), 201
|
| 25 |
|
| 26 |
+
except sqlite3.IntegrityError:
|
| 27 |
+
return jsonify({"error": "UDID already exists"}), 400
|
| 28 |
except Exception as e:
|
| 29 |
return jsonify({"error": str(e)}), 500
|