Skip to main content

Simple Book Borrowing using Grails

Posted by brunogh on February 4, 2009 at 5:06 PM PST

This post is simple. In the company that I am working, we have some local area books that have a different control. Because they are out of the normal process, we do not have anything to control the borrowing. That can cause a problem, because sometimes people can accidentally forget that borrowed a book (sometimes I cannot remember what day is in the week and I think I work with crazier guys). So, the problem is simple and the use case will be too. Basically, someone that is responsible for the books will rent them for the team. Why not develop this fast application using Grails?!

Grails, which means Groovy on Rails, is an "agile" framework that uses Spring and Hibernate with a lot of code by convention. NetBeans 6.5 has an interesting support for its development, you can find instructions on how to start here. Anyway, I decided to start programming the application described using gedit and console in order to learn from the beginning and actually type the Gant commands. It took me a few hours to set a first version of the application and I am definitely still learning, but I can guarantee fore sure that Grails is very fast and fun.

The application has two domain classes, a Book, that represents the instance itself (we usually do not have copies), and a Rent, that represents the act of borrowing the book. The application also contains other domain classes (User, Role, Requestmap) that came from the Acegi Plugin installed, which will manage permissions and URLs. All those domain classes have its controllers and views. I also have added a AdminController for the admin area and HomeController for the default home page, mapped in grails-app/conf/UrlMapping.groovy. The index home view uses a home decorator available at /grails-app/views/layout, specified by the meta name="layout" content="home" tag in its gsp page. The application uses a lot of scaffolding for the CRUDs and also have loved the dynamic finders to create the queries. Finally, have generated the war and deployed it on a Tomcat server using the production configuration with a MySQL database, specified in grails-app/conf/DataSource.groovy file.

You can download BookBorrowing here. Feel free to modify and do whatever you want.

Home - list all the availables books for borrow and has a search

screenshot.png

Admin area

screenshot2.png

Rent view in the Admin area - "Devolver" means return this book, "Devolvido" means list of returned books and "Emprestados" means the currently borrowed. Need to i18n, gonna do it soon.

screenshot3.png

Cheers! Have fun!!!

Bruno Ghisi

Related Topics >>