-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare for persistent domain classes
- Loading branch information
Dierk Koenig
committed
Oct 21, 2024
1 parent
c5086b3
commit a514743
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# WebEngineering Module, Persistence | ||
|
||
## Goals | ||
|
||
### Abilities | ||
- From a greenfield, being able to use a relational database with create-read-update-delete (CRUD) | ||
functionality in a webapp. | ||
- Use of simple entities, many-to-one, and many-to-many relations. | ||
|
||
### Knowledge | ||
- Understanding Grails domain classes as simple entities. | ||
- Understanding Grails domain classes with references as relations. | ||
- Understanding dynamic finder methods | ||
|
||
## Resources | ||
|
||
http://docs.grails.org/latest/guide/GORM.html | ||
|
||
## Demo / Live-coding | ||
|
||
- Creating a room reservation system | ||
- Domain classes: Room, Person, Booking (very simple) | ||
- Static scaffolding | ||
- Setting up bootstrap data | ||
- Use Controller actions to interact with the domain model | ||
|
||
## practical work | ||
|
||
- create an action that displays all bookings of a given person | ||
- create an action that displays all available rooms for a requested time slot today | ||
|
||
## Homework | ||
|
||
Finish the practical work | ||
|
||
Build on the practical work from above to | ||
create a full Web MVC-Cycle (without scaffolding) that shows | ||
|
||
- all bookings from today until eternity for a given person | ||
- all available rooms for a requested day and time slot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,47 @@ | ||
package rooms | ||
|
||
import grails.util.Environment | ||
|
||
import java.time.LocalDate | ||
|
||
class BootStrap { | ||
|
||
static Date today = toUtilDate(LocalDate.now()) | ||
static Date tomorrow = toUtilDate(LocalDate.now().plusDays(1)) | ||
static Date yesterday = toUtilDate(LocalDate.now().minusDays(1)) | ||
|
||
/** | ||
* This method is called when the server starts. | ||
*/ | ||
def init = { servletContext -> | ||
|
||
if (Environment.current == Environment.PRODUCTION) { // guard clause | ||
return | ||
} | ||
|
||
|
||
} | ||
|
||
def destroy = { | ||
} | ||
} | ||
|
||
/** | ||
* Convenience method to save a domain object and throw an exception if validation fails. | ||
* @param domainObject | ||
* @return Object - the saved domain object | ||
*/ | ||
static <T> T save(T domainObject) { | ||
domainObject.save(failOnError: true) // will throw an exception if validation fails | ||
return domainObject | ||
} | ||
|
||
/** | ||
* Convenience method to convert a LocalDate to a java.util.Date | ||
* @param localDate | ||
* @return Date - a java.util.Date | ||
*/ | ||
static Date toUtilDate(LocalDate localDate) { | ||
// this is not the best way to do it in general but it works for our purposes | ||
return new Date(localDate.toEpochDay() * 24 * 60 * 60 * 1000) | ||
} | ||
} |