Skip to content

Commit

Permalink
Merge branch 'isaacdonaldson-scaffold/add-api-prefix'
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Oct 23, 2024
2 parents 32051ef + 0b87af2 commit dcf7345
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion loco-gen/src/templates/controller/api/controller.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn {{action}}(State(_ctx): State<AppContext>) -> Result<Response> {

pub fn routes() -> Routes {
Routes::new()
.prefix("{{file_name | plural}}/")
.prefix("api/{{file_name | plural}}/")
.add("/", get(index))
{%- for action in actions %}
.add("{{action}}", get({{action}}))
Expand Down
2 changes: 1 addition & 1 deletion loco-gen/src/templates/scaffold/api/controller.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub async fn get_one(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Resu

pub fn routes() -> Routes {
Routes::new()
.prefix("{{file_name | plural}}/")
.prefix("api/{{file_name | plural}}/")
.add("/", get(list))
.add("/", post(add))
.add(":id", get(get_one))
Expand Down
4 changes: 1 addition & 3 deletions starters/lightweight-service/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ impl Hooks for App {
}

fn routes(_ctx: &AppContext) -> AppRoutes {
AppRoutes::empty()
.prefix("/api")
.add_route(controllers::home::routes())
AppRoutes::empty().add_route(controllers::home::routes())
}

async fn connect_workers(_ctx: &AppContext, _queue: &Queue) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion starters/lightweight-service/src/controllers/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ async fn current() -> Result<Response> {
}

pub fn routes() -> Routes {
Routes::new().add("/", get(current))
Routes::new().prefix("/api").add("/", get(current))
}
1 change: 0 additions & 1 deletion starters/rest-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl Hooks for App {

fn routes(_ctx: &AppContext) -> AppRoutes {
AppRoutes::with_default_routes()
.prefix("/api")
.add_route(controllers::notes::routes())
.add_route(controllers::auth::routes())
.add_route(controllers::user::routes())
Expand Down
2 changes: 1 addition & 1 deletion starters/rest-api/src/controllers/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async fn login(State(ctx): State<AppContext>, Json(params): Json<LoginParams>) -

pub fn routes() -> Routes {
Routes::new()
.prefix("auth")
.prefix("api/auth")
.add("/register", post(register))
.add("/verify", post(verify))
.add("/login", post(login))
Expand Down
2 changes: 1 addition & 1 deletion starters/rest-api/src/controllers/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub async fn get_one(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Resu

pub fn routes() -> Routes {
Routes::new()
.prefix("notes")
.prefix("api/notes")
.add("/", get(list))
.add("/", post(add))
.add("/:id", get(get_one))
Expand Down
4 changes: 3 additions & 1 deletion starters/rest-api/src/controllers/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ async fn current(auth: auth::JWT, State(ctx): State<AppContext>) -> Result<Respo
}

pub fn routes() -> Routes {
Routes::new().prefix("user").add("/current", get(current))
Routes::new()
.prefix("api/user")
.add("/current", get(current))
}

0 comments on commit dcf7345

Please sign in to comment.