// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ // ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX) ┃ // ┃ SPDX-License-Identifier: MPL-2.0 ┃ // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ // ┃ ┃ // ┃ This Source Code Form is subject to the terms of the Mozilla Public ┃ // ┃ License, v. 2.0. If a copy of the MPL was not distributed with this ┃ // ┃ file, You can obtain one at https://mozilla.org/MPL/2.0/. ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ use lexa_framework::routing; use crate::crud_site::applications::ApplicationState; use crate::crud_site::controllers::ArticlesController; // --------- // // Structure // // --------- // pub struct ArticlesRouter; // ----------- // // Énumération // // ----------- // lexa_framework::routes! { pub enum ArticlesRouteId<'r> { #[route(url = "/articles")] ArticlesIndex, #[route(url = "/articles/new")] ArticlesNew, #[route(url = "/articles/delete-all")] ArticlesDeleteAll, #[route(url = "/articles/{id}")] ArticlesShow { id: String }, #[route(url = "/articles/{id}/edit")] ArticlesEdit { id: String }, #[route(url = "/articles/{id}/delete")] ArticlesDelete { id: String }, } } // -------------- // // Implémentation // -> Interface // -------------- // impl lexa_framework::ApplicationRouter for ArticlesRouter { type State = ApplicationState; fn routes() -> routing::RouteCollection { Self::router_collection() .add( routing::Router::path(ArticlesRouteId::ArticlesIndex) .get(ArticlesController::index), ) .add( routing::Router::path(ArticlesRouteId::ArticlesNew) .get(ArticlesController::new) .post(ArticlesController::create), ) .add( routing::Router::path(ArticlesRouteId::ArticlesShow { id: ":id".to_owned(), }) .get(ArticlesController::show), ) .add( routing::Router::path(ArticlesRouteId::ArticlesEdit { id: ":id".to_owned(), }) .get(ArticlesController::edit) .put(ArticlesController::update), ) .add( routing::Router::path(ArticlesRouteId::ArticlesDelete { id: ":id".to_owned(), }) .delete(ArticlesController::destroy), ) .add( routing::Router::path(ArticlesRouteId::ArticlesDeleteAll) .delete(ArticlesController::delete_all), ) } }