Update get_methods.py
Browse files- get_methods.py +24 -3
get_methods.py
CHANGED
|
@@ -8,7 +8,28 @@ def get_users():
|
|
| 8 |
return jsonify([dict(user) for user in users])
|
| 9 |
|
| 10 |
def get_user(udid):
|
| 11 |
-
"""UDID ile kullanıcıyı getirir"""
|
| 12 |
db = get_db()
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return jsonify([dict(user) for user in users])
|
| 9 |
|
| 10 |
def get_user(udid):
|
| 11 |
+
"""UDID ile kullanıcıyı getirir (yoksa oluşturur)"""
|
| 12 |
db = get_db()
|
| 13 |
+
cursor = db.cursor()
|
| 14 |
+
|
| 15 |
+
user = cursor.execute(
|
| 16 |
+
'SELECT * FROM users WHERE udid = ?',
|
| 17 |
+
(udid,)
|
| 18 |
+
).fetchone()
|
| 19 |
+
|
| 20 |
+
if user:
|
| 21 |
+
return jsonify(dict(user))
|
| 22 |
+
|
| 23 |
+
# Kullanıcı yoksa otomatik oluştur
|
| 24 |
+
cursor.execute(
|
| 25 |
+
'INSERT INTO users (udid, name, premium_account, usage_limit, invoice) VALUES (?, ?, ?, ?, ?)',
|
| 26 |
+
(udid, 'guest', False, 3, 'empty')
|
| 27 |
+
)
|
| 28 |
+
db.commit()
|
| 29 |
+
|
| 30 |
+
new_user = cursor.execute(
|
| 31 |
+
'SELECT * FROM users WHERE udid = ?',
|
| 32 |
+
(udid,)
|
| 33 |
+
).fetchone()
|
| 34 |
+
|
| 35 |
+
return jsonify(dict(new_user)), 201
|