Skip to content

Commit

Permalink
gh-2: Adds scaffolding example with DB schema, repositories, services…
Browse files Browse the repository at this point in the history
…, and tests
  • Loading branch information
pmhsfelix committed Oct 3, 2022
1 parent d49e398 commit 235f8d0
Show file tree
Hide file tree
Showing 50 changed files with 1,702 additions and 0 deletions.
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)
}
}
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)
}
}
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()}"
}

37 changes: 37 additions & 0 deletions code/tic-tac-tow-service/.gitignore
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/
24 changes: 24 additions & 0 deletions code/tic-tac-tow-service/README.md
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`.
45 changes: 45 additions & 0 deletions code/tic-tac-tow-service/build.gradle.kts
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()
}
13 changes: 13 additions & 0 deletions code/tic-tac-tow-service/docker-compose.yml
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.
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
Loading

0 comments on commit 235f8d0

Please sign in to comment.