From 420a366b38d4768cdda3074b4f26c4949f927bcb Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sat, 8 Jun 2019 16:15:14 +0200 Subject: [PATCH] Add stub handlers for the complete application No handler is implemented! --- src/handlers.rs | 16 +++++++++++ src/handlers/company.rs | 20 +++++++++++++ src/handlers/customers.rs | 44 ++++++++++++++++++++++++++++ src/handlers/customers/invoices.rs | 41 ++++++++++++++++++++++++++ src/handlers/customers/tasks.rs | 36 +++++++++++++++++++++++ src/handlers/invoices.rs | 11 +++++++ src/handlers/timeline.rs | 43 ++++++++++++++++++++++++++++ src/main.rs | 46 ++++++++++++++++++++++++++---- 8 files changed, 251 insertions(+), 6 deletions(-) create mode 100644 src/handlers.rs create mode 100644 src/handlers/company.rs create mode 100644 src/handlers/customers.rs create mode 100644 src/handlers/customers/invoices.rs create mode 100644 src/handlers/customers/tasks.rs create mode 100644 src/handlers/invoices.rs create mode 100644 src/handlers/timeline.rs diff --git a/src/handlers.rs b/src/handlers.rs new file mode 100644 index 0000000..d8c17d1 --- /dev/null +++ b/src/handlers.rs @@ -0,0 +1,16 @@ +//! The root handlers + +use rocket::get; + +pub mod company; +pub mod customers; +pub mod invoices; +pub mod timeline; + +/// Presents the dashboard/overview as start/home view +/// +/// It lists the running tasks and projects per customer and shows a global summary. +#[get("/")] +pub fn index() { + unimplemented!() +} diff --git a/src/handlers/company.rs b/src/handlers/company.rs new file mode 100644 index 0000000..33c37cf --- /dev/null +++ b/src/handlers/company.rs @@ -0,0 +1,20 @@ +//! The company (information) handlers +//! +//! These handlers are for showing and updating information of the company of the user. + +use rocket::{get, post}; + +/// Shows a form with the company information that allows for updating it. +/// +/// When updating, it will create a new revision. The handler allows showing other revisions. +// FIXME: Implement revisions! +#[get("/")] +pub fn index() { + unimplemented!() +} + +/// Updates the company information by creating a new revision. +#[post("/")] +pub fn create() { + unimplemented!() +} diff --git a/src/handlers/customers.rs b/src/handlers/customers.rs new file mode 100644 index 0000000..31b1a5c --- /dev/null +++ b/src/handlers/customers.rs @@ -0,0 +1,44 @@ +//! The customer handlers +//! +//! Handlers for viewing a list of existing customers or creating a new one. + +use rocket::{delete, get, post, put}; + +pub mod invoices; +pub mod tasks; + +/// Shows the list of customers. +#[get("/")] +pub fn index() { + unimplemented!() +} + +/// Creates a new customer and redirects to the show handler. +#[post("/")] +pub fn create() { + unimplemented!() +} + +/// Provides the form for the data required to create a new customer. +#[get("/new")] +pub fn new() { + unimplemented!() +} + +/// Shows a form for viewing and updating information of the customer with the given ID. +#[get("/<_id>")] +pub fn show(_id: u32) { + unimplemented!() +} + +/// Updates the customer with the given ID. +#[put("/<_id>")] +pub fn update(_id: u32) { + unimplemented!() +} + +/// Destroys the customer with the given ID and redirects to the index handler. +#[delete("/<_id>")] +pub fn destroy(_id: u32) { + unimplemented!() +} diff --git a/src/handlers/customers/invoices.rs b/src/handlers/customers/invoices.rs new file mode 100644 index 0000000..18ad111 --- /dev/null +++ b/src/handlers/customers/invoices.rs @@ -0,0 +1,41 @@ +//! The invoice handlers +//! +//! These handlers are for creating and viewing invoices for a specific customer. + +use rocket::{get, post, put}; + +/// Creates a new invoice object for the customer the given ID. +/// +/// A unique number is generated for the invoice by taking the year and a sequence number. +/// +/// Fixed cost tasks are directly tied to the invoice. +/// +/// For a task with an hourly rate, a task copy is created with the select time entries that need +/// to be billed and put in the invoice; the remaining unbilled time entries are left in the +/// original task. +#[post("/<_customer_id>/invoices")] +pub fn create(_customer_id: u32) { + unimplemented!() +} + +/// Generates the form to create a new invoice object by listing unbulled fixed cost tasks and +/// unbilled registered time (for tasks with an hourly rate) of the customer with the given ID so +/// that a selection can be made. +#[get("/<_customer_id>/invoices/new")] +pub fn new(_customer_id: u32) { + unimplemented!() +} + +/// Shows a form for the invoice with the given number for the customer with the given ID +/// and shows a firm for updating it. +// FIXME: Handle PDF and LaTex generation here too! +#[get("/<_customer_id>/invoices/<_number>", rank = 2)] // Number could be "new" +pub fn show(_customer_id: u32, _number: String) { + unimplemented!() +} + +/// Updates the invoices with the given number for the customer with the given ID. +#[put("/<_customer_id>/invoices/<_number>")] +pub fn update(_customer_id: u32, _number: String) { + unimplemented!() +} diff --git a/src/handlers/customers/tasks.rs b/src/handlers/customers/tasks.rs new file mode 100644 index 0000000..111a777 --- /dev/null +++ b/src/handlers/customers/tasks.rs @@ -0,0 +1,36 @@ +//! The tasks handlers +//! +//! These handlers are for creating, editing and deleting a task for a specific customer. + +use rocket::{delete, get, post, put}; + +/// Creates a new task oject for a customer with the given ID. +#[post("/<_customer_id>/tasks")] +pub fn create(_customer_id: u32) { + unimplemented!() +} + +/// Provides the form for the data required to create a new task for a customer with the given ID. +#[get("/<_customer_id>/tasks/new")] +pub fn new(_customer_id: u32) { + unimplemented!() +} + +/// Shows a form for viewing and updating information of the task with the given ID for +/// a customer with the given ID. +#[get("/<_customer_id>/tasks/<_id>", rank = 2)] // FIXME: Why is rank 2 necessary? +pub fn show(_customer_id: u32, _id: u32) { + unimplemented!() +} + +/// Updates the task with the given ID for a customer with the given ID. +#[put("/<_customer_id>/tasks/<_id>")] +pub fn update(_customer_id: u32, _id: u32) { + unimplemented!() +} + +/// Destroys the task with the given ID of a customer with the given ID. +#[delete("/<_customer_id>/tasks/<_id>")] +pub fn destroy(_customer_id: u32, _id: u32) { + unimplemented!() +} diff --git a/src/handlers/invoices.rs b/src/handlers/invoices.rs new file mode 100644 index 0000000..c1a9a20 --- /dev/null +++ b/src/handlers/invoices.rs @@ -0,0 +1,11 @@ +//! The invoices handlers +//! +//! The handler is used for showing a list of all invoices. + +use rocket::get; + +/// Shows a list of invoices, sorted per customer. +#[get("/")] +pub fn index() { + unimplemented!() +} diff --git a/src/handlers/timeline.rs b/src/handlers/timeline.rs new file mode 100644 index 0000000..7814f25 --- /dev/null +++ b/src/handlers/timeline.rs @@ -0,0 +1,43 @@ +//! The timeline handlers +//! +//! These handlers are used for presenting a timeline of registered time and also for quickly +//! registering new time entries. + +use rocket::{delete, get, post, put}; + +/// Retrieves all registered time entries in descending order to present the timeline. +#[get("/")] +pub fn index() { + unimplemented!() +} + +/// Registers a time entry and redirects back. +#[post("/")] +pub fn create() { + unimplemented!() +} + +/// Shows a form for quickly registering time using a list of customers and tasks and the current +/// date and time. +#[get("/new")] +pub fn new() { + unimplemented!() +} + +/// Show a form of the time entry with the given ID for updating it. +#[get("/<_id>")] +pub fn show(_id: u32) { + unimplemented!() +} + +/// Update the time entry with the given ID. +#[put("/<_id>")] +pub fn update(_id: u32) { + unimplemented!() +} + +/// Destroys the time entry with the given ID. +#[delete("/<_id>")] +pub fn destroy(_id: u32) { + unimplemented!() +} diff --git a/src/main.rs b/src/main.rs index 0e5bffc..275c0c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,53 @@ #![feature(proc_macro_hygiene, decl_macro)] -use rocket::{get, routes, Rocket}; +use rocket::{routes, Rocket}; use rocket_contrib::serve::StaticFiles; -#[get("/")] -fn index() -> &'static str { - "Hello, world!" -} +pub mod handlers; fn rocket() -> Rocket { let static_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/static"); let static_files = StaticFiles::from(static_dir); + rocket::ignite() - .mount("/", routes![index]) + .mount("/", routes![handlers::index]) + .mount( + "/company", + routes![handlers::company::index, handlers::company::create], + ) + .mount( + "/customers", + routes![ + handlers::customers::index, + handlers::customers::create, + handlers::customers::new, + handlers::customers::show, + handlers::customers::update, + handlers::customers::destroy, + handlers::customers::invoices::create, + handlers::customers::invoices::new, + handlers::customers::invoices::show, + handlers::customers::invoices::update, + handlers::customers::tasks::create, + handlers::customers::tasks::new, + handlers::customers::tasks::show, + handlers::customers::tasks::update, + handlers::customers::tasks::destroy, + ], + ) + .mount("/invoices", routes![handlers::invoices::index]) .mount("/static", static_files) + .mount( + "/timeline", + routes![ + handlers::timeline::index, + handlers::timeline::create, + handlers::timeline::new, + handlers::timeline::show, + handlers::timeline::update, + handlers::timeline::destroy, + ], + ) } fn main() {