develop #3

Merged
wt merged 21 commits from develop into main 2025-10-23 07:20:44 +00:00
Showing only changes of commit 5fda74ab1d - Show all commits
+31 -1
View File
@@ -1,8 +1,13 @@
#ifdef USE_SQLITE3
#include "database.h"
#ifdef USE_SQLITE3
#include "sql.h"
#endif
#ifndef USE_SQLITE3
#include "file.h"
#endif
#include "user.h"
bool db_delete_user(const int id) {
@@ -47,6 +52,31 @@ bool db_delete_user(const int id) {
pthread_mutex_unlock(&db_mutex);
return true;
#else
pthread_mutex_lock(&users_file_mutex);
char *data = read_file("users_db.json");
cJSON *users = cJSON_Parse(data);
cJSON *user = nullptr;
int index = 0;
bool found = false;
cJSON_ArrayForEach(user, users) {
cJSON *user_id = cJSON_GetObjectItem(user, "id");
if (user_id->valueint == id) {
cJSON_DeleteItemFromArray(users, index);
found = true;
break;
}
index++;
}
if (!found) {
pthread_mutex_unlock(&users_file_mutex);
return false;
}
char *new_data = cJSON_Print(users);
write_file("users_db.json", new_data);
free(new_data);
free(data);
cJSON_Delete(users);
pthread_mutex_unlock(&users_file_mutex);
return true;
#endif
}