Skip to content

Commit 6b51e06

Browse files
V VV V
authored andcommitted
fix: direct route registration instead of .nest(), public structs
1 parent 0f93c15 commit 6b51e06

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

src/api.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn api_err(status: StatusCode, msg: impl Into<String>) -> Response {
9393

9494
/// Query parameters for `GET /api/v1/events`.
9595
#[derive(Debug, Deserialize)]
96-
struct EventsParams {
96+
pub struct EventsParams {
9797
event_type: Option<String>,
9898
from: Option<String>,
9999
to: Option<String>,
@@ -152,7 +152,7 @@ pub async fn get_event(
152152

153153
/// Request body for `POST /api/v1/events/query`.
154154
#[derive(Debug, Deserialize)]
155-
struct CustomQueryRequest {
155+
pub struct CustomQueryRequest {
156156
/// SQL SELECT statement — runs against `deduped` CTE (auto-scoped to tenant).
157157
sql: String,
158158
from: Option<String>,
@@ -204,7 +204,7 @@ async fn proxy_to_polars_query(state: &AppState, body: &serde_json::Value) -> Re
204204

205205
/// Query parameters for analytics endpoints.
206206
#[derive(Debug, Deserialize)]
207-
struct AnalyticsParams {
207+
pub struct AnalyticsParams {
208208
event_type: Option<String>,
209209
from: Option<String>,
210210
to: Option<String>,
@@ -235,7 +235,7 @@ pub async fn analytics_summary(
235235

236236
/// Query parameters for timeseries endpoint.
237237
#[derive(Debug, Deserialize)]
238-
struct TimeseriesParams {
238+
pub struct TimeseriesParams {
239239
event_type: Option<String>,
240240
from: Option<String>,
241241
to: Option<String>,
@@ -314,10 +314,10 @@ async fn proxy_to_polars_lite(state: &AppState, body: &serde_json::Value) -> Res
314314

315315
/// Request body for `POST /api/v1/query/nl`.
316316
#[derive(Debug, Deserialize)]
317-
struct NlQueryRequest {
317+
pub struct NlQueryRequest {
318318
/// Natural language question.
319-
prompt: String,
320-
limit: Option<u32>,
319+
pub prompt: String,
320+
pub limit: Option<u32>,
321321
}
322322

323323
/// `POST /api/v1/query/nl` — natural language → SQL → results.
@@ -352,12 +352,12 @@ pub async fn query_nl(
352352

353353
/// Request body for `POST /api/v1/query/similar`.
354354
#[derive(Debug, Deserialize)]
355-
struct SimilarQueryRequest {
355+
pub struct SimilarQueryRequest {
356356
/// Event ID to find similar events for.
357-
event_id: Option<String>,
357+
pub event_id: Option<String>,
358358
/// Or raw text to search for.
359-
query: Option<String>,
360-
limit: Option<u32>,
359+
pub query: Option<String>,
360+
pub limit: Option<u32>,
361361
}
362362

363363
/// `POST /api/v1/query/similar` — vector similarity search.

src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,15 @@ async fn main() {
145145
.layer(DefaultBodyLimit::max(16_384)))
146146
.route("/ingest", post(routes::handle_ingest)
147147
.layer(DefaultBodyLimit::max(1_048_576)))
148-
.nest("/api/v1", tracker_core::api::router())
148+
// Tenant-scoped analytics API
149+
.route("/api/v1/events", get(tracker_core::api::list_events))
150+
.route("/api/v1/events/id/{event_id}", get(tracker_core::api::get_event))
151+
.route("/api/v1/events/query", post(tracker_core::api::custom_query))
152+
.route("/api/v1/analytics/summary", get(tracker_core::api::analytics_summary))
153+
.route("/api/v1/analytics/timeseries", get(tracker_core::api::analytics_timeseries))
154+
.route("/api/v1/analytics/top", get(tracker_core::api::analytics_top))
155+
.route("/api/v1/query/nl", post(tracker_core::api::query_nl))
156+
.route("/api/v1/query/similar", post(tracker_core::api::query_similar))
149157
.with_state(state);
150158

151159
let listener = tokio::net::TcpListener::bind(config.listen_addr)

0 commit comments

Comments
 (0)