DEV Community

Adam Miedema
Adam Miedema

Posted on • Originally published at Medium on

How to create a to-do list app with Alpas

I created a quick to-do list app to better familiarize myself with some of Alpas’s key features and I want to share my example with you! 🚀

Here is a quick-start tutorial that will help guide you though creating your very own to-do list app as well as giving you a tour through a few of Alpas’s features, such as:

  • How to get Alpas setup and running on your local device
  • How to connect with a MySQL database
  • How to create database tables in Alpas and migrate them
  • How to create, retrieve, update, and delete data in your MySQL database
  • How to create a database entity object
  • How to create a controller
  • How to add routes
  • How to interact with the MySQL database using Ozone
  • How to protect your app against the cross site request forgery attacks
  • How to connect an interactive front-end with the powerful Alpas back-end
  • How to create a fun, yet useful to-do list! ✅

Here is a snippet from the guide on how you can store a new to-do task to your database (just to give you a taste 🍦 🙂).

// Let's create a function to store a new todo item that have been added via a form.

    fun store(call: HttpCall) {

        // Before we write the new todo task to the database, 
        // let's first validate to
        // make sure there is data with at least 2 characters. 
        // If validation fails,
        // a message will be sent back to the user with the failure 
        // reasons.

        call.applyRules("newTask") {
            required()
            min(2)
        }.validate()

        // If validation has passed, then create a new todo item in  
        // the database

        Tasks.create() {
            // Get the name of the task that was passed
            val taskName = call.stringParam("newTask")
            it.name to taskname
        }

        // If a new todo task has successfully been created and   
        // saved to the database,
        // let's send a success message back to the user to let them  
        // know.

        flash("success", "Successfully added to-do")
        call.redirect().back()
    }

Top comments (0)