Skip to content

Commit 7081de9

Browse files
authored
Merge pull request #6 from fractalliter/upgrade_ktor
upgrade_ktor
2 parents 832099f + 73fa005 commit 7081de9

File tree

7 files changed

+33
-47
lines changed

7 files changed

+33
-47
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<!-- You can erase any parts of this template not applicable to your Pull Request. -->
88

99
### How to test
10+
1011
<!-- Add description about the tests -->
1112

1213
### New Feature Submissions:

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
106106
### 4. Permanent Ban
107107

108108
**Community Impact**: Demonstrating a pattern of violation of community
109-
standards, including sustained inappropriate behavior, harassment of an
109+
standards, including sustained inappropriate behavior, harassment of an
110110
individual, or aggression toward or disparagement of classes of individuals.
111111

112112
**Consequence**: A permanent ban from any sort of public interaction within

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Kotlin Ktor and postgres backend
2+
23
Here lays a Kotlin web project with Ktor framework, Postgres database, and JWT Authentication.
34

45
The project comprises following ingredients:
5-
- [Ktor](https://ktor.io/) server includes [JSON serializers](https://ktor.io/docs/serialization.html), [Authentication](https://ktor.io/docs/authentication.html), and [Testing](https://ktor.io/docs/testing.html)
6+
7+
- [Ktor](https://ktor.io/) server
8+
includes [JSON serializers](https://ktor.io/docs/serialization.html), [Authentication](https://ktor.io/docs/authentication.html),
9+
and [Testing](https://ktor.io/docs/testing.html)
610
- [Netty](https://netty.io/) web server
711
- [Postgres](https://www.postgresql.org/) as database
812
- [Exposed](https://github.com/JetBrains/Exposed) as ORM
@@ -15,11 +19,13 @@ better go for [GUAVA Graph](https://github.com/google/guava/wiki/GraphsExplained
1519

1620
Project is agnostic about database, you can dynamically change Postgres to any other databases that Exposed JDBC
1721
supports by changing a couple of variables:
22+
1823
- the database driver version in `gradle.properties`
1924
- the database driver dependency in `build.gradle.kts`
2025
- the **WEB_DB_URL** variable in `.env` file
2126

2227
## Flow
28+
2329
1. deploy the docker compose with `docker compose up -d` command
2430
2. sign up to the system `/signup` with a username and password(not hardened enough)
2531
3. log in to with username and password to get access token `/login`
@@ -31,7 +37,8 @@ supports by changing a couple of variables:
3137
> You need **root access** for docker
3238
3339
Go to the root directory of the project where `docker-compose.yml` is and change the environment variables in
34-
`.env-example` with yours and rename the file to `mv .env-example .env` then deploy the application with following command:
40+
`.env-example` with yours and rename the file to `mv .env-example .env` then deploy the application with following
41+
command:
3542

3643
```bash
3744
docker-compose up
@@ -145,17 +152,21 @@ The response will be the access token
145152
```
146153

147154
## How to test locally
155+
148156
For testing the project locally you can run docker compose with `docker-compose-test.yml` file. It will run the tests
149157
against a test database.
158+
150159
```bash
151160
docker-compose --file docker-compose-test.yml up
152161
```
153-
After finishing the tests you can clean test data nd shut the containers down with following command:
162+
163+
After finishing the tests you can clean test data nd shut the containers down with following command:
154164

155165
```bash
156166
docker-compose --file docker-compose-test.yml down -v
157167
```
158168

159169
## Continues Integration
170+
160171
For continues integration, the CI workflow prepares the database, run the gradle build with tests, and generates report
161172
to Codacy about the quality of code.

build.gradle.kts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ val database_driver_version: String by project
66
val gson_version: String by project
77
val jbcrypt_version: String by project
88
val hikaricp_version: String by project
9+
val redis_version: String by project
910

1011
plugins {
1112
application
12-
kotlin("jvm") version "1.6.20"
13+
kotlin("jvm") version "1.8.0"
1314
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.20"
1415
id("com.github.johnrengelman.shadow") version "7.0.0"
1516
}
@@ -37,26 +38,26 @@ repositories {
3738
}
3839

3940
dependencies {
40-
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
41-
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
42-
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
43-
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version")
44-
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
4541
implementation("ch.qos.logback:logback-classic:$logback_version")
4642
implementation("org.jetbrains.exposed:exposed-core:$exposed_version")
4743
implementation("org.jetbrains.exposed:exposed-dao:$exposed_version")
4844
implementation("org.jetbrains.exposed:exposed-jdbc:$exposed_version")
4945
// add database driver below, default is postgres
5046
implementation("org.postgresql:postgresql:$database_driver_version")
5147
implementation("com.google.code.gson:gson:$gson_version")
48+
implementation("org.mindrot:jbcrypt:$jbcrypt_version")
49+
implementation("io.github.crackthecodeabhi:kreds:$redis_version")
50+
implementation("com.zaxxer:HikariCP:$hikaricp_version")
51+
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
52+
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
53+
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
54+
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version")
55+
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
5256
implementation("io.ktor:ktor-server-auth:$ktor_version")
5357
implementation("io.ktor:ktor-server-status-pages:$ktor_version")
54-
implementation("org.mindrot", "jbcrypt", "0.4")
5558
implementation("io.ktor:ktor-server-auth-jwt:$ktor_version")
56-
implementation("io.github.crackthecodeabhi:kreds:0.8")
57-
implementation("com.zaxxer:HikariCP:$hikaricp_version")
58-
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
5959
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
60-
testImplementation("io.ktor:ktor-server-test-host:$ktor_version")
6160
testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlin_version")
61+
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
62+
testImplementation("io.ktor:ktor-server-test-host-jvm:$ktor_version")
6263
}

docker-compose.yml

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,4 @@ services:
3030
- "5432:5432"
3131
healthcheck:
3232
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
33-
interval: 1s
34-
# auth-db:
35-
# image: postgres
36-
# volumes:
37-
# - postgres_data:/var/lib/postgresql/data
38-
# environment:
39-
# POSTGRES_DB: ${AUTH_DB_DATABASE}
40-
# POSTGRES_USER: ${AUTH_DB_USER}
41-
# POSTGRES_PASSWORD: ${AUTH_DB_PASSWORD}
42-
# keycloak:
43-
# image: docker.io/bitnami/keycloak:latest
44-
# environment:
45-
# DB_VENDOR: ${AUTH_DB_VENDOR}
46-
# KEYCLOAK_DATABASE_HOST: ${AUTH_DB_ADDRESS}
47-
# KEYCLOAK_DATABASE_PORT: ${AUTH_DB_PORT}
48-
# KEYCLOAK_DATABASE_NAME: ${AUTH_DB_DATABASE}
49-
# KEYCLOAK_DATABASE_USER: ${AUTH_DB_USER}
50-
# KEYCLOAK_DATABASE_SCHEMA: ${AUTH_DB_SCHEMA}
51-
# KEYCLOAK_DATABASE_PASSWORD: ${AUTH_DB_PASSWORD}
52-
# KEYCLOAK_MANAGEMENT_USER: ${AUTH_SERVER_USER}
53-
# KEYCLOAK_MANAGEMENT_PASSWORD: ${AUTH_SERVER_PASSWORD}
54-
# KEYCLOAK_ADMIN_USER: ${AUTH_ADMIN_USER}
55-
# KEYCLOAK_ADMIN_PASSWORD: ${AUTH_ADMIN_PASSWORD}
56-
# # Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the PostgreSQL JDBC driver documentation in order to use it.
57-
# #KEYCLOAK_JDBC_PARAMS: "ssl=true"
58-
# ports:
59-
# - "8080:8080"
60-
# depends_on:
61-
# - auth-db
33+
interval: 1s

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ktor_version=2.2.4
1+
ktor_version=2.3.0
22
kotlin_version=1.6.20
33
logback_version=1.2.11
44
kotlin.code.style=official
@@ -8,3 +8,4 @@ database_driver_version=42.5.1
88
gson_version=2.9.0
99
jbcrypt_version=0.4
1010
hikaricp_version=5.0.1
11+
redis_version=0.8

src/main/kotlin/com/personia/routes/HierarchyRoutes.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ fun Route.hierarchyRouting(nodeService: NodeService) {
3939

4040
val response = nodeService.retrieveSupervisors(name, level)
4141
val json: String = gson.toJson(response)
42-
call.respondText(text = json,contentType = applicationJson)
42+
call.respondText(text = json, contentType = applicationJson)
4343
}
4444
post {
4545
val hierarchy = call.receive<Map<String, String>>()
4646
val response = nodeService.createHierarchy(hierarchy)
4747
val json = gson.toJson(response)
48-
call.respondText(text = json,contentType = applicationJson)
48+
call.respondText(text = json, contentType = applicationJson)
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)