diff --git a/grails-app/controllers/rooms/AdminController.groovy b/grails-app/controllers/rooms/AdminController.groovy deleted file mode 100644 index c11140a..0000000 --- a/grails-app/controllers/rooms/AdminController.groovy +++ /dev/null @@ -1,6 +0,0 @@ -package rooms - -class AdminController { - - static scaffold = Admin -} diff --git a/grails-app/controllers/rooms/RoomController.groovy b/grails-app/controllers/rooms/RoomController.groovy index ec3313b..4e59c17 100644 --- a/grails-app/controllers/rooms/RoomController.groovy +++ b/grails-app/controllers/rooms/RoomController.groovy @@ -4,25 +4,12 @@ class RoomController { static scaffold = Room - def tryRoom() { -// List rooms = Room.list() -// List rooms = Room.listOrderByCapacity() - - Admin hans = new Admin(name: "Hans", tel: "1234", cardNumber: "1234").save() - Admin grete = new Admin(name: "Grete", tel: "4321", cardNumber: "4321").save() - - new Room(name: "5.1C56", capacity: 40, admin: hans).save() - // java style -// for (int i = 0; i < 10; i++) { -// new Room(name: "Room " + i, capacity: i * 5).save() -// } - // groovy style - 10.times { n -> - new Room(name: "Room " + n, capacity: n * 5, admin: grete).save() - } + def tryRoom() { // experiment with dynamic finder methods + List rooms = Room.list() +// List rooms = Room.listOrderByCapacity() // List rooms = Room.findAllByCapacityGreaterThan(30) - List rooms = Room.findAllByAdmin(grete) + String result = rooms.toString() render text: result } diff --git a/grails-app/domain/rooms/Admin.groovy b/grails-app/domain/rooms/Admin.groovy deleted file mode 100644 index 9923ec9..0000000 --- a/grails-app/domain/rooms/Admin.groovy +++ /dev/null @@ -1,18 +0,0 @@ -package rooms - -class Admin { - - String name - String tel - String cardNumber - - public String toString() { - return name; - } - - static constraints = { - name nullable: false, blank: false - tel nullable: true - cardNumber nullable: true - } -} diff --git a/grails-app/domain/rooms/Booking.groovy b/grails-app/domain/rooms/Booking.groovy index 820b466..46c6119 100644 --- a/grails-app/domain/rooms/Booking.groovy +++ b/grails-app/domain/rooms/Booking.groovy @@ -2,10 +2,21 @@ package rooms class Booking { + String purpose = "Lecture" Person person Room room - Date bookingDate + Date bookingDate // a date where we ignore the time and assume 00:00:00 + String timeslot // one of AM, PM1, PM2 + + public static final String AM = "08:15 - 11:00" + public static final String PM1 = "12:15 - 15:00" + public static final String PM2 = "15:15 - 18:00" static constraints = { + purpose () + person nullable: false + room nullable: false + bookingDate nullable: false + timeslot nullable: false, inList: [AM, PM1, PM2] } } diff --git a/grails-app/domain/rooms/Room.groovy b/grails-app/domain/rooms/Room.groovy index 2021488..a39f37c 100644 --- a/grails-app/domain/rooms/Room.groovy +++ b/grails-app/domain/rooms/Room.groovy @@ -3,16 +3,14 @@ package rooms class Room { String name int capacity - Admin admin String toString() { - "$name ($capacity ${admin?.name})" // groovy style -// return name + " (" + capacity + ")"; // java style + "$name ($capacity)" // groovy style +// return name + " (" + capacity + ")"; // java style } static constraints = { name nullable: false, blank: false capacity min: 0 - admin nullable: true } } diff --git a/src/main/resources/public/Jokes.html b/src/main/resources/public/Jokes.html new file mode 100644 index 0000000..8efa0c4 --- /dev/null +++ b/src/main/resources/public/Jokes.html @@ -0,0 +1,41 @@ + + + + + + Jokes + + + + +

+ Programmer jokes from jokeapi +

+ + + +
+ fetching ... +
+ + + + + diff --git a/src/main/resources/public/Pictures.html b/src/main/resources/public/Pictures.html new file mode 100644 index 0000000..a7063e3 --- /dev/null +++ b/src/main/resources/public/Pictures.html @@ -0,0 +1,58 @@ + + + + + + Pictures + + + + +

+ Pictures +

+ +
+ Click me to find interesting images on flickr. +
+ + + + \ No newline at end of file diff --git a/src/test/groovy/rooms/BookingSpec.groovy b/src/test/groovy/rooms/BookingSpec.groovy new file mode 100644 index 0000000..4429cd4 --- /dev/null +++ b/src/test/groovy/rooms/BookingSpec.groovy @@ -0,0 +1,57 @@ +package rooms + +import grails.testing.gorm.DomainUnitTest +import spock.lang.Specification + +import static rooms.BootStrap.today + +class BookingSpec extends Specification implements DomainUnitTest { + Person john + Room room_1 + Booking booking_1 + + def setup() { + john = new Person(firstName: "John", lastName: "Smith").save() + room_1 = new Room(name: "Room 1", capacity: 10).save() + booking_1 = new Booking( + person: john, + room: room_1, + bookingDate: today, + timeslot: Booking.AM) + .save() + } + + def cleanup() { + john.delete() + room_1.delete() + booking_1.delete() + } + + void "test constructor"() { + when:"sample data is loaded" + def bookings = Booking.list() + + then:"there is a booking" + bookings.size() == 1 + } + + void "simple finder methods"() { + expect: + [booking_1] == Booking.findAllByPerson(john) + [booking_1] == Booking.findAllByRoom(room_1) + [booking_1] == Booking.findAllByBookingDate(today) + [booking_1] == Booking.findAllByTimeslot(Booking.AM) + [] == Booking.findAllByTimeslot(Booking.PM1) + "Lecture" == Booking.findAllByPurpose("Lecture").first().purpose + } + + void "find all names of all rooms booked by john"() { + expect: + ["Room 1"] == Booking.findAllByPerson(john).room.name + } + + void "find the first names of all people that booked rooms today or in the future"() { + expect: + ["John"] == Booking.findAllByBookingDateGreaterThanEquals(today).person.firstName + } +} diff --git a/src/test/groovy/rooms/PersonSpec.groovy b/src/test/groovy/rooms/PersonSpec.groovy new file mode 100644 index 0000000..8f3cc40 --- /dev/null +++ b/src/test/groovy/rooms/PersonSpec.groovy @@ -0,0 +1,24 @@ +package rooms + +import grails.testing.gorm.DomainUnitTest +import spock.lang.Specification + +class PersonSpec extends Specification implements DomainUnitTest { + + def setup() { + } + + def cleanup() { + } + + void "test constructor"() { + given : + new Person(firstName: "John", lastName: "Smith").save() + new Person(firstName: "Jane", lastName: "Doe").save() + when:"sample data is loaded" + def people = Person.list() + + then:"there are 2 people" + people.size() == 2 + } +} diff --git a/src/test/groovy/rooms/RoomSpec.groovy b/src/test/groovy/rooms/RoomSpec.groovy new file mode 100644 index 0000000..4e652d5 --- /dev/null +++ b/src/test/groovy/rooms/RoomSpec.groovy @@ -0,0 +1,25 @@ +package rooms + +import grails.testing.gorm.DomainUnitTest +import spock.lang.Specification + +class RoomSpec extends Specification implements DomainUnitTest { + + def setup() { + } + + def cleanup() { + } + + void "test constructor"() { + given: + new Room(name: "Room 1", capacity: 10).save() + new Room(name: "Room 2", capacity: 20).save() + new Room(name: "Room 3", capacity: 30).save() + when:"sample data is loaded" + def rooms = Room.list() + + then:"there are 3 rooms" + rooms.size() == 3 + } +}