Skip to content

Commit ebb9c92

Browse files
authored
v1.0 (#15)
2 parents 80ffdc3 + 7dcf416 commit ebb9c92

73 files changed

Lines changed: 372713 additions & 44 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ out/
3333
/.nb-gradle/
3434

3535
### VS Code ###
36-
.vscode/
36+
.vscode/
37+
/config/

build.gradle.kts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ val kotlin_version: String by project
33
val logback_version: String by project
44
val kmongo_version: String by project
55
val koin_version: String by project
6+
val firebase_version: String by project
7+
val prometheus_version: String by project
68

79
plugins {
810
application
@@ -29,12 +31,15 @@ dependencies {
2931
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
3032
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
3133
implementation("io.ktor:ktor-serialization-gson-jvm:$ktor_version")
32-
implementation("io.ktor:ktor-server-metrics-jvm:$ktor_version")
3334
implementation("io.ktor:ktor-server-call-logging-jvm:$ktor_version")
3435
implementation("io.ktor:ktor-server-cors-jvm:$ktor_version")
3536
implementation("io.ktor:ktor-server-auth-jvm:$ktor_version")
3637
implementation("io.ktor:ktor-server-auth-jwt-jvm:$ktor_version")
3738
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
39+
implementation("io.ktor:ktor-server-rate-limit:$ktor_version")
40+
implementation("io.ktor:ktor-server-metrics-jvm:$ktor_version")
41+
implementation("io.ktor:ktor-server-metrics-micrometer:$ktor_version")
42+
implementation("io.micrometer:micrometer-registry-prometheus:$prometheus_version")
3843
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
3944
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
4045

@@ -47,17 +52,33 @@ dependencies {
4752
// Koin
4853
implementation("io.insert-koin:koin-ktor:$koin_version")
4954
implementation("io.insert-koin:koin-logger-slf4j:$koin_version")
55+
56+
// Firebase
57+
implementation("com.google.firebase:firebase-admin:$firebase_version")
58+
59+
// BCrypt
60+
implementation("org.mindrot:jbcrypt:0.4")
61+
62+
// Google auth
63+
implementation("com.google.api-client:google-api-client:2.1.1")
64+
65+
// JavaMail
66+
implementation("javax.mail:javax.mail-api:1.6.2")
67+
implementation("com.sun.mail:javax.mail:1.6.2")
68+
69+
// TOTP
70+
implementation("dev.turingcomplete:kotlin-onetimepassword:2.4.0")
5071
}
5172

5273
ktor {
5374
fatJar {
54-
archiveFileName.set("fat.jar")
75+
archiveFileName.set("${rootProject.name}-${rootProject.version}.jar")
5576
}
5677

5778
docker {
5879
jreVersion.set(io.ktor.plugin.features.JreVersion.JRE_17)
5980
localImageName.set(rootProject.name)
60-
imageTag.set("0.0.1-preview")
81+
imageTag.set("1.0-preview")
6182

6283
externalRegistry.set(
6384
io.ktor.plugin.features.DockerImageRegistry.dockerHub(

gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
ktor_version=2.1.3
1+
ktor_version=2.2.4
22
kotlin_version=1.7.21
33
logback_version=1.4.4
44
kmongo_version=4.7.2
55
koin_version=3.2.2
6+
firebase_version=9.1.1
7+
prometheus_version=1.10.3
68
kotlin.code.style=official
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
package es.wokis
22

3+
import com.typesafe.config.ConfigFactory
4+
import es.wokis.plugins.*
35
import io.ktor.server.application.*
6+
import io.ktor.server.config.*
47
import io.ktor.server.engine.*
58
import io.ktor.server.netty.*
6-
import es.wokis.plugins.*
79

810
fun main() {
9-
embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module)
10-
.start(wait = true)
11+
embeddedServer(Netty, environment = applicationEngineEnvironment {
12+
config = HoconApplicationConfig(ConfigFactory.load("application.conf"))
13+
14+
connector {
15+
host = config.host
16+
port = config.port
17+
}
18+
}).start(wait = true)
1119
}
1220

1321
fun Application.module() {
22+
initConfig()
23+
configureFirebase()
1424
configureKoin()
1525
configureSerialization()
1626
configureMonitoring()
1727
configureHTTP()
1828
configureSecurity()
29+
configureRateLimit()
1930
configureRouting()
2031
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package es.wokis.data.bo.invoice
2+
3+
import es.wokis.data.constants.ServerConstants.EMPTY_TEXT
4+
import java.util.*
5+
6+
data class InvoiceBO(
7+
val id: String? = null,
8+
val idApp: Long = 0L,
9+
val title: String = EMPTY_TEXT,
10+
val description: String = EMPTY_TEXT,
11+
val quantity: Int = 0,
12+
val date: Date = Date(),
13+
val type: InvoiceType,
14+
val userId: String,
15+
val category: CategoryBO? = null,
16+
val reactions: List<ReactionBO> = emptyList()
17+
)
18+
19+
data class CategoryBO(
20+
val id: Long,
21+
val title: String,
22+
val color: String,
23+
)
24+
25+
data class ReactionBO(
26+
val id: Long,
27+
val unicode: String
28+
)
29+
30+
enum class InvoiceType(val key: String) {
31+
DEPOSIT("DEPOSIT"),
32+
EXPENSE("EXPENSE");
33+
34+
companion object {
35+
fun getFromKey(key: String) = values().find { it.key == key } ?: DEPOSIT
36+
}
37+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package es.wokis.data.bo.recover
2+
3+
import java.util.*
4+
5+
data class RecoverBO(
6+
val id: String? = null,
7+
val email: String,
8+
val verificationToken: String,
9+
val timeStamp: Date = Date()
10+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package es.wokis.data.bo.response
2+
3+
data class AcknowledgeBO(
4+
val acknowledge: Boolean
5+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package es.wokis.data.bo.user
2+
3+
data class TOTPResponseBO(
4+
val encodedSecret: String,
5+
val totpUrl: String,
6+
val words: List<String>
7+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package es.wokis.data.bo.user
2+
3+
data class UpdateUserBO(
4+
val username: String?,
5+
val email: String?,
6+
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package es.wokis.data.bo.user
2+
3+
import es.wokis.data.constants.ServerConstants.DEFAULT_LANG
4+
import es.wokis.data.constants.ServerConstants.EMPTY_TEXT
5+
import io.ktor.server.auth.*
6+
import java.util.*
7+
8+
data class UserBO(
9+
val id: String? = null,
10+
val username: String,
11+
val email: String,
12+
val password: String,
13+
val image: String = EMPTY_TEXT,
14+
val lang: String = DEFAULT_LANG,
15+
val createdOn: Long = Date().time,
16+
val totpEncodedSecret: ByteArray? = null,
17+
val currentSession: String? = null,
18+
val emailVerified: Boolean = false,
19+
val loginWithGoogle: Boolean = false,
20+
val sessions: List<String> = emptyList(),
21+
val badges: List<BadgeBO> = emptyList(),
22+
val devices: List<String> = emptyList(),
23+
val recoverWords: List<String> = emptyList()
24+
) : Principal {
25+
26+
override fun equals(other: Any?): Boolean {
27+
if (this === other) return true
28+
if (javaClass != other?.javaClass) return false
29+
30+
other as UserBO
31+
32+
if (id != other.id) return false
33+
if (username != other.username) return false
34+
if (email != other.email) return false
35+
if (password != other.password) return false
36+
if (image != other.image) return false
37+
if (lang != other.lang) return false
38+
if (createdOn != other.createdOn) return false
39+
if (totpEncodedSecret != null) {
40+
if (other.totpEncodedSecret == null) return false
41+
if (!totpEncodedSecret.contentEquals(other.totpEncodedSecret)) return false
42+
} else if (other.totpEncodedSecret != null) return false
43+
if (emailVerified != other.emailVerified) return false
44+
if (sessions != other.sessions) return false
45+
if (badges != other.badges) return false
46+
if (devices != other.devices) return false
47+
48+
return true
49+
}
50+
51+
override fun hashCode(): Int {
52+
var result = id?.hashCode() ?: 0
53+
result = 31 * result + username.hashCode()
54+
result = 31 * result + email.hashCode()
55+
result = 31 * result + password.hashCode()
56+
result = 31 * result + image.hashCode()
57+
result = 31 * result + lang.hashCode()
58+
result = 31 * result + createdOn.hashCode()
59+
result = 31 * result + (totpEncodedSecret?.contentHashCode() ?: 0)
60+
result = 31 * result + emailVerified.hashCode()
61+
result = 31 * result + sessions.hashCode()
62+
result = 31 * result + badges.hashCode()
63+
result = 31 * result + devices.hashCode()
64+
return result
65+
}
66+
}
67+
68+
data class BadgeBO(
69+
val id: Int,
70+
val color: String
71+
)

0 commit comments

Comments
 (0)