-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathDebugController.cs
More file actions
75 lines (68 loc) · 2.17 KB
/
DebugController.cs
File metadata and controls
75 lines (68 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using Microsoft.AspNetCore.Mvc;
using Nocturne.Core.Contracts.Entries;
using Nocturne.Core.Models;
namespace Nocturne.API.Controllers.V1;
/// <summary>
/// V1 debug controller for development and diagnostics.
/// Provides basic database connectivity tests against the PostgreSQL data store.
/// </summary>
/// <seealso cref="IEntryStore"/>
[ApiController]
[Route("api/v1/[controller]")]
public class DebugController : ControllerBase
{
private readonly IEntryStore _store;
private readonly ILogger<DebugController> _logger;
public DebugController(IEntryStore store, ILogger<DebugController> logger)
{
_store = store;
_logger = logger;
}
[HttpGet("postgresql-test")]
public async Task<IActionResult> TestPostgreSqlConnection()
{
try
{
_logger.LogInformation("Testing PostgreSQL connection");
// Try to get recent entries as a connectivity check
var entries = await _store.QueryAsync(new EntryQuery { Type = "sgv", Count = 1 });
var firstEntry = entries.FirstOrDefault();
return Ok(
new
{
DatabaseType = "PostgreSQL",
HasEntries = firstEntry != null,
SampleEntry = firstEntry,
Status = "Success",
}
);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error testing PostgreSQL: {Message}", ex.Message);
return StatusCode(
500,
new
{
Error = ex.Message,
InnerError = ex.InnerException?.Message,
Status = "Failed",
}
);
}
}
[HttpGet("entries-direct")]
public async Task<IActionResult> GetEntriesDirect()
{
try
{
var entries = await _store.QueryAsync(new EntryQuery { Type = "sgv", Count = 5 });
return Ok(entries);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting entries directly");
return StatusCode(500, new { Error = ex.Message });
}
}
}