Spaces:
Running
Running
Commit ·
d6581ab
1
Parent(s): eb6d2f6
Fix: add robust user existence checks to prevent SQLite Foreign Key errors
Browse files17 unmodified lines181920212223242526272829303132333435363738394011 unmodified lines52535455565723 unmodified lines8182838485868717 unmodified lines{private readonly IGraphService _graphService;private readonly ITokenService _tokenService;public AgentCanvasController(IGraphService graphService, ITokenService tokenService){_graphService = graphService;_tokenService = tokenService;}[AllowAnonymous][HttpGet("token")]public IActionResult GetToken(){var user = new User{Id = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"),Email = "dan9228335@gmail.com",DisplayName = "Dodikuser"};var token = _tokenService.CreateToken(user);return Ok(new { token });}11 unmodified linestry{// 1. Create the Graph record in the databasevar createDto = new CreateGraphDto{23 unmodified lines}catch (Exception ex){return BadRequest(new { message = $"Internal error during plan generation: {ex.Message}" });}}17 unmodified lines18192021222324252627282930313233343536373839404142434445464748495011 unmodified lines62636465666768697071727374757677787980818223 unmodified lines10610710810911011111217 unmodified lines{private readonly IGraphService _graphService;private readonly ITokenService _tokenService;private readonly IUserRepository _userRepo;public AgentCanvasController(IGraphService graphService, ITokenService tokenService, IUserRepository userRepo){_graphService = graphService;_tokenService = tokenService;_userRepo = userRepo;}[AllowAnonymous][HttpGet("token")]public async Task<IActionResult> GetToken(){var userId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");var user = await _userRepo.GetByIdAsync(userId);if (user == null){user = new User{Id = userId,Email = "dan9228335@gmail.com",DisplayName = "Dodikuser",PasswordHash = "",CreatedAt = DateTime.UtcNow};await _userRepo.CreateAsync(user);}var token = _tokenService.CreateToken(user);return Ok(new { token });}11 unmodified linestry{// Ensure user exists in database to prevent Foreign Key constraints failurevar user = await _userRepo.GetByIdAsync(CurrentUserId);if (user == null){user = new User{Id = CurrentUserId,Email = User.FindFirst(ClaimTypes.Email)?.Value ?? $"{CurrentUserId}@questboard.ai",DisplayName = User.FindFirst("displayName")?.Value ?? "Questboard User",PasswordHash = "",CreatedAt = DateTime.UtcNow};await _userRepo.CreateAsync(user);}// 1. Create the Graph record in the databasevar createDto = new CreateGraphDto{23 unmodified lines}catch (Exception ex){return BadRequest(new { message = $"Internal error during plan generation: {ex}" });}}
FlowAPI/Controllers/AgentCanvasController.cs+33-8