├── .gitignore ├── .travis.yml ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── kotlin │ └── com │ │ └── yetanotherdevblog │ │ ├── DbInitializer.kt │ │ ├── ReactiveApplication.kt │ │ └── petclinic │ │ ├── Extensions.kt │ │ ├── PetClinicRoutes.kt │ │ ├── handlers │ │ ├── OwnersHandler.kt │ │ ├── PetTypeHandler.kt │ │ ├── PetsHandler.kt │ │ ├── SpecialitiesHandler.kt │ │ ├── VetsHandler.kt │ │ ├── VisitHandler.kt │ │ ├── WelcomeHandler.kt │ │ └── api │ │ │ ├── OwnersApiHandler.kt │ │ │ └── PetsApiHandler.kt │ │ ├── model │ │ ├── Owner.kt │ │ ├── Pet.kt │ │ ├── PetType.kt │ │ ├── Speciality.kt │ │ ├── Vet.kt │ │ └── Visit.kt │ │ └── repositories │ │ ├── OwnersRepository.kt │ │ ├── PetRepository.kt │ │ ├── PetTypeRepository.kt │ │ ├── SpecialityRepository.kt │ │ ├── VetRepository.kt │ │ └── VisitRepository.kt └── resources │ ├── application.properties │ ├── static │ └── resources │ │ ├── css │ │ └── default.css │ │ ├── fonts │ │ ├── basic.icons.eot │ │ ├── basic.icons.svg │ │ ├── basic.icons.ttf │ │ ├── basic.icons.woff │ │ ├── icons.eot │ │ ├── icons.otf │ │ ├── icons.svg │ │ ├── icons.ttf │ │ └── icons.woff │ │ └── images │ │ ├── bg.jpg │ │ ├── loader-large-inverted.gif │ │ ├── loader-large.gif │ │ ├── loader-medium-inverted.gif │ │ ├── loader-medium.gif │ │ ├── loader-mini-inverted.gif │ │ ├── loader-mini.gif │ │ ├── loader-small-inverted.gif │ │ ├── loader-small.gif │ │ └── pets.png │ └── templates │ ├── fragments │ ├── bodyFooter.html │ ├── bodyHeader.html │ └── headTag.html │ ├── owners │ ├── add.html │ ├── edit.html │ ├── index.html │ └── view.html │ ├── petTypes │ ├── add.html │ ├── edit.html │ └── index.html │ ├── pets │ ├── add.html │ └── edit.html │ ├── specialities │ ├── add.html │ ├── edit.html │ └── index.html │ ├── vets │ ├── add.html │ ├── edit.html │ └── index.html │ ├── visits │ ├── add.html │ └── edit.html │ └── welcome.html └── test └── kotlin └── com └── yetanotherdevblog ├── ApiTest.kt ├── CollectionTests.kt ├── OwnersHandlerTest.kt ├── VariousTests.kt └── WebsiteTest.kt /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .idea/ 3 | *.iml 4 | *.ipr 5 | *.iws 6 | *.log 7 | .gradle/ 8 | classes/ 9 | out/ 10 | node/ 11 | node_modules/ 12 | src/main/resources/static/css/ 13 | src/main/resources/static/images/ 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | script: 5 | - ./gradlew build 6 | branches: 7 | only: 8 | - master -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [PetClinic (Kotlin/Spring 5/Reactive)](https://ssouris.github.io/2017/06/02/petclinic-spring-5-kotlin-reactive-mongodb.html) 2 | [![Build Status](https://travis-ci.org/ssouris/petclinic-spring5-reactive.svg)](https://travis-ci.org/ssouris/petclinic-spring5-reactive) 3 | 4 | ### Description 5 | PetClinic application using Kotlin, Spring 5 with the reactive APIs (Reactor). 6 | You can find the related blog [here](https://ssouris.github.io/2017/06/02/petclinic-spring-5-kotlin-reactive-mongodb.html). 7 | 8 | ### Technologies used 9 | 10 | - Language: [Kotlin](https://kotlin.link/) 11 | - Web framework: [Spring Boot](https://projects.spring.io/spring-boot/) and [Spring Web Reactive Functional](https://spring.io/blog/2016/09/22/new-in-spring-5-functional-web-framework) 12 | - Engine: [Netty](http://netty.io/) used for client and server 13 | - Reactive API: [Reactor](http://projectreactor.io/) 14 | - Persistence : [Spring Data Reactive MongoDB](https://spring.io/blog/2016/11/28/going-reactive-with-spring-data) 15 | - Build: [Gradle Script Kotlin](https://github.com/gradle/gradle-script-kotlin) 16 | - Testing: [Junit](http://junit.org/) 17 | 18 | ### Run the app in dev mod using command line 19 | - Run `./gradlew bootRun` in another terminal 20 | - Open `http://localhost:8080/` in your browser 21 | - If you want to debug the app, add `--debug-jvm` parameter to Gradle command line 22 | 23 | ### Package and run the application from the executable JAR: 24 | ``` 25 | ./gradlew clean build 26 | java -jar build/libs/petclinic-spring5-kotlin-1.0.0-SNAPSHOT.jar 27 | ``` 28 | 29 | ### TODO 30 | 31 | - Validation on save/edit 32 | - Error handling (what happens when an entity is not present in the db) 33 | 34 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | 3 | version = "1.0.0-SNAPSHOT" 4 | 5 | buildscript { 6 | repositories { 7 | mavenCentral() 8 | maven { setUrl("https://repo.spring.io/milestone") } 9 | } 10 | 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M1") 13 | } 14 | } 15 | 16 | plugins { 17 | val kotlinVersion = "1.1.2" 18 | id("org.jetbrains.kotlin.jvm") version kotlinVersion 19 | id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion 20 | id("org.jetbrains.kotlin.plugin.noarg") version kotlinVersion 21 | id("io.spring.dependency-management") version "1.0.3.RELEASE" 22 | } 23 | 24 | apply { 25 | plugin("org.springframework.boot") 26 | } 27 | 28 | repositories { 29 | mavenCentral() 30 | maven { setUrl("https://repo.spring.io/milestone") } 31 | maven { setUrl("https://repo.spring.io/snapshot") } 32 | } 33 | 34 | tasks.withType { 35 | kotlinOptions { 36 | jvmTarget = "1.8" 37 | } 38 | } 39 | 40 | noArg { 41 | annotation("org.springframework.data.mongodb.core.mapping.Document") 42 | } 43 | 44 | dependencies { 45 | compile("org.jetbrains.kotlin:kotlin-stdlib-jre8") 46 | compile("org.jetbrains.kotlin:kotlin-reflect") 47 | 48 | compile("org.springframework.boot:spring-boot-starter-webflux") { 49 | exclude(module = "hibernate-validator") 50 | } 51 | compileOnly("org.springframework:spring-context-indexer") 52 | compile("org.springframework.boot:spring-boot-starter-data-mongodb-reactive") 53 | compile("org.springframework.boot:spring-boot-starter-thymeleaf") 54 | compile("org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.0.RELEASE") 55 | 56 | testCompile("org.springframework.boot:spring-boot-starter-test") 57 | runtime("de.flapdoodle.embed:de.flapdoodle.embed.mongo") 58 | 59 | compile("io.projectreactor:reactor-kotlin-extensions:1.0.0.M2") 60 | testCompile("io.projectreactor.addons:reactor-test") 61 | 62 | compile("com.fasterxml.jackson.module:jackson-module-kotlin") 63 | compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") 64 | } 65 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.script.lang.kotlin.accessors.auto=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jun 14 18:24:53 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'petclinic-spring5-kotlin' 2 | rootProject.buildFileName = 'build.gradle.kts' 3 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/DbInitializer.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog 2 | 3 | import com.yetanotherdevblog.petclinic.model.* 4 | import com.yetanotherdevblog.petclinic.repositories.* 5 | import org.springframework.boot.CommandLineRunner 6 | import org.springframework.stereotype.Component 7 | import reactor.core.Disposable 8 | import reactor.core.publisher.Flux 9 | import reactor.core.publisher.Mono 10 | import java.time.LocalDate 11 | import java.util.* 12 | 13 | @Component 14 | class DbInitializer(val petTypeRepository: PetTypeRepository, 15 | val specialityRepository: SpecialityRepository, 16 | val vetRepository: VetRepository, 17 | val ownersRepository: OwnersRepository, 18 | val petRepository: PetRepository, 19 | val visitRepository: VisitRepository): CommandLineRunner { 20 | 21 | override fun run(vararg args: String?) { 22 | 23 | val ownerId = UUID.fromString("5bead0d3-cd7b-41e5-b064-09f48e5e6a08").toString() 24 | val petId = UUID.fromString("6bead0d3-cd7b-41e5-b064-09f48e5e6a08").toString() 25 | val secondPetId = UUID.fromString("6bead0d2-cd7b-41e5-b064-09f48e5e6a08").toString() 26 | val thirdPetId = UUID.fromString("6bead0a3-cd7b-41e5-b064-09f48e5e6a08").toString() 27 | val dogId = UUID.randomUUID().toString() 28 | 29 | petTypeRepository.deleteAll().subscribeOnComplete { 30 | val petTypes = listOf("cat", "lizard", "snake", "bird", "hamster", "dog") 31 | .map { if (it == "dog") PetType(name=it, id = dogId) else PetType(name = it) } 32 | petTypeRepository.saveAll(petTypes) 33 | .subscribeOnComplete { println("Added PetTypes") } 34 | } 35 | 36 | 37 | specialityRepository.deleteAll().subscribeOnComplete { 38 | val specialities = listOf("radiology", "dentistry", "surgery") 39 | .map {Speciality(name = it)} 40 | specialityRepository.saveAll(specialities) 41 | .subscribeOnComplete { println("Added Specialities") } 42 | } 43 | 44 | vetRepository.deleteAll().subscribeOnComplete { 45 | vetRepository.saveAll(listOf( 46 | Vet(firstName = "James", lastName="Carter"), 47 | Vet(firstName = "Helen", lastName="Leary", specialities = setOf("radiology")), 48 | Vet(firstName = "Linda", lastName="Douglas", specialities = setOf("dentistry", "surgery")), 49 | Vet(firstName = "Rafael", lastName="Ortega", specialities = setOf("surgery")), 50 | Vet(firstName = "Henry", lastName="Stevens", specialities = setOf("radiology")), 51 | Vet(firstName = "Sharon", lastName="Jenkins"))) 52 | .subscribeOnComplete { println("Added Vets") } 53 | } 54 | 55 | ownersRepository.deleteAll().subscribeOnComplete { 56 | ownersRepository.saveAll(listOf( 57 | Owner(firstName = "James", lastName="Owner", 58 | telephone = "+44 4444444", address = "Road St", 59 | city = "Serverless", 60 | id = ownerId))) 61 | .subscribeOnComplete { println("Added Owners") } 62 | } 63 | 64 | petRepository.deleteAll().subscribeOnComplete { 65 | petRepository.saveAll(listOf( 66 | Pet(id = petId, name = "Pet 1", birthDate = LocalDate.now(), type = dogId, owner = ownerId), 67 | Pet(id = secondPetId, name = "Pet 2", birthDate = LocalDate.now(), type = dogId, owner = ownerId), 68 | Pet(id = thirdPetId, name = "Pet 3", birthDate = LocalDate.now(), type = dogId, owner = ownerId))) 69 | .subscribeOnComplete { println("Added Pets") } 70 | } 71 | 72 | visitRepository.deleteAll().subscribeOnComplete { 73 | visitRepository.saveAll(listOf( 74 | Visit(visitDate= LocalDate.now(), description = "Visit description ${Random().nextInt()}", petId= petId), 75 | Visit(visitDate= LocalDate.now(), description = "Visit description ${Random().nextInt()}", petId= petId), 76 | Visit(visitDate= LocalDate.now(), description = "Visit description ${Random().nextInt()}", petId= petId), 77 | Visit(visitDate= LocalDate.now(), description = "Visit description ${Random().nextInt()}", petId= secondPetId))) 78 | .subscribeOnComplete { println("Added Visits") } 79 | } 80 | 81 | } 82 | 83 | /** 84 | * Subscribe onComplete only. Used by db populators. 85 | */ 86 | private fun Mono.subscribeOnComplete(completeConsumer: () -> Unit) : Disposable { 87 | return this.subscribe(null, null, completeConsumer) 88 | } 89 | 90 | private fun Flux.subscribeOnComplete(completeConsumer: () -> Unit) : Disposable { 91 | return this.subscribe(null, null, completeConsumer) 92 | } 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/ReactiveApplication.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog 2 | 3 | import org.springframework.boot.SpringApplication 4 | import org.springframework.boot.autoconfigure.SpringBootApplication 5 | 6 | 7 | @SpringBootApplication 8 | class ReactiveApplication 9 | 10 | fun main(args: Array) { 11 | SpringApplication.run(ReactiveApplication::class.java, *args) 12 | } 13 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/Extensions.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic 2 | 3 | import org.springframework.data.mongodb.core.ReactiveMongoOperations 4 | import org.springframework.http.MediaType.APPLICATION_JSON_UTF8 5 | import org.springframework.http.MediaType.TEXT_EVENT_STREAM 6 | import org.springframework.http.MediaType.TEXT_HTML 7 | import org.springframework.web.reactive.function.server.ServerResponse 8 | import reactor.core.publisher.Flux 9 | import java.time.LocalDate 10 | import java.time.format.DateTimeFormatter 11 | 12 | inline fun ReactiveMongoOperations.findAll(): Flux = findAll(T::class.java) 13 | 14 | fun ServerResponse.BodyBuilder.json() = contentType(APPLICATION_JSON_UTF8) 15 | 16 | fun ServerResponse.BodyBuilder.textEventStream() = contentType(TEXT_EVENT_STREAM) 17 | 18 | fun ServerResponse.BodyBuilder.html() = contentType(TEXT_HTML) 19 | 20 | // Date Extension methods 21 | 22 | fun LocalDate.toStr(format:String = "dd/MM/yyyy") = DateTimeFormatter.ofPattern(format).format(this) 23 | 24 | fun String.toLocalDate(format:String = "dd/MM/yyyy") = LocalDate.parse(this, DateTimeFormatter.ofPattern(format)) -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/PetClinicRoutes.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic 2 | 3 | import com.yetanotherdevblog.petclinic.handlers.* 4 | import com.yetanotherdevblog.petclinic.handlers.api.OwnersApiHandler 5 | import com.yetanotherdevblog.petclinic.handlers.api.PetsApiHandler 6 | import org.springframework.context.annotation.Bean 7 | import org.springframework.context.annotation.Configuration 8 | import org.springframework.context.annotation.DependsOn 9 | import org.springframework.core.io.ClassPathResource 10 | import org.springframework.http.MediaType 11 | import org.springframework.web.reactive.function.server.RouterFunctions.resources 12 | import org.springframework.web.reactive.function.server.router 13 | 14 | 15 | @Configuration 16 | class PetClinicRoutes() { 17 | 18 | @Bean 19 | @DependsOn("petClinicRouter") 20 | fun resourceRouter() = resources("/**", ClassPathResource("static/")) 21 | 22 | @Bean 23 | fun apiRouter(ownersApiHandler: OwnersApiHandler, petsApiHandler: PetsApiHandler) = 24 | router { 25 | (accept(MediaType.APPLICATION_JSON) and "/api").nest { 26 | "/owners".nest { 27 | GET("/", ownersApiHandler::getOwners) 28 | GET("/{id}", ownersApiHandler::getOwner) 29 | } 30 | "/pets".nest { 31 | GET("/", petsApiHandler::getPets) 32 | GET("/{id}", petsApiHandler::getPet) 33 | GET("/{id}/visits", petsApiHandler::getPetVisits) 34 | } 35 | } 36 | } 37 | 38 | @Bean 39 | fun petClinicRouter(welcomeHandler: WelcomeHandler, 40 | ownersHandler: OwnersHandler, 41 | specialitiesHandler: SpecialitiesHandler, 42 | vetsHandler: VetsHandler, 43 | petsHandler: PetsHandler, 44 | petTypeHandler: PetTypeHandler, 45 | visitHandler: VisitHandler) = 46 | router { 47 | GET("/", welcomeHandler::welcome) 48 | "/owners".nest { 49 | GET("/", ownersHandler::indexPage) 50 | "/add".nest { 51 | GET("/", ownersHandler::addPage) 52 | POST("/", ownersHandler::add) 53 | } 54 | "/edit".nest { 55 | GET("/", ownersHandler::editPage) 56 | POST("/", ownersHandler::edit) 57 | } 58 | "/view".nest { 59 | GET("/", ownersHandler::view) 60 | } 61 | } 62 | "/vets".nest { 63 | GET("/", vetsHandler::indexPage) 64 | "/add".nest { 65 | GET("/", vetsHandler::addPage) 66 | POST("/", vetsHandler::add) 67 | } 68 | "/edit".nest { 69 | GET("/", vetsHandler::editPage) 70 | POST("/", vetsHandler::edit) 71 | } 72 | } 73 | "/pets".nest { 74 | "/add".nest { 75 | GET("/", petsHandler::addPage) 76 | POST("/", petsHandler::add) 77 | } 78 | "/edit".nest { 79 | GET("/", petsHandler::editPage) 80 | POST("/", petsHandler::edit) 81 | } 82 | } 83 | "/visits".nest { 84 | "/add".nest { 85 | GET("/", visitHandler::addPage) 86 | POST("/", visitHandler::add) 87 | } 88 | "/edit".nest { 89 | GET("/", visitHandler::editPage) 90 | POST("/", visitHandler::edit) 91 | } 92 | } 93 | "/specialities".nest { 94 | GET("/", specialitiesHandler::indexPage) 95 | "/add".nest { 96 | GET("/", specialitiesHandler::addPage) 97 | POST("/", specialitiesHandler::add) 98 | } 99 | "/edit".nest { 100 | GET("/", specialitiesHandler::editPage) 101 | POST("/", specialitiesHandler::edit) 102 | } 103 | } 104 | "/petTypes".nest { 105 | GET("/", petTypeHandler::indexPage) 106 | "/add".nest { 107 | GET("/", petTypeHandler::addPage) 108 | POST("/", petTypeHandler::add) 109 | } 110 | "/edit".nest { 111 | GET("/", petTypeHandler::editPage) 112 | POST("/", petTypeHandler::edit) 113 | } 114 | } 115 | 116 | } 117 | 118 | } 119 | 120 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/OwnersHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers 2 | 3 | import com.yetanotherdevblog.petclinic.html 4 | import com.yetanotherdevblog.petclinic.repositories.OwnersRepository 5 | 6 | import com.yetanotherdevblog.petclinic.model.Owner 7 | import com.yetanotherdevblog.petclinic.model.Pet 8 | import com.yetanotherdevblog.petclinic.model.Visit 9 | import com.yetanotherdevblog.petclinic.repositories.PetRepository 10 | import com.yetanotherdevblog.petclinic.repositories.PetTypeRepository 11 | import org.springframework.data.mongodb.core.ReactiveMongoTemplate 12 | import org.springframework.data.mongodb.core.query.Criteria 13 | import org.springframework.data.mongodb.core.query.Criteria.* 14 | import org.springframework.data.mongodb.core.query.Query 15 | import org.springframework.stereotype.Component 16 | import org.springframework.web.reactive.function.BodyExtractors 17 | import org.springframework.web.reactive.function.server.ServerRequest 18 | import org.springframework.web.reactive.function.server.ServerResponse 19 | import org.springframework.web.reactive.function.server.ServerResponse.ok 20 | import reactor.core.publisher.Mono 21 | import reactor.util.function.component1 22 | import reactor.util.function.component2 23 | import java.util.UUID 24 | 25 | @Component 26 | class OwnersHandler(val ownersRepository: OwnersRepository, 27 | val petRepository: PetRepository, 28 | val petTypeRepository: PetTypeRepository, 29 | val mongoTemplate: ReactiveMongoTemplate) { 30 | 31 | fun indexPage(serverRequest: ServerRequest) = 32 | serverRequest.queryParam("q").filter { it.trim().isNotEmpty() } 33 | .map { indexPageWithQuery(it) } 34 | .orElse(indexPage()) 35 | 36 | fun addPage(serverRequest: ServerRequest) = ok().html().render("owners/add") 37 | 38 | fun editPage(serverRequest: ServerRequest) = 39 | serverRequest.queryParam("id") 40 | .map { ownersRepository.findById(it) } 41 | .orElse(Mono.empty()) 42 | .map { mapOf("id" to it.id, 43 | "firstName" to it.firstName, 44 | "lastName" to it.lastName, 45 | "address" to it.address, 46 | "city" to it.city, 47 | "telephone" to it.telephone) 48 | } 49 | .flatMap { ok().html().render("owners/edit", it) } 50 | 51 | fun view(serverRequest: ServerRequest) = 52 | serverRequest.queryParam("id").map { ownersRepository.findById(it) }.orElse(Mono.empty()) 53 | .and({ (id) -> petRepository.findAllByOwner(id).collectList() }) 54 | .flatMap { (owner, pets) -> 55 | val model = mapOf( 56 | "owner" to owner, 57 | "pets" to pets, 58 | "petTypes" to petTypeRepository.findAll().collectMap({ it.id }, {it.name}), 59 | "petVisits" to petVisits(pets.map { it.id })) 60 | ok().html().render("owners/view", model) 61 | } 62 | .switchIfEmpty(ServerResponse.notFound().build()) 63 | 64 | fun petVisits(petIds: List) = 65 | mongoTemplate.find(Query(where("petId").`in`(petIds) ), Visit::class.java) 66 | .collectMultimap { it.petId } 67 | 68 | fun add(serverRequest: ServerRequest) = serverRequest.body(BodyExtractors.toFormData()) 69 | .flatMap { 70 | val formData = it.toSingleValueMap() 71 | ownersRepository.save(Owner( 72 | id = formData["id"] ?: UUID.randomUUID().toString(), 73 | firstName = formData["firstName"]!!, 74 | lastName = formData["lastName"]!!, 75 | address = formData["address"]!!, 76 | telephone = formData["telephone"]!!, 77 | city = formData["city"]!!)) 78 | } 79 | .then(indexPage()) 80 | 81 | fun edit(serverRequest: ServerRequest) = 82 | serverRequest.queryParam("id").map { ownersRepository.findById(it) }.orElse(Mono.empty()) 83 | .flatMap { ownersRepository.save(it) } 84 | .flatMap { ok().render("owners/edit", it) } 85 | 86 | fun indexPageWithQuery(query:String) = ok().html().render("owners/index", 87 | mapOf("owners" to findByNameLike(query) 88 | .map { Pair(it, emptySet()) }, 89 | "pets" to petRepository.findAll().collectMultimap { it.owner })) 90 | 91 | fun indexPage(): Mono = ok().html().render("owners/index", 92 | mapOf("owners" to ownersRepository.findAll().map { Pair(it, emptySet()) }, 93 | "pets" to petRepository.findAll().collectMultimap { it.owner })) 94 | 95 | fun findByNameLike(query:String) = mongoTemplate.find( 96 | Query(Criteria().orOperator( 97 | where("firstName").regex(query, "i"), 98 | where("lastName").regex(query, "i"))), Owner::class.java) 99 | 100 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/PetTypeHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers 2 | 3 | import com.yetanotherdevblog.petclinic.html 4 | import com.yetanotherdevblog.petclinic.model.PetType 5 | import com.yetanotherdevblog.petclinic.repositories.PetTypeRepository 6 | import org.springframework.http.MediaType 7 | import org.springframework.stereotype.Component 8 | import org.springframework.web.reactive.function.BodyExtractors 9 | import org.springframework.web.reactive.function.server.ServerRequest 10 | import org.springframework.web.reactive.function.server.ServerResponse.ok 11 | 12 | @Component 13 | class PetTypeHandler(val petTypeRepository: PetTypeRepository) { 14 | 15 | fun indexPage(serverRequest: ServerRequest) = indexPage() 16 | 17 | fun addPage(serverRequest: ServerRequest) = 18 | ok().contentType(MediaType.TEXT_HTML).render("petTypes/add") 19 | 20 | fun add(serverRequest: ServerRequest) = serverRequest.body(BodyExtractors.toFormData()) 21 | .flatMap { 22 | val formData = it.toSingleValueMap() 23 | petTypeRepository.save(PetType(name = formData["name"]!!)) 24 | } 25 | .then(indexPage()) 26 | 27 | fun editPage(serverRequest: ServerRequest) = 28 | petTypeRepository.findById(serverRequest.queryParam("id").orElseThrow{ IllegalArgumentException() }) 29 | .map { mapOf("id" to it.id, "name" to it.name) } 30 | .flatMap { ok().html().render("petTypes/edit", it) } 31 | 32 | fun edit(serverRequest: ServerRequest) = 33 | serverRequest.body(BodyExtractors.toFormData()) 34 | .flatMap { 35 | val formData = it.toSingleValueMap() 36 | petTypeRepository.save(PetType(id = formData["id"]!!, name = formData["name"]!!)) 37 | } 38 | .then(indexPage()) 39 | 40 | fun indexPage() = ok().html().render("petTypes/index", mapOf("petTypes" to petTypeRepository.findAll())) 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/PetsHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers 2 | 3 | import com.yetanotherdevblog.petclinic.html 4 | import com.yetanotherdevblog.petclinic.model.Pet 5 | import com.yetanotherdevblog.petclinic.repositories.OwnersRepository 6 | import com.yetanotherdevblog.petclinic.repositories.PetRepository 7 | import com.yetanotherdevblog.petclinic.repositories.PetTypeRepository 8 | import com.yetanotherdevblog.petclinic.toLocalDate 9 | import org.springframework.stereotype.Component 10 | import org.springframework.web.reactive.function.BodyExtractors 11 | import org.springframework.web.reactive.function.server.ServerRequest 12 | import org.springframework.web.reactive.function.server.ServerResponse.ok 13 | 14 | @Component 15 | class PetsHandler(val petRepository: PetRepository, 16 | val ownersRepository: OwnersRepository, 17 | val petTypeRepository: PetTypeRepository, 18 | val ownersHandler: OwnersHandler) { 19 | 20 | fun addPage(serverRequest: ServerRequest) = 21 | ok().html().render("pets/add", mapOf( 22 | "owner" to ownersRepository.findById( 23 | serverRequest.queryParam("ownerId").orElseThrow({IllegalArgumentException()})), 24 | "petTypes" to petTypeRepository.findAll())) 25 | 26 | fun add(serverRequest: ServerRequest) = serverRequest.body(BodyExtractors.toFormData()) 27 | .flatMap { 28 | val formData = it.toSingleValueMap() 29 | petRepository.save(Pet( 30 | name = formData["name"]!!, 31 | birthDate = formData["birthDate"]!!.toLocalDate(), 32 | owner = formData["ownerId"]!!, 33 | type = formData["typeId"]!!)) 34 | } 35 | .then(ownersHandler.indexPage()) 36 | 37 | fun editPage(serverRequest: ServerRequest) = 38 | petRepository.findById(serverRequest.queryParam("id").orElseThrow({IllegalArgumentException()})) 39 | .map { mapOf("pet" to it, 40 | "petTypes" to petTypeRepository.findAll(), 41 | "owner" to ownersRepository.findById(it.owner)) 42 | } 43 | .flatMap { ok().html().render("pets/edit", it) } 44 | 45 | fun edit(serverRequest: ServerRequest) = serverRequest.body(BodyExtractors.toFormData()) 46 | .flatMap { 47 | val formData = it.toSingleValueMap() 48 | petRepository.save(Pet( 49 | id = formData["id"]!!, 50 | name = formData["name"]!!, 51 | birthDate = formData["birthDate"]!!.toLocalDate(), 52 | owner = formData["ownerId"]!!, 53 | type = formData["type"]!!)) 54 | } 55 | .then(ownersHandler.indexPage()) 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/SpecialitiesHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers 2 | 3 | import com.yetanotherdevblog.petclinic.html 4 | import com.yetanotherdevblog.petclinic.model.Speciality 5 | import com.yetanotherdevblog.petclinic.repositories.SpecialityRepository 6 | import org.springframework.stereotype.Component 7 | import org.springframework.web.reactive.function.BodyExtractors 8 | import org.springframework.web.reactive.function.server.ServerRequest 9 | import org.springframework.web.reactive.function.server.ServerResponse.ok 10 | import java.util.UUID 11 | 12 | @Component 13 | class SpecialitiesHandler(val specialityRepository: SpecialityRepository) { 14 | 15 | fun indexPage(serverRequest: ServerRequest) = indexPage() 16 | 17 | fun addPage(serverRequest: ServerRequest) = ok().html().render("specialities/add") 18 | 19 | fun add(serverRequest: ServerRequest) = 20 | serverRequest.body(BodyExtractors.toFormData()) 21 | .flatMap { 22 | val formData = it.toSingleValueMap() 23 | specialityRepository.save(Speciality( 24 | id = UUID.randomUUID().toString(), name = formData["name"]!!)) 25 | } 26 | .then(indexPage()) 27 | 28 | fun editPage(serverRequest: ServerRequest) = 29 | specialityRepository.findById( 30 | serverRequest.queryParam("id").orElseThrow {IllegalArgumentException()}) 31 | .map { mapOf("id" to it.id, "name" to it.name) } 32 | .flatMap { ok().html().render("specialities/edit", it) } 33 | 34 | fun edit(serverRequest: ServerRequest) = 35 | serverRequest.body(BodyExtractors.toFormData()) 36 | .flatMap { 37 | val formData = it.toSingleValueMap() 38 | specialityRepository.save(Speciality( 39 | id = formData["id"]!!, 40 | name = formData["name"]!!)) 41 | } 42 | .then(indexPage()) 43 | 44 | fun indexPage() = ok().html().render("specialities/index", 45 | mapOf("specialities" to specialityRepository.findAll())) 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/VetsHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers 2 | 3 | import com.yetanotherdevblog.petclinic.html 4 | import com.yetanotherdevblog.petclinic.model.Vet 5 | import com.yetanotherdevblog.petclinic.repositories.SpecialityRepository 6 | import com.yetanotherdevblog.petclinic.repositories.VetRepository 7 | import org.springframework.stereotype.Component 8 | import org.springframework.web.reactive.function.BodyExtractors 9 | import org.springframework.web.reactive.function.server.ServerRequest 10 | import org.springframework.web.reactive.function.server.ServerResponse.ok 11 | import java.util.UUID 12 | 13 | @Component 14 | class VetsHandler(val vetRepository: VetRepository, 15 | val specialityRepository: SpecialityRepository) { 16 | 17 | fun indexPage(serverRequest: ServerRequest) = indexPage() 18 | 19 | fun addPage(serverRequest: ServerRequest) = 20 | ok().html().render("vets/add", mapOf("specialities" to specialityRepository.findAll())) 21 | 22 | fun add(serverRequest: ServerRequest) = serverRequest.body(BodyExtractors.toFormData()) 23 | .flatMap { 24 | formData -> 25 | vetRepository.save(Vet( 26 | id = UUID.randomUUID().toString(), 27 | firstName = formData["firstName"]?.get(0)!!, 28 | lastName = formData["lastName"]?.get(0)!!, 29 | specialities = formData["specialities"]?.toCollection(HashSet())!!)) 30 | } 31 | .then(indexPage()) 32 | 33 | fun editPage(serverRequest: ServerRequest) = 34 | vetRepository.findById( 35 | serverRequest.queryParam("id").orElseThrow({IllegalArgumentException()})) 36 | .map { mapOf("vet" to it, "specialities" to specialityRepository.findAll()) } 37 | .flatMap { ok().html().render("vets/edit", it) } 38 | 39 | fun edit(serverRequest: ServerRequest) = serverRequest.body(BodyExtractors.toFormData()) 40 | .flatMap { formData -> 41 | vetRepository.save(Vet( 42 | id = formData["id"]?.get(0)!!, 43 | firstName = formData["firstName"]?.get(0)!!, 44 | lastName = formData["lastName"]?.get(0)!!, 45 | specialities = formData["specialities"]?.toCollection(HashSet())!!)) 46 | } 47 | .then(indexPage()) 48 | 49 | fun indexPage() = ok().html().render("vets/index", mapOf("vets" to vetRepository.findAll())) 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/VisitHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers 2 | 3 | import com.yetanotherdevblog.petclinic.html 4 | import com.yetanotherdevblog.petclinic.model.Visit 5 | import com.yetanotherdevblog.petclinic.repositories.OwnersRepository 6 | import com.yetanotherdevblog.petclinic.repositories.PetRepository 7 | import com.yetanotherdevblog.petclinic.repositories.VisitRepository 8 | import com.yetanotherdevblog.petclinic.toLocalDate 9 | import com.yetanotherdevblog.petclinic.toStr 10 | import org.springframework.stereotype.Component 11 | import org.springframework.web.reactive.function.BodyExtractors 12 | import org.springframework.web.reactive.function.server.ServerRequest 13 | import org.springframework.web.reactive.function.server.ServerResponse.ok 14 | import java.util.UUID 15 | 16 | @Component 17 | class VisitHandler(val visitRepository: VisitRepository, 18 | val petRepository: PetRepository, 19 | val ownersRepository: OwnersRepository, 20 | val ownersHandler: OwnersHandler) { 21 | 22 | fun addPage(serverRequest: ServerRequest) = 23 | petRepository.findById( 24 | serverRequest.queryParam("petId").orElseThrow { IllegalArgumentException() }) 25 | .flatMap { pet -> 26 | ok().html().render("visits/add", mapOf( 27 | "owner" to ownersRepository.findById(pet.owner), 28 | "pet" to pet)) 29 | } 30 | 31 | fun add(serverRequest: ServerRequest) = 32 | serverRequest.body(BodyExtractors.toFormData()) 33 | .flatMap { 34 | val formData = it.toSingleValueMap() 35 | visitRepository.save(Visit( 36 | id = UUID.randomUUID().toString(), 37 | description = formData["description"]!!, 38 | petId = formData["petId"]!!, 39 | visitDate = formData["date"]!!.toLocalDate())) 40 | } 41 | .then(ownersHandler.indexPage()) 42 | 43 | 44 | fun editPage(serverRequest: ServerRequest) = 45 | visitRepository.findById( 46 | serverRequest.queryParam("id").orElseThrow({ IllegalArgumentException() })) 47 | .and { petRepository.findById(it.petId) } 48 | .map { 49 | val (visit, pet) = Pair(it.t1, it.t2) 50 | mapOf( 51 | Pair("id", visit.id), 52 | Pair("date", visit.visitDate.toStr()), 53 | Pair("description", visit.description), 54 | Pair("pet", pet), 55 | Pair("owner", ownersRepository.findById(pet.owner))) 56 | } 57 | .flatMap { ok().html().render("visits/edit", it) } 58 | 59 | 60 | fun edit(serverRequest: ServerRequest) = 61 | serverRequest.body(BodyExtractors.toFormData()) 62 | .flatMap { 63 | val formData = it.toSingleValueMap() 64 | visitRepository.save(Visit( 65 | id = formData["id"]!!, 66 | visitDate = formData["date"]!!.toLocalDate(), 67 | petId = formData["petId"]!!, 68 | description = formData["description"]!!)) 69 | } 70 | .then(ownersHandler.indexPage()) 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/WelcomeHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers 2 | 3 | import com.yetanotherdevblog.petclinic.html 4 | import org.springframework.stereotype.Component 5 | import org.springframework.web.reactive.function.server.ServerRequest 6 | import org.springframework.web.reactive.function.server.ServerResponse.ok 7 | 8 | @Component 9 | class WelcomeHandler { 10 | 11 | fun welcome(serverRequest: ServerRequest) = ok().html().render("welcome") 12 | 13 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/api/OwnersApiHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers.api 2 | 3 | import com.yetanotherdevblog.petclinic.model.Owner 4 | import com.yetanotherdevblog.petclinic.repositories.OwnersRepository 5 | import org.springframework.stereotype.Component 6 | import org.springframework.web.reactive.function.server.ServerRequest 7 | import org.springframework.web.reactive.function.server.ServerResponse.ok 8 | 9 | @Component 10 | class OwnersApiHandler(val ownersRepository: OwnersRepository) { 11 | 12 | fun getOwners(serverRequest: ServerRequest) = 13 | ok().body(ownersRepository.findAll(), Owner::class.java) 14 | 15 | fun getOwner(serverRequest: ServerRequest) = 16 | ok().body(ownersRepository.findById(serverRequest.pathVariable("id")), Owner::class.java) 17 | 18 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/handlers/api/PetsApiHandler.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.handlers.api 2 | 3 | import com.yetanotherdevblog.petclinic.model.Pet 4 | import com.yetanotherdevblog.petclinic.model.Visit 5 | import com.yetanotherdevblog.petclinic.repositories.PetRepository 6 | import com.yetanotherdevblog.petclinic.repositories.VisitRepository 7 | import org.springframework.stereotype.Component 8 | import org.springframework.web.reactive.function.server.ServerRequest 9 | import org.springframework.web.reactive.function.server.ServerResponse.ok 10 | 11 | @Component 12 | class PetsApiHandler(val petRepository: PetRepository, 13 | val visitRepository: VisitRepository) { 14 | 15 | fun getPets(serverRequest: ServerRequest) = 16 | ok().body(petRepository.findAll(), Pet::class.java) 17 | 18 | fun getPet(serverRequest: ServerRequest) = 19 | ok().body(petRepository.findById(serverRequest.pathVariable("id")), Pet::class.java) 20 | 21 | fun getPetVisits(serverRequest: ServerRequest) = 22 | ok().body(visitRepository.findByPetId(serverRequest.pathVariable("id")), Visit::class.java) 23 | 24 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/model/Owner.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.model 2 | 3 | import org.springframework.data.annotation.Id 4 | import org.springframework.data.mongodb.core.mapping.Document 5 | 6 | @Document 7 | data class Owner(@Id val id:String, 8 | val firstName: String, 9 | val lastName: String, 10 | val address: String, 11 | val city: String, 12 | val telephone: String) 13 | 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/model/Pet.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.model 2 | 3 | import org.springframework.data.annotation.Id 4 | import org.springframework.data.mongodb.core.mapping.DBRef 5 | import org.springframework.data.mongodb.core.mapping.Document 6 | import java.time.LocalDate 7 | import java.util.Date 8 | import java.util.UUID 9 | 10 | @Document 11 | data class Pet( 12 | @Id val id:String = UUID.randomUUID().toString(), 13 | val name: String, 14 | val birthDate: LocalDate, 15 | val type: String, 16 | val owner: String) 17 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/model/PetType.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.model 2 | 3 | import org.springframework.data.annotation.Id 4 | import org.springframework.data.mongodb.core.mapping.Document 5 | import java.util.UUID 6 | 7 | @Document 8 | data class PetType( 9 | @Id val id:String = UUID.randomUUID().toString(), 10 | val name: String) -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/model/Speciality.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.model 2 | 3 | import org.springframework.data.annotation.Id 4 | import org.springframework.data.mongodb.core.mapping.Document 5 | import java.util.UUID 6 | 7 | @Document 8 | data class Speciality( 9 | @Id val id: String = UUID.randomUUID().toString(), 10 | val name: String) -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/model/Vet.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.model 2 | 3 | import org.springframework.data.annotation.Id 4 | import org.springframework.data.mongodb.core.mapping.Document 5 | import java.util.UUID 6 | 7 | @Document 8 | data class Vet( 9 | @Id val id:String = UUID.randomUUID().toString(), 10 | val firstName: String, 11 | val lastName : String, 12 | val specialities: Set = emptySet()) 13 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/model/Visit.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.model 2 | 3 | import org.springframework.data.annotation.Id 4 | import org.springframework.data.mongodb.core.mapping.Document 5 | import java.time.LocalDate 6 | import java.util.* 7 | 8 | @Document 9 | data class Visit( 10 | @Id val id:String = UUID.randomUUID().toString(), 11 | val visitDate: LocalDate, 12 | val description: String, 13 | val petId: String) -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/repositories/OwnersRepository.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.repositories 2 | 3 | import com.yetanotherdevblog.petclinic.model.Owner 4 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository 5 | import org.springframework.stereotype.Repository 6 | 7 | @Repository interface OwnersRepository : ReactiveMongoRepository -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/repositories/PetRepository.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.repositories 2 | 3 | import com.yetanotherdevblog.petclinic.model.Pet 4 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository 5 | import org.springframework.stereotype.Repository 6 | import reactor.core.publisher.Flux 7 | 8 | @Repository interface PetRepository : ReactiveMongoRepository { 9 | 10 | fun findAllByOwner(id: String): Flux 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/repositories/PetTypeRepository.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.repositories 2 | 3 | import com.yetanotherdevblog.petclinic.model.PetType 4 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository 5 | import org.springframework.stereotype.Repository 6 | 7 | @Repository interface PetTypeRepository : ReactiveMongoRepository -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/repositories/SpecialityRepository.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.repositories 2 | 3 | import com.yetanotherdevblog.petclinic.model.Speciality 4 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository 5 | import org.springframework.stereotype.Repository 6 | import reactor.core.publisher.Flux 7 | 8 | @Repository interface SpecialityRepository : ReactiveMongoRepository { 9 | 10 | fun findAllByName(nameList: Iterable) : Flux 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/repositories/VetRepository.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.repositories 2 | 3 | import com.yetanotherdevblog.petclinic.model.Vet 4 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository 5 | import org.springframework.stereotype.Repository 6 | 7 | @Repository interface VetRepository : ReactiveMongoRepository -------------------------------------------------------------------------------- /src/main/kotlin/com/yetanotherdevblog/petclinic/repositories/VisitRepository.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog.petclinic.repositories 2 | 3 | import com.yetanotherdevblog.petclinic.model.Visit 4 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository 5 | import org.springframework.stereotype.Repository 6 | import reactor.core.publisher.Flux 7 | 8 | @Repository interface VisitRepository : ReactiveMongoRepository { 9 | 10 | fun findByPetId(petId: String) : Flux 11 | 12 | } -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.root=INFO 2 | server.port=${PORT:8082} 3 | 4 | custom.property=Lorem Ipsum -------------------------------------------------------------------------------- /src/main/resources/static/resources/css/default.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | font-size: 15px; 3 | height: 100%; 4 | } 5 | 6 | body { 7 | font-family: "Open Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif; 8 | background: #FFFFFF; 9 | background-image: url("../images/bg.jpg"); 10 | margin: 0px; 11 | padding: 0px; 12 | color: #555555; 13 | text-rendering: optimizeLegibility; 14 | min-width: 320px; 15 | } 16 | 17 | #example .container { 18 | width: auto; 19 | margin: 0 200px; 20 | } 21 | 22 | #example .ui.menu { 23 | padding: 0 200px; 24 | } 25 | 26 | #example .ui.footer.list { 27 | display: block; 28 | text-align: center; 29 | margin-bottom: 1.5rem; 30 | } -------------------------------------------------------------------------------- /src/main/resources/static/resources/fonts/basic.icons.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/fonts/basic.icons.eot -------------------------------------------------------------------------------- /src/main/resources/static/resources/fonts/basic.icons.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Created by FontForge 20100429 at Thu Sep 20 22:09:47 2012 6 | By root 7 | Copyright (C) 2012 by original authors @ fontello.com 8 | 9 | 10 | 11 | 24 | 26 | 28 | 30 | 32 | 35 | 37 | 41 | 44 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 65 | 68 | 71 | 74 | 76 | 80 | 86 | 89 | 91 | 101 | 103 | 105 | 108 | 110 | 112 | 115 | 118 | 121 | 123 | 125 | 127 | 129 | 131 | 133 | 135 | 137 | 140 | 142 | 146 | 149 | 153 | 158 | 161 | 163 | 165 | 169 | 172 | 174 | 178 | 181 | 184 | 191 | 193 | 196 | 199 | 203 | 206 | 209 | 213 | 217 | 219 | 221 | 223 | 225 | 228 | 231 | 234 | 237 | 240 | 243 | 245 | 247 | 250 | 253 | 255 | 258 | 262 | 264 | 266 | 268 | 270 | 273 | 275 | 278 | 283 | 289 | 292 | 295 | 299 | 301 | 304 | 307 | 311 | 315 | 317 | 322 | 325 | 329 | 334 | 341 | 344 | 347 | 351 | 354 | 358 | 362 | 367 | 372 | 377 | 380 | 385 | 388 | 392 | 398 | 401 | 403 | 409 | 411 | 413 | 418 | 422 | 425 | 428 | 431 | 434 | 436 | 440 | 443 | 446 | 449 | 450 | 451 | -------------------------------------------------------------------------------- /src/main/resources/static/resources/fonts/basic.icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/fonts/basic.icons.ttf -------------------------------------------------------------------------------- /src/main/resources/static/resources/fonts/basic.icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/fonts/basic.icons.woff -------------------------------------------------------------------------------- /src/main/resources/static/resources/fonts/icons.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/fonts/icons.eot -------------------------------------------------------------------------------- /src/main/resources/static/resources/fonts/icons.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/fonts/icons.otf -------------------------------------------------------------------------------- /src/main/resources/static/resources/fonts/icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/fonts/icons.ttf -------------------------------------------------------------------------------- /src/main/resources/static/resources/fonts/icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/fonts/icons.woff -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/bg.jpg -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/loader-large-inverted.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/loader-large-inverted.gif -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/loader-large.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/loader-large.gif -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/loader-medium-inverted.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/loader-medium-inverted.gif -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/loader-medium.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/loader-medium.gif -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/loader-mini-inverted.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/loader-mini-inverted.gif -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/loader-mini.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/loader-mini.gif -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/loader-small-inverted.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/loader-small-inverted.gif -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/loader-small.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/loader-small.gif -------------------------------------------------------------------------------- /src/main/resources/static/resources/images/pets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssouris/petclinic-spring5-reactive/7f9971d561853fe8570cf2cbc746a82f47353616/src/main/resources/static/resources/images/pets.png -------------------------------------------------------------------------------- /src/main/resources/templates/fragments/bodyFooter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 |
7 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/resources/templates/fragments/bodyHeader.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/resources/templates/fragments/headTag.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | <script type="text/javascript"> 19 | $("document").ready(function() { 20 | $('.ui.radio.checkbox').checkbox(); 21 | $('.ui.checkbox').checkbox(); 22 | }) 23 | </script> 24 | </head> 25 | <body> 26 | </body> 27 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/owners/add.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Add Owner')"> 4 | </head> 5 | <body> 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | firstName : { 10 | identifier : 'firstName', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please enter first name' 15 | } 16 | ] 17 | }, 18 | lastName : { 19 | identifier : 'lastName', 20 | rules : [ 21 | { 22 | type : 'empty', 23 | prompt : 'Please enter last name' 24 | } 25 | ] 26 | }, 27 | address : { 28 | identifier : 'address', 29 | rules : [ 30 | { 31 | type : 'empty', 32 | prompt : 'Please enter address' 33 | } 34 | ] 35 | }, 36 | city : { 37 | identifier : 'city', 38 | rules : [ 39 | { 40 | type : 'empty', 41 | prompt : 'Please enter city' 42 | } 43 | ] 44 | }, 45 | telephone : { 46 | identifier : 'telephone', 47 | rules : [ 48 | { 49 | type : 'empty', 50 | prompt : 'Please enter telephone' 51 | } 52 | ] 53 | } 54 | }) 55 | }) 56 | </script> 57 | 58 | <div th:include="fragments/bodyHeader (tab='add owner')" th:remove="tag"></div> 59 | 60 | <div class="container"> 61 | <h1 class="ui header">Add Owner</h1> 62 | 63 | <form method="post" action="add" role="form" class="ui form"> 64 | <div class="field"> 65 | <label for="firstName">First Name</label> 66 | <input type="text" id="firstName" name="firstName" placeholder="First Name"/> 67 | </div> 68 | <div class="field"> 69 | <label for="lastName">Last Name</label> 70 | <input type="text" id="lastName" name="lastName" placeholder="Last Name"/> 71 | </div> 72 | <div class="field"> 73 | <label for="address">Address</label> 74 | <input type="text" id="address" name="address" placeholder="Address"/> 75 | </div> 76 | <div class="field"> 77 | <label for="city">City</label> 78 | <input type="text" id="city" name="city" placeholder="City"/> 79 | </div> 80 | <div class="field"> 81 | <label for="telephone">Telephone</label> 82 | <input type="text" id="telephone" name="telephone" placeholder="Telephone"/> 83 | </div> 84 | <button type="submit" class="ui green submit button">Add</button> 85 | </form> 86 | </div> 87 | 88 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 89 | </body> 90 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/owners/edit.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Owner')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | firstName : { 10 | identifier : 'firstName', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please enter first name' 15 | } 16 | ] 17 | }, 18 | lastName : { 19 | identifier : 'lastName', 20 | rules : [ 21 | { 22 | type : 'empty', 23 | prompt : 'Please enter last name' 24 | } 25 | ] 26 | }, 27 | address : { 28 | identifier : 'address', 29 | rules : [ 30 | { 31 | type : 'empty', 32 | prompt : 'Please enter address' 33 | } 34 | ] 35 | }, 36 | city : { 37 | identifier : 'city', 38 | rules : [ 39 | { 40 | type : 'empty', 41 | prompt : 'Please enter city' 42 | } 43 | ] 44 | }, 45 | telephone : { 46 | identifier : 'telephone', 47 | rules : [ 48 | { 49 | type : 'empty', 50 | prompt : 'Please enter telephone' 51 | } 52 | ] 53 | } 54 | }) 55 | }) 56 | </script> 57 | 58 | <div th:include="fragments/bodyHeader (tab='edit owner')" th:remove="tag"></div> 59 | 60 | <div class="container"> 61 | <h1 class="ui header">Edit Owner</h1> 62 | 63 | <form method="post" action="edit" role="form" class="ui form"> 64 | <input type="hidden" id="id" name="id" th:value="${id}"/> 65 | <div class="field"> 66 | <label for="firstName">First Name</label> 67 | <input type="text" id="firstName" name="firstName" placeholder="First Name" th:value="${firstName}"/> 68 | </div> 69 | <div class="field"> 70 | <label for="lastName">Last Name:</label> 71 | <input type="text" id="lastName" name="lastName" placeholder="Last Name" th:value="${lastName}"/> 72 | </div> 73 | <div class="field"> 74 | <label for="address">Address:</label> 75 | <input type="text" id="address" name="address" placeholder="Address" th:value="${address}"/> 76 | </div> 77 | <div class="field"> 78 | <label for="city">City:</label> 79 | <input type="text" id="city" name="city" placeholder="City" th:value="${city}"/> 80 | </div> 81 | <div class="field"> 82 | <label for="telephone">Telephone:</label> 83 | <input type="text" id="telephone" name="telephone" placeholder="Telephone" th:value="${telephone}"/> 84 | </div> 85 | <button type="submit" class="ui blue submit button">Save</button> 86 | </form> 87 | </div> 88 | 89 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 90 | </body> 91 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/owners/index.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Owners')"></head> 4 | <body> 5 | 6 | <div th:include="fragments/bodyHeader (tab='owners')" th:remove="tag"></div> 7 | 8 | <div class="container"> 9 | <div class="ui grid"> 10 | <div class="seven wide column"> 11 | <h1 class="ui header">Owners</h1> 12 | </div> 13 | <div class="nine wide column"> 14 | <div class="ui icon input" style="float: right; margin-left: 1em;"> 15 | <form action="" method="get"> 16 | <input name="q" type="text" placeholder="Find owners..." th:value="${searchQuery}"/> 17 | </form> 18 | <i class="circular search icon"></i> 19 | </div> 20 | <a href="add" class="ui button green" style="float: right; margin-left: 1em;">Add Owner</a> 21 | </div> 22 | </div> 23 | 24 | <table class="ui table segment" th:if="${not owners.isEmpty()}"> 25 | <thead> 26 | <tr> 27 | <th>Name</th> 28 | <th>City</th> 29 | <th>Address</th> 30 | <th>Telephone</th> 31 | <th>Pets</th> 32 | </tr> 33 | </thead> 34 | <tbody> 35 | <tr th:each="owner: ${owners}"> 36 | <td><a th:href="@{/owners/view(id=${owner.first.id})}" 37 | th:text="${owner.first.firstName} + ' ' + ${owner.first.lastName}"></a></td> 38 | <td th:text="${owner.first.city}"></td> 39 | <td th:text="${owner.first.address}"></td> 40 | <td th:text="${owner.first.telephone}"></td> 41 | <td> 42 | <div th:if="${pets[owner.first.id] != null && not pets[owner.first.id].isEmpty()}"> 43 | <span class="ui small label teal" th:each="pet: ${pets[owner.first.id]}" th:text="${pet.name}"/> 44 | </div> 45 | </td> 46 | </tr> 47 | </tbody> 48 | </table> 49 | </div> 50 | 51 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 52 | </body> 53 | </html> 54 | -------------------------------------------------------------------------------- /src/main/resources/templates/owners/view.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Owner')"></head> 4 | <body> 5 | 6 | <div th:include="fragments/bodyHeader (tab='view owner')" th:remove="tag"></div> 7 | 8 | <div class="container"> 9 | <div class="ui grid"> 10 | <div class="twelve wide column"> 11 | <h1 class="ui header">Owner</h1> 12 | </div> 13 | <div class="four wide column"> 14 | <a th:href="@{/owners/edit(id=${owner.id})}" class="small ui right floated button blue">Edit Owner</a> 15 | </div> 16 | </div> 17 | 18 | <table class="ui table segment"> 19 | <tr> 20 | <th>Name</th> 21 | <td><i class="user icon"></i> <span th:text="${owner.firstName + ' ' + owner.lastName}"></span></td> 22 | </tr> 23 | <tr> 24 | <th>Address</th> 25 | <td><i class="map marker icon"></i> <span th:text="${owner.city + ', ' + owner.address}"></span></td> 26 | </tr> 27 | <tr> 28 | <th>Telephone</th> 29 | <td><i class="phone icon"></i> <span th:text="${owner.telephone}"></span></td> 30 | </tr> 31 | </table> 32 | 33 | <div class="ui grid"> 34 | <div class="twelve wide column"> 35 | <h2 class="ui header">Pets and Visits</h2> 36 | </div> 37 | <div class="four wide column"> 38 | <a th:href="@{/pets/add(ownerId=${owner.id})}" class="small ui right floated button green">Add Pet</a> 39 | </div> 40 | </div> 41 | 42 | <table class="ui table segment" th:if="${not pets.isEmpty()}"> 43 | <thead> 44 | <tr> 45 | <th style="width: 25%">Name</th> 46 | <th style="width: 25%">Type</th> 47 | <th style="width: 25%">Visit Date</th> 48 | <th style="width: 25%">Description</th> 49 | </tr> 50 | </thead> 51 | <tbody> 52 | <tr th:each="pet: ${pets}"> 53 | <td style="vertical-align: top"><a th:href="@{/pets/edit(id=${pet.id})}" th:text="${pet.name}"></a></td> 54 | <td style="vertical-align: top" th:text="${petTypes.get(pet.type)}"></td> 55 | <td colspan="2" style="padding: 0"> 56 | <table class="ui table small " style="width: 100%"> 57 | <tr th:each="visit: ${petVisits.get(pet.id)}"> 58 | <td style="width: 50%"> 59 | <a th:text="${#temporals.format(visit.visitDate, 'dd/MM/yyyy')}" th:href="@{/visits/edit(id=${visit.id})}"></a> 60 | </td> 61 | <td th:text="${visit.description}" style="width: 50%"/> 62 | </tr> 63 | <tr> 64 | <td colspan="2"> 65 | <a class="mini ui green button" th:href="@{/visits/add(petId=${pet.id})}">Add Visit</a> 66 | </td> 67 | </tr> 68 | </table> 69 | </td> 70 | </tr> 71 | </tbody> 72 | </table> 73 | </div> 74 | 75 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 76 | </body> 77 | </html> 78 | -------------------------------------------------------------------------------- /src/main/resources/templates/petTypes/add.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Add Pet Type')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | name : { 10 | identifier : 'name', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please enter name' 15 | } 16 | ] 17 | } 18 | }) 19 | }) 20 | </script> 21 | 22 | <div th:include="fragments/bodyHeader (tab='add petType')" th:remove="tag"></div> 23 | 24 | <div class="container"> 25 | <h1 class="ui header">Add Pet Type</h1> 26 | 27 | <form method="post" action="add" role="form" class="ui form"> 28 | <div class="field"> 29 | <label for="name">Name</label> 30 | <input type="text" id="name" name="name" placeholder="Name"/> 31 | </div> 32 | <button type="submit" class="ui blue submit button">Save</button> 33 | </form> 34 | </div> 35 | 36 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 37 | </body> 38 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/petTypes/edit.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Edit Pet Type')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | name : { 10 | identifier : 'name', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please enter name' 15 | } 16 | ] 17 | } 18 | }) 19 | }) 20 | </script> 21 | 22 | <div th:include="fragments/bodyHeader (tab='edit petType')" th:remove="tag"></div> 23 | 24 | <div class="container"> 25 | <h1 class="ui header">Edit Pet Type</h1> 26 | 27 | <form method="post" action="edit" role="form" class="ui form"> 28 | <input type="hidden" id="id" name="id" th:value="${id}"/> 29 | <div class="field"> 30 | <label for="name">Name</label> 31 | <input type="text" id="name" name="name" placeholder="Name" 32 | th:value="${name}"/> 33 | </div> 34 | <button type="submit" class="ui blue submit button">Save</button> 35 | </form> 36 | </div> 37 | 38 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 39 | </body> 40 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/petTypes/index.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Pet Types')"></head> 4 | <body> 5 | 6 | <div th:include="fragments/bodyHeader (tab='petTypes')" th:remove="tag"></div> 7 | 8 | <div class="container"> 9 | <div class="ui grid"> 10 | <div class="nine wide column"> 11 | <h1 class="ui header">Pet Types</h1> 12 | </div> 13 | <div class="seven wide column"> 14 | <a href="add" class="ui button green" style="float: right; margin-left: 1em;">Add Pet Type</a> 15 | </div> 16 | </div> 17 | 18 | <table class="ui table segment" th:if="${not petTypes.isEmpty()}"> 19 | <thead> 20 | <tr> 21 | <th>Name</th> 22 | <!--<th style="width: 30%"></th>--> 23 | </tr> 24 | </thead> 25 | <tbody> 26 | <tr th:each="petType: ${petTypes}"> 27 | <td> <a th:text="${petType.name}" th:href="@{edit(id=${petType.id})}"></a></td> 28 | <!--<td> 29 | <a href="@{edit(id=${petType.id})}" class="ui mini button blue" style="float: left; margin-right: 1em;">Edit</a> 30 | <form th:action="@{delete(id=${petType.id})}" method="post" style="float: left; margin-right: 1em;"><input type="submit" 31 | class="ui mini button red" 32 | value="Delete"/> 33 | </form> 34 | </td>--> 35 | </tr> 36 | </tbody> 37 | </table> 38 | </div> 39 | 40 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 41 | </body> 42 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/pets/add.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Add Pet')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | name : { 10 | identifier : 'name', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please enter pet name' 15 | } 16 | ] 17 | }, 18 | birthDate : { 19 | identifier : 'birthDate', 20 | rules : [ 21 | { 22 | type : 'empty', 23 | prompt : 'Please enter birth date' 24 | } 25 | ] 26 | } 27 | }) 28 | }) 29 | </script> 30 | 31 | <div th:include="fragments/bodyHeader (tab='add pet')" th:remove="tag"></div> 32 | 33 | <div class="container"> 34 | <h1 class="ui header">Add Pet</h1> 35 | 36 | <form method="post" action="add" role="form" class="ui form"> 37 | <input name="ownerId" type="hidden" th:value="${owner.id}"/> 38 | 39 | <div class="field"> 40 | <label for="ownerName">Owner</label> 41 | <input type="text" id="ownerName" th:value="${owner.firstName + ' ' + owner.lastName}" readonly="true"/> 42 | </div> 43 | <div class="field"> 44 | <label for="name">Name</label> 45 | <input type="text" id="name" name="name" placeholder="Name"/> 46 | </div> 47 | <div class="date field"> 48 | <label for="birthDate">Birth Date</label> 49 | <input type="text" id="birthDate" name="birthDate" placeholder="dd/MM/yyyy"/> 50 | </div> 51 | <div class="field"> 52 | <label>Type</label> 53 | </div> 54 | <div class="grouped inline fields ui segment"> 55 | <div th:each="petType : ${petTypes}" class="field"> 56 | <div class="ui radio checkbox"> 57 | <input type="radio" name="typeId" 58 | th:value="${petType.id}"/> 59 | <label th:text="${petType.name}"/> 60 | </div> 61 | </div> 62 | </div> 63 | <button type="submit" class="ui blue submit button">Save</button> 64 | </form> 65 | </div> 66 | 67 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 68 | </body> 69 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/pets/edit.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Edit Pet')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | name : { 10 | identifier : 'name', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please enter pet name' 15 | } 16 | ] 17 | }, 18 | birthDate : { 19 | identifier : 'birthDate', 20 | rules : [ 21 | { 22 | type : 'empty', 23 | prompt : 'Please enter birth date' 24 | } 25 | ] 26 | } 27 | }) 28 | }) 29 | </script> 30 | 31 | <div th:include="fragments/bodyHeader (tab='edit pet')" th:remove="tag"></div> 32 | 33 | <div class="container"> 34 | <h1 class="ui header">Edit Pet</h1> 35 | 36 | <form method="post" action="edit" role="form" class="ui form"> 37 | <input name="id" type="hidden" th:value="${pet.id}"/> 38 | <input name="ownerId" type="hidden" th:value="${owner.id}"/> 39 | 40 | <div class="field"> 41 | <label for="ownerName">Owner</label> 42 | <input type="text" id="ownerName" th:value="${owner.firstName + ' ' + owner.lastName}" readonly="true"/> 43 | </div> 44 | <div class="field"> 45 | <label for="name">Name</label> 46 | <input type="text" id="name" name="name" placeholder="Name" th:value="${pet.name}"/> 47 | </div> 48 | <div class="date field"> 49 | <label for="birthDate">Birth Date</label> 50 | <input type="text" id="birthDate" name="birthDate" placeholder="dd/MM/yyyy" 51 | th:value="${#temporals.format(pet.birthDate, 'dd/MM/yyyy')}"/> 52 | </div> 53 | <div class="field"> 54 | <label>Type</label> 55 | </div> 56 | <div class="grouped inline fields ui segment"> 57 | <div th:each="petType : ${petTypes}" class="field"> 58 | <div class="ui radio checkbox"> 59 | <input type="radio" th:field="*{pet.type}" name="typeId" 60 | th:value="${petType.id}"/> 61 | <label th:text="${petType.name}"/> 62 | </div> 63 | </div> 64 | </div> 65 | <button type="submit" class="ui blue submit button">Save</button> 66 | </form> 67 | </div> 68 | 69 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 70 | </body> 71 | </html> 72 | -------------------------------------------------------------------------------- /src/main/resources/templates/specialities/add.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Add Speciality')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | name : { 10 | identifier : 'name', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please enter name' 15 | } 16 | ] 17 | } 18 | }) 19 | }) 20 | </script> 21 | 22 | <div th:include="fragments/bodyHeader (tab='add speciality')" th:remove="tag"></div> 23 | 24 | <div class="container"> 25 | <h1 class="ui header">Add Speciality</h1> 26 | 27 | <form method="post" action="add" role="form" class="ui form"> 28 | <div class="field"> 29 | <label for="name">Name</label> 30 | <input type="text" id="name" name="name" placeholder="Name"/> 31 | </div> 32 | <button type="submit" class="ui blue submit button">Save</button> 33 | </form> 34 | </div> 35 | 36 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 37 | </body> 38 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/specialities/edit.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Edit Speciality')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | name : { 10 | identifier : 'name', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please enter name' 15 | } 16 | ] 17 | } 18 | }) 19 | }) 20 | </script> 21 | 22 | <div th:include="fragments/bodyHeader (tab='edit speciality')" th:remove="tag"></div> 23 | 24 | <div class="container"> 25 | <h1 class="ui header">Edit Speciality</h1> 26 | 27 | <form method="post" action="edit" role="form" class="ui form"> 28 | <input type="hidden" id="id" name="id" th:value="${id}"/> 29 | <div class="field"> 30 | <label for="name">Name</label> 31 | <input type="text" id="name" name="name" placeholder="Name" 32 | th:value="${name}"/> 33 | </div> 34 | <button type="submit" class="ui blue submit button">Save</button> 35 | </form> 36 | </div> 37 | 38 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 39 | </body> 40 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/specialities/index.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Specialities')"></head> 4 | <body> 5 | 6 | <div th:include="fragments/bodyHeader (tab='specialities')" th:remove="tag"></div> 7 | 8 | <div class="container"> 9 | <div class="ui grid"> 10 | <div class="nine wide column"> 11 | <h1 class="ui header">Specialities</h1> 12 | </div> 13 | <div class="seven wide column"> 14 | <a href="add" class="ui button green" style="float: right; margin-left: 1em;">Add Speciality</a> 15 | </div> 16 | </div> 17 | 18 | <table class="ui table segment" th:if="${not specialities.isEmpty()}"> 19 | <thead> 20 | <tr> 21 | <th>Name</th> 22 | </tr> 23 | </thead> 24 | <tbody> 25 | <tr th:each="speciality: ${specialities}"> 26 | <td> <a th:text="${speciality.name}" th:href="@{edit(id=${speciality.id})}"></a></td> 27 | </tr> 28 | </tbody> 29 | </table> 30 | </div> 31 | 32 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 33 | </body> 34 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/vets/add.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Add Veterinarian')"> 4 | </head> 5 | <body> 6 | 7 | <script type="text/javascript"> 8 | $(document).ready(function(){ 9 | $(".ui.form").form({ 10 | firstName : { 11 | identifier : 'firstName', 12 | rules : [ 13 | { 14 | type : 'empty', 15 | prompt : 'Please first name' 16 | } 17 | ] 18 | }, 19 | lastName : { 20 | identifier : 'lastName', 21 | rules : [ 22 | { 23 | type : 'empty', 24 | prompt : 'Please last name' 25 | } 26 | ] 27 | } 28 | }) 29 | }) 30 | </script> 31 | 32 | <div th:include="fragments/bodyHeader (tab='add vet')" th:remove="tag"></div> 33 | 34 | <div class="container"> 35 | <h1 class="ui header">Add Veterinarian</h1> 36 | 37 | <form method="post" action="add" role="form" class="ui form"> 38 | <div class="field"> 39 | <label for="firstName">First Name</label> 40 | <input type="text" id="firstName" name="firstName" placeholder="First Name"/> 41 | </div> 42 | <div class="field"> 43 | <label for="lastName">Last Name</label> 44 | <input type="text" id="lastName" name="lastName" placeholder="Last Name"/> 45 | </div> 46 | <div class="field"> 47 | <label>Specialities</label> 48 | </div> 49 | <div class="ui segment"> 50 | <div th:each="speciality : ${specialities}" class="field"> 51 | <div class="ui checkbox"> 52 | <input type="checkbox" th:name="${speciality.name}"/> 53 | <label th:text="${speciality.name}"/> 54 | </div> 55 | </div> 56 | </div> 57 | <button type="submit" class="ui green submit button">Add</button> 58 | </form> 59 | </div> 60 | 61 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 62 | </body> 63 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/vets/edit.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Edit Veterinarian')"> 4 | </head> 5 | <body> 6 | 7 | <script type="text/javascript"> 8 | $(document).ready(function(){ 9 | $(".ui.form").form({ 10 | firstName : { 11 | identifier : 'firstName', 12 | rules : [ 13 | { 14 | type : 'empty', 15 | prompt : 'Please first name' 16 | } 17 | ] 18 | }, 19 | lastName : { 20 | identifier : 'lastName', 21 | rules : [ 22 | { 23 | type : 'empty', 24 | prompt : 'Please last name' 25 | } 26 | ] 27 | } 28 | }) 29 | }) 30 | </script> 31 | 32 | <div th:include="fragments/bodyHeader (tab='edit vet')" th:remove="tag"></div> 33 | 34 | <div class="container"> 35 | <h1 class="ui header">Edit Veterinarian</h1> 36 | 37 | <form method="post" action="edit" role="form" class="ui form"> 38 | <input name="id" type="hidden" th:value="${vet.id}"/> 39 | 40 | <div class="field"> 41 | <label for="firstName">First Name</label> 42 | <input type="text" id="firstName" name="firstName" placeholder="First Name" th:value="${vet.firstName}"/> 43 | </div> 44 | <div class="field"> 45 | <label for="lastName">Last Name</label> 46 | <input type="text" id="lastName" name="lastName" placeholder="Last Name" th:value="${vet.lastName}"/> 47 | </div> 48 | <div class="field"> 49 | <label>Specialities</label> 50 | </div> 51 | <div class="ui segment"> 52 | <div th:each="speciality : ${specialities}" class="field"> 53 | <div class="ui checkbox"> 54 | <input type="checkbox" th:name="${speciality.name}" th:checked="${vet.specialities.contains(speciality.name)}"/> 55 | <label th:text="${speciality.name}"/> 56 | </div> 57 | </div> 58 | </div> 59 | <button type="submit" class="ui green submit button">Save</button> 60 | </form> 61 | </div> 62 | 63 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 64 | </body> 65 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/vets/index.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Veterinarians')"></head> 4 | <body> 5 | 6 | <div th:include="fragments/bodyHeader (tab='vets')" th:remove="tag"></div> 7 | 8 | <div class="container"> 9 | <div class="ui grid"> 10 | <div class="nine wide column"> 11 | <h1 class="ui header">Veterinarians</h1> 12 | </div> 13 | <div class="seven wide column"> 14 | <a href="add" class="ui button green" style="float: right; margin-left: 1em;">Add Veterinarian</a> 15 | </div> 16 | </div> 17 | 18 | <table class="ui table segment" th:if="${not vets.isEmpty()}"> 19 | <thead> 20 | <tr> 21 | <th>Name</th> 22 | <th>Specialities</th> 23 | </tr> 24 | </thead> 25 | <tbody> 26 | <tr th:each="vet: ${vets}"> 27 | <td> <a th:text="${vet.firstName} + ' ' + ${vet.lastName}" th:href="@{edit(id=${vet.id})}"></a></td> 28 | <td> 29 | <div th:if="${not vet.specialities.isEmpty()}"> 30 | <span class="ui small teal label" th:each="speciality: ${vet.specialities}" th:text="${speciality}"/> 31 | </div> 32 | </td> 33 | </tr> 34 | </tbody> 35 | </table> 36 | </div> 37 | 38 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 39 | </body> 40 | </html> -------------------------------------------------------------------------------- /src/main/resources/templates/visits/add.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Add Pet Visit')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | date : { 10 | identifier : 'date', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please date' 15 | } 16 | ] 17 | }, 18 | description : { 19 | identifier : 'description', 20 | rules : [ 21 | { 22 | type : 'empty', 23 | prompt : 'Please description' 24 | } 25 | ] 26 | } 27 | }) 28 | }) 29 | </script> 30 | 31 | <div th:include="fragments/bodyHeader (tab='add visit')" th:remove="tag"></div> 32 | 33 | <div class="container"> 34 | <h1 class="ui header">Add Pet Visit</h1> 35 | 36 | <form method="post" action="add" role="form" class="ui form"> 37 | <input name="petId" type="hidden" th:value="${pet.id}"/> 38 | 39 | <div class="field"> 40 | <label for="ownerName">Owner</label> 41 | <input type="text" id="ownerName" th:value="${owner.firstName + ' ' + owner.lastName}" readonly="true"/> 42 | </div> 43 | <div class="field"> 44 | <label for="petName">Pet</label> 45 | <input type="text" id="petName" th:value="${pet.name}" readonly="true"/> 46 | </div> 47 | <div class="field"> 48 | <label for="petBirthDate">Birth Date</label> 49 | <input type="text" id="petBirthDate" th:value="${#temporals.format(pet.birthDate, 'dd/MM/yyyy')}" readonly="true"/> 50 | </div> 51 | <div class="date field"> 52 | <label for="date">Date</label> 53 | <input type="text" id="date" name="date" placeholder="dd/MM/yyyy"/> 54 | </div> 55 | <div class="field"> 56 | <label for="description">Description</label> 57 | <input type="text" id="description" name="description" placeholder="Description"/> 58 | </div> 59 | <button type="submit" class="ui blue submit button">Add</button> 60 | </form> 61 | </div> 62 | 63 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 64 | </body> 65 | </html> 66 | -------------------------------------------------------------------------------- /src/main/resources/templates/visits/edit.html: -------------------------------------------------------------------------------- 1 | <!doctype html> 2 | <html xmlns:th="http://www.thymeleaf.org" lang="en-US"> 3 | <head th:replace="fragments/headTag :: headTag (title='Add Pet Visit')"></head> 4 | <body> 5 | 6 | <script type="text/javascript"> 7 | $(document).ready(function(){ 8 | $(".ui.form").form({ 9 | date : { 10 | identifier : 'date', 11 | rules : [ 12 | { 13 | type : 'empty', 14 | prompt : 'Please date' 15 | } 16 | ] 17 | }, 18 | description : { 19 | identifier : 'description', 20 | rules : [ 21 | { 22 | type : 'empty', 23 | prompt : 'Please description' 24 | } 25 | ] 26 | } 27 | }) 28 | }) 29 | </script> 30 | 31 | <div th:include="fragments/bodyHeader (tab='edit visit')" th:remove="tag"></div> 32 | 33 | <div class="container"> 34 | <h1 class="ui header">Edit Pet Visit</h1> 35 | 36 | <form method="post" action="edit" role="form" class="ui form"> 37 | <input name="id" type="hidden" th:value="${id}"/> 38 | <input name="petId" type="hidden" th:value="${pet.id}"/> 39 | 40 | <div class="field"> 41 | <label for="ownerName">Owner</label> 42 | <input type="text" id="ownerName" th:value="${owner.firstName + ' ' + owner.lastName}" readonly="true"/> 43 | </div> 44 | <div class="field"> 45 | <label for="petName">Pet</label> 46 | <input type="text" id="petName" th:value="${pet.name}" readonly="true"/> 47 | </div> 48 | <div class="field"> 49 | <label for="petBirthDate">Birth Date</label> 50 | <input type="text" id="petBirthDate" th:value="${pet.birthDate}" readonly="true"/> 51 | </div> 52 | <div class="date field"> 53 | <label for="date">Date</label> 54 | <input type="text" id="date" name="date" th:value="${date}" placeholder="dd/MM/yyyy"/> 55 | </div> 56 | <div class="field"> 57 | <label for="description">Description</label> 58 | <input type="text" id="description" name="description" th:value="${description}" placeholder="Description" 59 | required="true"/> 60 | </div> 61 | <button type="submit" class="ui blue submit button">Save</button> 62 | </form> 63 | </div> 64 | 65 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 66 | </body> 67 | </html> 68 | -------------------------------------------------------------------------------- /src/main/resources/templates/welcome.html: -------------------------------------------------------------------------------- 1 | <!DOCTYPE html> 2 | 3 | <html xmlns:th="http://www.thymeleaf.org"> 4 | <head th:replace="fragments/headTag :: headTag (title='Home')"></head> 5 | 6 | <body> 7 | 8 | <div th:include="fragments/bodyHeader (tab='home')" th:remove="tag"></div> 9 | 10 | <h2>Welcome</h2> 11 | <div class="row"> 12 | <div class="col-md-12"> 13 | <img class="img-responsive" src="../static/resources/images/pets.png" th:src="@{/resources/images/pets.png}"/> 14 | </div> 15 | </div> 16 | 17 | <div th:include="fragments/bodyFooter" th:remove="tag"></div> 18 | </body> 19 | 20 | </html> 21 | -------------------------------------------------------------------------------- /src/test/kotlin/com/yetanotherdevblog/ApiTest.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog 2 | 3 | import com.yetanotherdevblog.petclinic.model.Owner 4 | import com.yetanotherdevblog.petclinic.repositories.PetRepository 5 | import org.junit.Assert.assertEquals 6 | import org.junit.Before 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import org.springframework.beans.factory.annotation.Autowired 10 | import org.springframework.boot.test.context.SpringBootTest 11 | import org.springframework.boot.web.server.LocalServerPort 12 | import org.springframework.http.HttpStatus 13 | import org.springframework.http.MediaType 14 | import org.springframework.test.context.junit4.SpringRunner 15 | import org.springframework.web.reactive.function.client.ClientResponse 16 | import org.springframework.web.reactive.function.client.WebClient 17 | import reactor.core.publisher.test 18 | import reactor.core.publisher.toMono 19 | import java.time.Duration 20 | 21 | @RunWith(SpringRunner::class) 22 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 23 | class ApiTest { 24 | 25 | @LocalServerPort 26 | var port: Int? = null 27 | 28 | lateinit var client: WebClient 29 | 30 | @Autowired 31 | lateinit var petRepository: PetRepository 32 | 33 | @Before 34 | fun setup() { 35 | client = WebClient.create("http://localhost:$port") 36 | } 37 | 38 | @Test 39 | fun `API call for Owners`() { 40 | client.get().uri("/api/owners").accept(MediaType.APPLICATION_JSON) 41 | .retrieve() 42 | .bodyToFlux(Owner::class.java) 43 | .test() 44 | .consumeNextWith { 45 | assertEquals("James", it.firstName) 46 | } 47 | .verifyComplete() 48 | 49 | client.get().uri("/api/owners/5bead0d3-cd7b-41e5-b064-09f48e5e6a08").accept(MediaType.APPLICATION_JSON) 50 | .retrieve() 51 | .bodyToFlux(Owner::class.java) 52 | .test() 53 | .consumeNextWith { 54 | assertEquals("James", it.firstName) 55 | assertEquals("Owner", it.lastName) 56 | } 57 | .verifyComplete() 58 | } 59 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/yetanotherdevblog/CollectionTests.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog 2 | 3 | import com.yetanotherdevblog.petclinic.model.Owner 4 | import org.junit.Assert.* 5 | import org.junit.Test 6 | import java.util.* 7 | 8 | class CollectionTests { 9 | 10 | val orderedList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) 11 | val unOrderedList = mutableListOf(orderedList).shuffle() 12 | 13 | 14 | @Test 15 | fun `any`() { 16 | assertTrue(orderedList.any()) 17 | assertFalse(orderedList.any( { it == 0 } )) 18 | } 19 | 20 | @Test 21 | fun `all`() { 22 | assertTrue(orderedList.all( { it > 0 } )) 23 | assertFalse(orderedList.all( { it > 10 } )) 24 | } 25 | 26 | @Test 27 | fun `count`() { 28 | assertEquals(10, orderedList.count()) 29 | assertEquals(0, orderedList.count( { it > 10 } )) 30 | } 31 | 32 | @Test 33 | fun `fold`() { 34 | assertEquals(55, orderedList.fold(0) { 35 | acc, next -> acc + next 36 | }) 37 | assertEquals(97, orderedList.fold (42) { 38 | acc, next -> acc + next 39 | }) 40 | 41 | // compress list of chars 42 | assertEquals("abcdefgh".toList(), 43 | "aaaabbbbcccddddeeeeffffggghh".toList() 44 | .fold(emptyList<Char>()) { result, value -> 45 | if (result.isNotEmpty() && result.last() == value) result 46 | else result + value 47 | }) 48 | } 49 | 50 | @Test 51 | fun `foldRight`() { 52 | // compress list of chars and reverse 53 | assertEquals("hgfedcba".toList(), 54 | "aaaabbbbcccddddeeeeffffggghh".toList() 55 | .foldRight(emptyList<Char>(), { value: Char, result: List<Char> -> 56 | if (result.isNotEmpty() && result.last() == value) result 57 | else result + value 58 | })) 59 | } 60 | 61 | @Test 62 | fun `forEach`() { 63 | orderedList.forEach { println(it) } 64 | orderedList.forEachIndexed { index, i -> println("$index -> $i") } 65 | unOrderedList.forEachIndexed { index, i -> println("$index -> $i") } 66 | } 67 | 68 | @Test 69 | fun `max`() { 70 | assertEquals(orderedList.last(), orderedList.max()) 71 | assertEquals(orderedList.first(), orderedList.maxBy({ -it})) 72 | } 73 | 74 | @Test 75 | fun `min`() { 76 | assertEquals(orderedList.first(), orderedList.min()) 77 | assertEquals(orderedList.last(), orderedList.minBy({ -it})) 78 | } 79 | 80 | @Test 81 | fun `none`() { 82 | assertTrue(orderedList.none { it == Int.MAX_VALUE }) 83 | } 84 | 85 | @Test 86 | fun `reduce,reduceRight`() { 87 | assertEquals(55, orderedList.reduce { total, next -> total + next }) 88 | assertEquals(10, listOf(1, 2, 3, 4).reduceRight { total, next -> total + next }) 89 | 90 | } 91 | 92 | // Filtering 93 | 94 | @Test 95 | fun `drop`() { 96 | orderedList.drop(1) 97 | } 98 | 99 | @Test 100 | fun `dropWhile`() { 101 | orderedList.dropWhile { it < 10 } 102 | } 103 | 104 | @Test 105 | fun `dropLastWhile`() { 106 | orderedList.dropLastWhile { it < 10 } 107 | } 108 | 109 | 110 | @Test 111 | fun `filter`() { 112 | orderedList.filter { it < 10 } 113 | orderedList.filterNot { it < 10 } 114 | orderedList.filterNotNull() 115 | orderedList.filterIsInstance(Owner::class.java) 116 | } 117 | 118 | @Test 119 | fun `slice`() { 120 | orderedList.slice(1..3) 121 | orderedList.slice(listOf(1, 2, 3)) 122 | } 123 | 124 | @Test 125 | fun `take`() { 126 | orderedList.take(2) 127 | orderedList.takeLast(2) 128 | orderedList.takeWhile { it > 0 } 129 | orderedList.takeLastWhile { it > 0 } 130 | } 131 | 132 | // mapping functions 133 | 134 | // @Test 135 | // fun `flatMap`() { 136 | // 137 | // assertEquals(listOf(1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7), 138 | // list.flatMap { listOf(it, it + 1) }) 139 | // 140 | // } 141 | // ``` 142 | // 143 | // ### groupBy 144 | // 145 | // Returns a map of the elements in original collection grouped by the result of given 146 | // function 147 | // 148 | // ```kotlin 149 | // assertEquals(mapOf("odd" to listOf(1, 3, 5), "even" to listOf(2, 4, 6)), 150 | // list.groupBy { if (it % 2 == 0) "even" else "odd" }) 151 | // ``` 152 | // 153 | // ### map 154 | // 155 | // Returns a list containing the results of applying the given transform function to each 156 | // element of the original collection. 157 | // 158 | // ```kotlin 159 | // assertEquals(listOf(2, 4, 6, 8, 10, 12), list.map { it * 2 }) 160 | // ``` 161 | // 162 | // ### mapIndexed 163 | // 164 | // Returns a list containing the results of applying the given transform function to each 165 | // element and its index of the original collection. 166 | // 167 | // ```kotlin 168 | // assertEquals(listOf (0, 2, 6, 12, 20, 30), list.mapIndexed { index, it 169 | // -> index * it }) 170 | // ``` 171 | // 172 | // ### mapNotNull 173 | // 174 | // Returns a list containing the results of applying the given transform function to each 175 | // non-null element of the original collection. 176 | // 177 | // ```kotlin 178 | // assertEquals(listOf(2, 4, 6, 8), listWithNull.mapNotNull { it * 2 }) 179 | 180 | } 181 | 182 | private fun <E> MutableList<E>.shuffle(): MutableList<E> { 183 | val rg : Random = Random() 184 | for (i in 0..this.count() - 1) { 185 | val randomPosition = rg.nextInt(this.size) 186 | val tmp : E = this[i] 187 | this[i] = this[randomPosition] 188 | this[randomPosition] = tmp 189 | } 190 | return this 191 | } 192 | 193 | -------------------------------------------------------------------------------- /src/test/kotlin/com/yetanotherdevblog/OwnersHandlerTest.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog 2 | 3 | import com.yetanotherdevblog.petclinic.handlers.OwnersHandler 4 | import org.junit.Assert 5 | import org.junit.Test 6 | import org.junit.runner.RunWith 7 | import org.springframework.beans.factory.annotation.Autowired 8 | import org.springframework.boot.test.context.SpringBootTest 9 | import org.springframework.test.context.junit4.SpringRunner 10 | import reactor.core.publisher.test 11 | import reactor.core.publisher.toMono 12 | 13 | @RunWith(SpringRunner::class) 14 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) 15 | class OwnersHandlerTest { 16 | 17 | @Autowired 18 | lateinit var ownersHandler: OwnersHandler 19 | 20 | @Test 21 | fun `findByNameLike returns no result`() { 22 | ownersHandler.findByNameLike("No Result") 23 | .test() 24 | .expectNextCount(0) 25 | .verifyComplete() 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/yetanotherdevblog/VariousTests.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog 2 | 3 | import com.yetanotherdevblog.petclinic.toLocalDate 4 | import com.yetanotherdevblog.petclinic.toStr 5 | import org.junit.Assert 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | import org.springframework.beans.factory.annotation.Value 9 | import org.springframework.boot.test.context.SpringBootTest 10 | import org.springframework.test.context.junit4.SpringRunner 11 | import java.time.LocalDate 12 | 13 | @RunWith(SpringRunner::class) 14 | @SpringBootTest 15 | class VariousTests { 16 | 17 | /** 18 | * @Value injection need escaping of the `$` char 19 | * Or you can instead use ConfigurationProperties 20 | * Or change that special character 21 | */ 22 | @Value("\${custom.property}") 23 | lateinit var customProperty : String 24 | 25 | /** 26 | * Method names can be free text by wrapping them around `...` 27 | */ 28 | @Test 29 | fun `@Value properties needs escaping`() { 30 | Assert.assertEquals(customProperty, "Lorem Ipsum") 31 | } 32 | 33 | @Test 34 | fun `Test LocalDate#toStr extension method`() { 35 | Assert.assertEquals(LocalDate.of(1970, 1, 1).toStr(), "01/01/1970") 36 | } 37 | 38 | @Test 39 | fun `Test String#toLocalDate extension method`() { 40 | Assert.assertEquals("01/01/1970".toLocalDate(), LocalDate.of(1970, 1, 1)) 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/kotlin/com/yetanotherdevblog/WebsiteTest.kt: -------------------------------------------------------------------------------- 1 | package com.yetanotherdevblog 2 | 3 | import com.yetanotherdevblog.petclinic.model.Owner 4 | import com.yetanotherdevblog.petclinic.repositories.OwnersRepository 5 | import org.junit.Assert 6 | import org.junit.Before 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import org.springframework.beans.factory.annotation.Autowired 10 | import org.springframework.beans.factory.annotation.Value 11 | import org.springframework.boot.test.context.SpringBootTest 12 | import org.springframework.boot.web.server.LocalServerPort 13 | import org.springframework.http.HttpStatus 14 | import org.springframework.http.MediaType 15 | import org.springframework.test.context.junit4.SpringRunner 16 | import org.springframework.web.reactive.function.client.WebClient 17 | import reactor.core.publisher.test 18 | import java.time.Duration 19 | import java.util.* 20 | 21 | @RunWith(SpringRunner::class) 22 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 23 | class WebsiteTest { 24 | 25 | @LocalServerPort 26 | var port: Int? = null 27 | 28 | lateinit var client: WebClient 29 | 30 | @Autowired 31 | lateinit var ownerRepository: OwnersRepository 32 | 33 | @Before 34 | fun setup() { 35 | client = WebClient.create("http://localhost:$port") 36 | } 37 | 38 | @Test 39 | fun home() { 40 | client.get().uri("/").accept(MediaType.TEXT_HTML) 41 | .exchange() 42 | .test() 43 | .expectNextMatches { it.statusCode() == HttpStatus.OK } 44 | .verifyComplete() 45 | } 46 | 47 | @Test 48 | fun owners() { 49 | client.get().uri("/owners").accept(MediaType.TEXT_HTML) 50 | .exchange() 51 | .test() 52 | .expectNextMatches { it.statusCode() == HttpStatus.OK } 53 | .verifyComplete() 54 | } 55 | 56 | @Test 57 | fun pets() { 58 | 59 | val ownerId = UUID.randomUUID().toString() 60 | 61 | ownerRepository.save(Owner( 62 | id=ownerId, 63 | firstName = "Lorem", 64 | lastName = "Ipsum", 65 | address = "LoremIpsum", 66 | city = "IpsumLorem", 67 | telephone = "1111" 68 | )).block(Duration.ofSeconds(2)) 69 | 70 | client.get().uri("/pets/add?ownerId=$ownerId").accept(MediaType.TEXT_HTML) 71 | .exchange() 72 | .test() 73 | .expectNextMatches { it.statusCode() == HttpStatus.OK } 74 | .verifyComplete() 75 | } 76 | 77 | @Test 78 | fun vets() { 79 | client.get().uri("/vets").accept(MediaType.TEXT_HTML) 80 | .exchange() 81 | .test() 82 | .expectNextMatches { it.statusCode() == HttpStatus.OK } 83 | .verifyComplete() 84 | } 85 | 86 | @Test 87 | fun specialities() { 88 | client.get().uri("/specialities").accept(MediaType.TEXT_HTML) 89 | .exchange() 90 | .test() 91 | .expectNextMatches { it.statusCode() == HttpStatus.OK } 92 | .verifyComplete() 93 | } 94 | 95 | @Test 96 | fun petTypes() { 97 | client.get().uri("/petTypes").accept(MediaType.TEXT_HTML) 98 | .exchange() 99 | .test() 100 | .expectNextMatches { it.statusCode() == HttpStatus.OK } 101 | .verifyComplete() 102 | } 103 | 104 | } --------------------------------------------------------------------------------