-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-2: Adds scaffolding example with DB schema, repositories, services…
…, and tests
- Loading branch information
Showing
50 changed files
with
1,702 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
code/example-spring-boot-demo/src/main/kotlin/com/example/demo/RequestScopedComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.demo | ||
|
||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.context.annotation.RequestScope | ||
|
||
|
||
@Component | ||
@RequestScope | ||
class RequestScopedComponent { | ||
var path: String? = null | ||
|
||
override fun toString() = "${hashCode()} - $path" | ||
|
||
init { | ||
logger.info("ctor") | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(RequestScopedComponent::class.java) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
code/example-spring-boot-demo/src/main/kotlin/com/example/demo/SingletonScopedComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.demo | ||
|
||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SingletonScopedComponent( | ||
val requestScopedComponent: RequestScopedComponent | ||
) { | ||
init { | ||
logger.info("ctor") | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(SingletonScopedComponent::class.java) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...-spring-boot-demo/src/main/kotlin/com/example/demo/controllers/ScopesExampleController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example.demo.controllers | ||
|
||
import com.example.demo.SingletonScopedComponent | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("examples-scopes") | ||
class ScopesExampleController( | ||
private val singletonScopedComponent: SingletonScopedComponent | ||
) { | ||
|
||
@GetMapping("/0/{id}") | ||
fun get0() = "${singletonScopedComponent.hashCode()}, " + | ||
"${singletonScopedComponent.requestScopedComponent.toString()}" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Tic Tac Toe Service | ||
|
||
## Development time commands | ||
|
||
* Start docker image with development time services | ||
``` | ||
docker compose up --build --force-recreate | ||
``` | ||
|
||
* Start shell on postgres container | ||
|
||
``` | ||
docker exec -ti db-tests bash | ||
``` | ||
|
||
* Start `psql` inside postgres container | ||
``` | ||
psql -U dbuser -d db | ||
``` | ||
* `psql` commands | ||
* `\h` - show help. | ||
* `\d <table>` - show table. | ||
* `select ... ;` - execute query. | ||
* `\q` - quit `psql`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
id("org.springframework.boot") version "2.7.4" | ||
id("io.spring.dependency-management") version "1.0.14.RELEASE" | ||
kotlin("jvm") version "1.6.21" | ||
kotlin("plugin.spring") version "1.6.21" | ||
} | ||
|
||
group = "pt.isel.daw" | ||
version = "0.0.1-SNAPSHOT" | ||
java.sourceCompatibility = JavaVersion.VERSION_17 | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter-validation") | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") | ||
implementation("org.jetbrains.kotlin:kotlin-reflect") | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
|
||
implementation("org.springframework.security:spring-security-core:5.7.3") | ||
|
||
// for JDBI | ||
implementation("org.jdbi:jdbi3-core:3.32.0") | ||
implementation("org.jdbi:jdbi3-kotlin:3.32.0") | ||
implementation("org.postgresql:postgresql:42.5.0") | ||
|
||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
testImplementation(kotlin("test")) | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
freeCompilerArgs = listOf("-Xjsr305=strict") | ||
jvmTarget = "17" | ||
} | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: "3.3" | ||
services: | ||
db-tests: | ||
container_name: db-tests | ||
build: | ||
context: . | ||
dockerfile: ./tests/Dockerfile-db-test | ||
environment: | ||
- POSTGRES_USER=dbuser | ||
- POSTGRES_PASSWORD=changeit | ||
- POSTGRES_DB=db | ||
ports: | ||
- 5432:5432 |
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
code/tic-tac-tow-service/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.