|
|
@@ -245,23 +245,6 @@ class UserDataService(BaseDataService):
|
|
|
return result
|
|
|
return 0
|
|
|
|
|
|
- def set_reward_progress(self, user_id: int, progress: int) -> bool:
|
|
|
- """Add progress to user's reward"""
|
|
|
- conn = self._get_connection()
|
|
|
- cursor = conn.cursor()
|
|
|
- try:
|
|
|
- cursor.execute("UPDATE users SET reward_progress = %s WHERE id = %s", (progress, user_id))
|
|
|
- conn.commit()
|
|
|
- success = cursor.rowcount > 0
|
|
|
- if success:
|
|
|
- logger.info(f"Reward progress updated for user {user_id}: {progress}")
|
|
|
- return success
|
|
|
- except psycopg2.IntegrityError as e:
|
|
|
- logger.error(f"Failed to update reward progress: {e}")
|
|
|
- return False
|
|
|
- finally:
|
|
|
- conn.close()
|
|
|
-
|
|
|
def get_by_rut(self, rut: str) -> Optional[User]:
|
|
|
"""Get user by RUT"""
|
|
|
conn = self._get_connection()
|
|
|
@@ -287,6 +270,17 @@ class UserDataService(BaseDataService):
|
|
|
reward_progress=user[8]
|
|
|
)
|
|
|
return None
|
|
|
+
|
|
|
+ def get_next_id(self) -> int:
|
|
|
+ """Get the next user ID"""
|
|
|
+ conn = self._get_connection()
|
|
|
+ cursor = conn.cursor()
|
|
|
+ cursor.execute("SELECT last_value FROM users_id_seq")
|
|
|
+ result = cursor.fetchone()
|
|
|
+ conn.close()
|
|
|
+ if result and result[0]:
|
|
|
+ return result[0]
|
|
|
+ return 1
|
|
|
#endregion
|
|
|
#region Update
|
|
|
def update(self, user_id: int, email=None, name=None, rut=None, pin_hash=None, kleincoins=None) -> bool:
|
|
|
@@ -326,6 +320,25 @@ class UserDataService(BaseDataService):
|
|
|
finally:
|
|
|
conn.close()
|
|
|
#endregion
|
|
|
+
|
|
|
+ def set_reward_progress(self, user_id: int, progress: int) -> bool:
|
|
|
+ """Add progress to user's reward"""
|
|
|
+ conn = self._get_connection()
|
|
|
+ cursor = conn.cursor()
|
|
|
+ try:
|
|
|
+ cursor.execute("UPDATE users SET reward_progress = %s WHERE id = %s", (progress, user_id))
|
|
|
+ conn.commit()
|
|
|
+ success = cursor.rowcount > 0
|
|
|
+ if success:
|
|
|
+ logger.info(f"Reward progress updated for user {user_id}: {progress}")
|
|
|
+ return success
|
|
|
+ except psycopg2.IntegrityError as e:
|
|
|
+ logger.error(f"Failed to update reward progress: {e}")
|
|
|
+ return False
|
|
|
+ finally:
|
|
|
+ conn.close()
|
|
|
+
|
|
|
+
|
|
|
#region Delete
|
|
|
def delete(self, user_id: int) -> bool:
|
|
|
"""Delete a user from the database"""
|