yusufgundogdu commited on
Commit
3e38b4c
·
verified ·
1 Parent(s): caa5d47

Update get_methods.py

Browse files
Files changed (1) hide show
  1. get_methods.py +23 -7
get_methods.py CHANGED
@@ -2,16 +2,22 @@ from flask import jsonify
2
  from database import get_db
3
 
4
  def get_users():
5
- """Tüm kullanıcıları getirir"""
6
  try:
7
  db = get_db()
8
  users = db.execute('SELECT * FROM users').fetchall()
9
- return jsonify([dict(user) for user in users])
 
 
 
10
  except Exception as e:
11
- return jsonify({"error": str(e)}), 500
 
 
 
12
 
13
  def get_user(udid):
14
- """UDID ile kullanıcıyı getirir (yoksa oluşturur)"""
15
  try:
16
  db = get_db()
17
  cursor = db.cursor()
@@ -22,7 +28,10 @@ def get_user(udid):
22
  ).fetchone()
23
 
24
  if user:
25
- return jsonify(dict(user))
 
 
 
26
 
27
  # Kullanıcı yoksa otomatik oluştur
28
  cursor.execute(
@@ -36,7 +45,14 @@ def get_user(udid):
36
  (udid,)
37
  ).fetchone()
38
 
39
- return jsonify(dict(new_user)), 201
 
 
 
 
40
 
41
  except Exception as e:
42
- return jsonify({"error": str(e)}), 500
 
 
 
 
2
  from database import get_db
3
 
4
  def get_users():
5
+ """Tüm kullanıcıları standart bir JSON yapısıyla getirir"""
6
  try:
7
  db = get_db()
8
  users = db.execute('SELECT * FROM users').fetchall()
9
+ return jsonify({
10
+ "success": True,
11
+ "users": [dict(user) for user in users]
12
+ })
13
  except Exception as e:
14
+ return jsonify({
15
+ "success": False,
16
+ "error": str(e)
17
+ }), 500
18
 
19
  def get_user(udid):
20
+ """UDID ile kullanıcıyı standart bir response yapısında döner"""
21
  try:
22
  db = get_db()
23
  cursor = db.cursor()
 
28
  ).fetchone()
29
 
30
  if user:
31
+ return jsonify({
32
+ "success": True,
33
+ "user": dict(user)
34
+ })
35
 
36
  # Kullanıcı yoksa otomatik oluştur
37
  cursor.execute(
 
45
  (udid,)
46
  ).fetchone()
47
 
48
+ return jsonify({
49
+ "success": True,
50
+ "user": dict(new_user),
51
+ "created": True
52
+ }), 201
53
 
54
  except Exception as e:
55
+ return jsonify({
56
+ "success": False,
57
+ "error": str(e)
58
+ }), 500