Skip to content

Commit b9bb7dd

Browse files
committed
JSON API routes
1 parent 87c7b1d commit b9bb7dd

7 files changed

Lines changed: 12 additions & 54 deletions

File tree

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ mod utils;
99

1010
use axum::{routing::get, Router};
1111

12-
use models::SharedState;
12+
use models::app_state::SharedState;
1313
use repository::todo::{Repo, TodoRepo};
14-
use routes::htmx::index::{create_htmx_routes, get_index};
14+
use routes::{
15+
htmx::index::{create_htmx_routes, get_index},
16+
json::index::create_json_routes,
17+
};
1518
use service::todo::{TodoService, TodoServiceImpl};
1619
use tokio::net::TcpListener;
1720
use tower_http::{services::ServeDir, trace::TraceLayer};
@@ -22,12 +25,11 @@ pub fn app() -> Router {
2225
let todo_repo = TodoRepo::new(SharedState::default());
2326
let todo_service = TodoServiceImpl::new(todo_repo);
2427

25-
let htmx_routes = create_htmx_routes();
26-
2728
Router::new()
2829
.nest_service("/assets", ServeDir::new("assets"))
2930
.route("/", get(get_index))
30-
.nest("/htmx-api", htmx_routes)
31+
.nest("/htmx-api", create_htmx_routes())
32+
.nest("/json-api", create_json_routes())
3133
.layer(TraceLayer::new_for_http())
3234
.with_state(todo_service)
3335
}

src/models.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/repository/todo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Result;
22

33
use crate::{
44
error::TodoError,
5-
models::{SharedState, Todo},
5+
models::{app_state::SharedState, todo::Todo},
66
};
77

88
// TODO: refactor to use an in-memory db?

src/routes/htmx/todo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
models::TodoRequest,
2+
models::todo::TodoRequest,
33
service::todo::{TodoService, TodoServiceImpl},
44
templates::{
55
index::EmptyResponse,

src/routes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod htmx;
2+
pub mod json;

src/service/todo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Result;
22

33
use crate::{
44
error::TodoError,
5-
models::Todo,
5+
models::todo::Todo,
66
repository::todo::{Repo, TodoRepo},
77
};
88

src/templates/todo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use askama::Template;
22
use serde::Deserialize;
33

4-
use crate::models::Todo;
4+
use crate::models::todo::Todo;
55

66
#[derive(Template, Deserialize)]
77
#[template(path = "todo/list.html")]

0 commit comments

Comments
 (0)