Fix db and fix endpoints

This commit is contained in:
2025-08-05 22:30:18 +07:00
parent 2dcbcc3ef2
commit 36529ae403
36 changed files with 5073 additions and 245 deletions

View File

@@ -95,15 +95,16 @@ public class UserService : IUserService
}
else
{
// First login
// First login - create user first
user = new User
{
Name = name
};
await _userRepository.InsertUserAsync(user);
// Save the user first
await _userRepository.SaveOrUpdateUserAsync(user);
// Create embedded account to authenticate user
// Create embedded account to authenticate user after user is saved
var account = await _accountService.CreateAccount(user, new Account
{
Name = $"{name}-embedded",
@@ -116,9 +117,6 @@ public class UserService : IUserService
{
account
};
// Update user with the new account
await _userRepository.UpdateUser(user);
}
return user;
@@ -165,8 +163,12 @@ public class UserService : IUserService
else
{
user = await GetUserByName(user.Name);
if (!string.IsNullOrEmpty(user.AgentName) && user.AgentName.Equals(agentName))
return user;
// Update the agent name on the provided user object
user.AgentName = agentName;
await _userRepository.UpdateUser(user);
await _userRepository.SaveOrUpdateUserAsync(user);
// Initialize the AgentGrain for this user
try
@@ -204,8 +206,12 @@ public class UserService : IUserService
}
user = await GetUserByName(user.Name);
if (!string.IsNullOrEmpty(user.AvatarUrl) && user.AvatarUrl.Equals(avatarUrl))
return user;
// Update the avatar URL on the provided user object
user.AvatarUrl = avatarUrl;
await _userRepository.UpdateUser(user);
await _userRepository.SaveOrUpdateUserAsync(user);
return user;
}
@@ -222,8 +228,12 @@ public class UserService : IUserService
}
user = await GetUserByName(user.Name);
if (!string.IsNullOrEmpty(user.TelegramChannel) && user.TelegramChannel.Equals(telegramChannel))
return user;
// Update the telegram channel on the provided user object
user.TelegramChannel = telegramChannel;
await _userRepository.UpdateUser(user);
await _userRepository.SaveOrUpdateUserAsync(user);
return user;
}
@@ -247,6 +257,4 @@ public class UserService : IUserService
{
return await _userRepository.GetAllUsersAsync();
}
}