Get rid of all non-GraphQL handlers

Also move the GraphQL handlers to the parent handlers model.
This commit is contained in:
Paul van Tilburg 2019-07-10 20:54:43 +02:00
parent 26c86fe03e
commit c3a6b5f572
9 changed files with 40 additions and 239 deletions

View File

@ -1,17 +1,44 @@
//! The root handlers
use rocket::get;
use crate::graphql::Schema;
use crate::DbConn;
pub mod company;
pub mod customers;
pub mod graphql;
pub mod invoices;
pub mod timeline;
use juniper_rocket::{playground_source, GraphQLRequest, GraphQLResponse};
use rocket::response::content::Html;
use rocket::{get, post, State};
/// Presents the dashboard/overview as start/home view
/// Presents the main web application.
///
/// It lists the running tasks and projects per customer and shows a global summary.
/// FIXME: Not implemented yet.
#[get("/")]
pub fn index() {
unimplemented!()
}
/// Presents a playground GraphQL web application.
///
/// This can be used to test the GraphQL backend.
#[get("/graphql/playground")]
pub fn graphql_playground() -> Html<String> {
playground_source("/graphql")
}
/// Handles a GraphQL GET request.
#[get("/graphql?<request>")]
pub fn graphql_get(
request: GraphQLRequest,
conn: DbConn,
schema: State<Schema>,
) -> GraphQLResponse {
request.execute(&schema, &conn)
}
/// Handles a GraphQL POST request.
#[post("/graphql", data = "<request>")]
pub fn graphql_post(
request: GraphQLRequest,
conn: DbConn,
schema: State<Schema>,
) -> GraphQLResponse {
request.execute(&schema, &conn)
}

View File

@ -1,20 +0,0 @@
//! 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!()
}

View File

@ -1,44 +0,0 @@
//! 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!()
}

View File

@ -1,41 +0,0 @@
//! 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!()
}

View File

@ -1,36 +0,0 @@
//! 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!()
}

View File

@ -1,30 +0,0 @@
//! The GraphQL handlers
//!
//! Handlers for querying and mutating models via GraphQL.
use crate::graphql::Schema;
use crate::DbConn;
use juniper_rocket::{graphiql_source, playground_source, GraphQLRequest, GraphQLResponse};
use rocket::response::content::Html;
use rocket::{get, post, State};
#[get("/graphiql")]
pub fn graphiql() -> Html<String> {
graphiql_source("/graphql")
}
#[get("/playground")]
pub fn playground() -> Html<String> {
playground_source("/graphql")
}
#[get("/?<request>")]
pub fn get(request: GraphQLRequest, conn: DbConn, schema: State<Schema>) -> GraphQLResponse {
request.execute(&schema, &conn)
}
#[post("/", data = "<request>")]
pub fn post(request: GraphQLRequest, conn: DbConn, schema: State<Schema>) -> GraphQLResponse {
request.execute(&schema, &conn)
}

View File

@ -1,11 +0,0 @@
//! 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!()
}

View File

@ -1,43 +0,0 @@
//! 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!()
}

View File

@ -49,14 +49,13 @@ fn rocket() -> Rocket {
.attach(DbConn::fairing())
.attach(AdHoc::on_attach("Database Migrations", run_db_migrations))
.manage(graphql::Schema::new(graphql::Query, graphql::Mutation))
.mount("/", routes![handlers::index])
.mount(
"/graphql",
"/",
routes![
handlers::graphql::playground,
handlers::graphql::graphiql,
handlers::graphql::get,
handlers::graphql::post,
handlers::index,
handlers::graphql_playground,
handlers::graphql_get,
handlers::graphql_post,
],
)
.mount("/static", static_files)