RejectedSoftware Forums

Sign up

Can we add this to WebInterface?

I am planning to build a command-line generator for fast prototyping that looks like this

scaffold books --fields="id:pk, title:string(255), summary:text:nullable, created_at:datetime, updated_at:timestamp, author_id:int:nullable:fk:authors"

the command above would produce a

database table named books (plural for relational databases, I might use DDBC or HibernateD, I don't know how to use NoSql)
Struct (for hibernated)
create statement (for ddbc)
Route

router.registerWebInterface(new Book);

WebInterface with
index() and index.dt with a boiler code for datagrid with basic functions create, edit, delete, search, reorder, etc...

However I would like to suggest some additional classes and or functions, since the original goal of the webframework is to create a better and solid experience when coding...

Input Class
req.form and url values should be mapped to this Class so that it is accessible using

Input.all(); //returns posts and get values json form
Input.get('title'); //post and get values json form

Input.head('get').only('id'); // returns id only on GET HTTP verb
Input.head('post').only('id','title'); // returns id and title only on POST HTTP verb

Input.head('get').except('id'); // returns all except id on GET HTTP verb
Input.head('post').except('id','title'); // returns id only on POST HTTP verb

Input.only('id'); // returns id only POST or GET head
Input.except('id'); // returns all except id POST or GET head

Input.has('title'); //checks both POST and GET heads for the key

Validation Class

Validation.check(string inputs[string], string rules[string]); //
Validation.passes(); // return true or false
Validation.fails(); // returns true or false
Validation.messages(); // returns array of error messages

Allow the access of Session class and add additional functions instead of using the "SessionVar!". I don't know, for some reason I am getting confused with it, and also getting confused with res.startSession and res.session, and there is also req.session. I did check that there is a Session Class, I actually noticed that the example in the opApply API Documentation was not included in the "code format"...

Ok so here are the functions...
Session Class

Session.storage('memory','file','database','redis'); // etc
Session.all(); // get all json
Session.set('key', '1');
Session.get('key');
Session.take('key'); // get and forget
Session.has('key');
Session.flush(); // delete all key
Session.regenerate(); // regenerate sessions

Consider the method "store" below, which uses some of the functions above Session.take, Validation, and Input...


	auto rules = [
		"title":"required|min:2|max:255|alphanumeric",
		"summary":"alphanumeric",
		"created_at":"date-format:yyyy-mm-dd"
	];

/**
 * Store a newly created resource in storage.
 *
 * @return HTTPServerResponse
 */
@method(HTTPMethod.POST) @path("/book")
void store(){
  // get only posts values and dont include the nonce
  auto inputs = Input.head('post').except('nonce');

  // compute for nonce
  if(Input.get('nonce') != Session.take('nonce')){
	redirect("book/create").withInput(inputs).withMessage("Nonce not the same");
  }


  // Validation
  bool validate = Validation.check(inputs, this.rules);
  if(Validation.passes()){
    if(DB.save(inputs, this.table_name)){
      // return to books with Success Message
      redirect("/books").withMessage("Successfully Saved!");
    }else{
     redirect("book/create").withInput(inputs).withMessage(DB.error());
	}
  }else{
  	redirect("/book/create").withInput(inputs).withMessage(Validation.messages());
  }
}

the .withInput and .withMessage functions will just save the values to a session, on the "book/create" will check if there is an input or a message, the input will be used to repopulate the fields with values, the messages will tell what the error was, ex. Required, Minimum 10 Characters, Maximum 255 characters, Number only, Date only, pattern didn't match, etc...

I have not even included the upload file and the higher level file, Cookie methods that I was thinking like file.rename(), file.move(), Cookies.forever()... Please let me know your thoughts about this...

Thanks!

Re: Can we add this to WebInterface?

Sorry for not having answered so far, I'll have a closer look at this ASAP.