Claude opus authored everything to make the user and task work. First iteration
This commit is contained in:
56
Provider/main/api/users/store.cpp
Normal file
56
Provider/main/api/users/store.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// User data store: CRUD helpers and seed data
|
||||
|
||||
#include "api/users/store.hpp"
|
||||
|
||||
// Find a user by ID, returns nullptr if not found
|
||||
internal user_t *find_user(uint8 id)
|
||||
{
|
||||
for (int i = 0; i < MAX_USERS; i++)
|
||||
{
|
||||
if (g_Users[i].active && g_Users[i].id == id)
|
||||
{
|
||||
return &g_Users[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Add a user, returns pointer to new user or nullptr if full
|
||||
internal user_t *add_user(const char *name)
|
||||
{
|
||||
for (int i = 0; i < MAX_USERS; i++)
|
||||
{
|
||||
if (!g_Users[i].active)
|
||||
{
|
||||
g_Users[i].id = g_NextUserId++;
|
||||
strlcpy(g_Users[i].name, name, sizeof(g_Users[i].name));
|
||||
g_Users[i].active = true;
|
||||
return &g_Users[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Remove a user by ID, returns true if found and removed
|
||||
internal bool remove_user(uint8 id)
|
||||
{
|
||||
for (int i = 0; i < MAX_USERS; i++)
|
||||
{
|
||||
if (g_Users[i].active && g_Users[i].id == id)
|
||||
{
|
||||
g_Users[i].active = false;
|
||||
g_Users[i].id = 0;
|
||||
g_Users[i].name[0] = '\0';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Populate dummy users on boot for development iteration
|
||||
internal void seed_users()
|
||||
{
|
||||
add_user("Alice");
|
||||
add_user("Bob");
|
||||
add_user("Charlie");
|
||||
}
|
||||
Reference in New Issue
Block a user