-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d085555
commit f8fd3b1
Showing
17 changed files
with
648 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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,81 @@ | ||
# Spring Boot with PostgreSQL | ||
|
||
This is a simple example application that demonstrates how to use Kotlin, Spring Boot, and PostgreSQL together. The application provides a REST API for managing heroes, which are stored in a PostgreSQL database. | ||
|
||
## Prerequisites | ||
|
||
Before you can run this application, you will need to have the following installed: | ||
|
||
* Java 17 or later | ||
* Gradle 8.4 or later | ||
* PostgreSQL 13 or later (via Docker) | ||
|
||
## Getting Started | ||
|
||
To get started, follow these steps: | ||
|
||
1. Clone the repository: | ||
|
||
```shell | ||
git clone https://github.com/nais/examples.git | ||
``` | ||
|
||
1. Navigate to the project directory: | ||
|
||
```shell | ||
cd db-dings | ||
``` | ||
|
||
1. Start the PostgreSQL database: | ||
|
||
```shell | ||
docker-compose up db -d | ||
``` | ||
|
||
1. Build the application: | ||
|
||
```shell | ||
./gradlew build | ||
``` | ||
|
||
1. Run the application: | ||
|
||
```shell | ||
./gradlew bootRun | ||
``` | ||
|
||
This will start the application on port 8080 on localhost. | ||
|
||
Test the API using a tool like `curl` or `httpie`: | ||
|
||
```shell | ||
http localhost:8080/api/heroes | ||
``` | ||
|
||
This should return an empty JSON array. | ||
|
||
## API Documentation | ||
|
||
The API provides the following endpoints: | ||
|
||
* `GET /api/heroes`: Returns a list of all heroes. | ||
* `GET /api/heroes/{id}`: Returns the hero with the specified ID. | ||
* `POST /api/heroes`: Creates a new hero. | ||
* `PUT /api/heroes/{id}`: Updates the hero with the specified ID. | ||
* `DELETE /api/heroes/{id}`: Deletes the hero with the specified ID. | ||
|
||
The request and response bodies are in JSON format. Here's an example of a hero object: | ||
```json | ||
{ | ||
"firstName": "Luke", | ||
"lastName": "Skywalker", | ||
"species": "HUMAN" | ||
} | ||
``` | ||
The species field can be one of the following values: `HUMAN`, `WOOKIEE`, or `YODA_SPECIES`. | ||
## License | ||
This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details. |
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,43 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
id("org.springframework.boot") version "3.1.4" | ||
id("io.spring.dependency-management") version "1.1.3" | ||
kotlin("jvm") version "1.8.22" | ||
kotlin("plugin.spring") version "1.8.22" | ||
kotlin("plugin.jpa") version "1.8.22" | ||
} | ||
|
||
group = "no.nav" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter-data-jpa") | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") | ||
//implementation("org.flywaydb:flyway-core") | ||
implementation("org.jetbrains.kotlin:kotlin-reflect") | ||
developmentOnly("org.springframework.boot:spring-boot-devtools") | ||
runtimeOnly("com.h2database:h2") | ||
runtimeOnly("org.postgresql:postgresql") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
freeCompilerArgs += "-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,17 @@ | ||
version: '3.8' | ||
|
||
services: | ||
db: | ||
image: postgres:14 | ||
restart: always | ||
environment: | ||
POSTGRES_USER: test | ||
POSTGRES_PASSWORD: test | ||
POSTGRES_DB: test | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- db-data:/var/lib/postgresql/data | ||
|
||
volumes: | ||
db-data: |
Binary file not shown.
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,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.