Spaces:
Running
Running
Commit ·
d6581ab
1
Parent(s): eb6d2f6
Fix: add robust user existence checks to prevent SQLite Foreign Key errors
Browse files17 unmodified lines1819202122222324252627282930313032333234353637383934353637404142434445464748495011 unmodified lines62636465666768697071727374757677787980818223 unmodified lines1061071088410911011111217 unmodified lines { private readonly IGraphService _graphService; private readonly ITokenService _tokenService; private readonly IUserRepository _userRepo;
public AgentCanvasController(IGraphService graphService, ITokenService tokenService) public AgentCanvasController(IGraphService graphService, ITokenService tokenService, IUserRepository userRepo) { _graphService = graphService; _tokenService = tokenService; _userRepo = userRepo; }
[AllowAnonymous] [HttpGet("token")] public IActionResult GetToken() public async Task<IActionResult> GetToken() { var user = new User var userId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); var user = await _userRepo.GetByIdAsync(userId); if (user == null) { user = new User { Id = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"), Email = "dan9228335@gmail.com", DisplayName = "Dodikuser" }; 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 lines
try { // Ensure user exists in database to prevent Foreign Key constraints failure var 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 database var createDto = new CreateGraphDto {23 unmodified lines } catch (Exception ex) { return BadRequest(new { message = $"Internal error during plan generation: {ex.Message}" }); return BadRequest(new { message = $"Internal error during plan generation: {ex}" }); } }
FlowAPI/Controllers/AgentCanvasController.cs+33-8