Skip to content

Commit

Permalink
Merge pull request #1 from dungeon-hub/feature/initial-migration
Browse files Browse the repository at this point in the history
Initial migration from the common api classes
  • Loading branch information
Taubsie authored Nov 2, 2024
2 parents 7ae0705 + 8dd7987 commit fa46c48
Show file tree
Hide file tree
Showing 68 changed files with 1,647 additions and 11 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@ description = "The model classes that are used in the Dungeon Hub API."

repositories {
mavenCentral()

maven {
url = uri("https://repo.kordex.dev/releases")
name = "KordEx (Releases)"
}
maven {
url = uri("https://repo.kordex.dev/snapshots")
name = "KordEx (Snapshots)"
}
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
name = "Sonatype Snapshots (Legacy)"
}
}

dependencies {
implementation("com.squareup.moshi:moshi-kotlin:1.15.1")

//Moshi, the JSON library
api("com.squareup.moshi:moshi-kotlin:1.15.1")
ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.1")

//Used frameworks for compatible classes
implementation("dev.kordex:kord-extensions:2.2.1-SNAPSHOT")
implementation("org.springframework:spring-web:6.1.12")

testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(kotlin("test"))
Expand Down Expand Up @@ -72,6 +89,9 @@ tasks.test {

kotlin {
jvmToolchain(17)
compilerOptions {
freeCompilerArgs.add("-Xjvm-default=all")
}
}

java {
Expand Down
7 changes: 7 additions & 0 deletions model/src/main/kotlin/net/dungeonhub/enums/QueueStep.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.dungeonhub.enums

enum class QueueStep {
Confirmation,
Transcript,
Approving
}
11 changes: 11 additions & 0 deletions model/src/main/kotlin/net/dungeonhub/enums/ScoreResetType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.dungeonhub.enums

import dev.kordex.core.commands.application.slash.converters.ChoiceEnum

enum class ScoreResetType : ChoiceEnum {
Default,
Event,
Both;

override val readableName = name
}
32 changes: 32 additions & 0 deletions model/src/main/kotlin/net/dungeonhub/enums/ScoreType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.dungeonhub.enums

import dev.kordex.core.commands.application.slash.converters.ChoiceEnum
import net.dungeonhub.model.carry_type.CarryTypeModel

enum class ScoreType(
override val readableName: String,
val displayName: String,
val leaderboardSuffix: String?
) : ChoiceEnum {
Default("current", "Current"),
Alltime("alltime", "Alltime", "(all-time)"),
Event("event", "Event", "(event)");

constructor(name: String, displayName: String) : this(name, displayName, null)

fun getLeaderboardTitle(carryType: CarryTypeModel?): String {
val suffix = if (leaderboardSuffix.isNullOrBlank()) "" else " $leaderboardSuffix"

if (carryType == null) {
return "Leaderboard | Total score$suffix"
}

return "Leaderboard | ${carryType.displayName}-Carries$suffix"
}

companion object {
fun fromName(name: String): ScoreType? = entries.firstOrNull { currentType: ScoreType ->
currentType.readableName.equals(name, ignoreCase = true)
}
}
}
9 changes: 9 additions & 0 deletions model/src/main/kotlin/net/dungeonhub/enums/WarningAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.dungeonhub.enums

enum class WarningAction {
Timeout,
Ban,
RemoveRole,
RemoveRoleGroup,
AddRole;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.dungeonhub.enums

enum class WarningComparison {
Equal,
GreaterOrEqual;
}
8 changes: 8 additions & 0 deletions model/src/main/kotlin/net/dungeonhub/enums/WarningType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.dungeonhub.enums

enum class WarningType {
Strike,
Minor,
Major,
Serious;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.dungeonhub.expections

class EntityUnknownException(
val id: Long
) : IllegalStateException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.dungeonhub.model.auth

import java.time.Instant

@JvmRecord
data class JwtTokenModel(val token: String, val validUntil: Instant)
44 changes: 44 additions & 0 deletions model/src/main/kotlin/net/dungeonhub/model/carry/CarryModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.dungeonhub.model.carry

import net.dungeonhub.structure.model.Model
import net.dungeonhub.model.carry_difficulty.CarryDifficultyModel
import net.dungeonhub.model.discord_user.DiscordUserModel
import net.dungeonhub.service.MoshiService
import java.time.Instant

data class CarryModel(
val id: Long,
val amount: Long,
val carryDifficulty: CarryDifficultyModel,
val player: DiscordUserModel,
val carrier: DiscordUserModel,
val approver: Long?,
val attachmentLink: String?,
val time: Instant?
): Model {
val carryTier = carryDifficulty.carryTier
val carryType = carryDifficulty.carryType

val scoreMultiplier = carryDifficulty.score

fun calculatePrice(): Long {
val bulkPrice = carryDifficulty.bulkPrice
val bulkAmount = carryDifficulty.bulkAmount

if (bulkPrice != null && bulkAmount != null && bulkAmount <= amount) {
return bulkPrice.toLong()
}

return carryDifficulty.price.toLong()
}

fun calculateScore(): Long {
return scoreMultiplier * amount
}

companion object {
fun fromString(json: String): CarryModel {
return MoshiService.moshi.adapter(CarryModel::class.java).fromJson(json)!!
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.dungeonhub.model.carry_difficulty

import net.dungeonhub.structure.model.CreationModel

class CarryDifficultyCreationModel(
var identifier: String,
var displayName: String,
var thumbnailUrl: String? = null,
var bulkPrice: Int? = null,
var bulkAmount: Int? = null,
var priceName: String? = null,
var price: Int,
var score: Int
) : CreationModel
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.dungeonhub.model.carry_difficulty

import net.dungeonhub.model.carry_tier.CarryTierModel
import net.dungeonhub.model.carry_type.CarryTypeModel
import net.dungeonhub.service.MoshiService
import net.dungeonhub.structure.model.UpdateableModel
import kotlin.math.max

class CarryDifficultyModel(
val id: Long,
val identifier: String,
val displayName: String,
val carryTier: CarryTierModel,
val price: Int,
bulkPrice: Int?,
bulkAmount: Int?,
score: Int,
thumbnailUrl: String?,
priceName: String?
) : UpdateableModel<CarryDifficultyUpdateModel, CarryDifficultyModel> {
val bulkPrice = bulkPrice
get() = if (field != null && field > 0) field else null

val bulkAmount = bulkAmount
get() = if (field != null && field > 0) field else null

val score = score
get() = max(field, 0)

val thumbnailUrl: String? = thumbnailUrl
get() = field ?: carryTier.thumbnailUrl

val priceName = priceName
get() = (if (!field.isNullOrBlank()) field else null) ?: displayName

val carryType: CarryTypeModel
get() = carryTier.carryType

fun toJson(): String {
return MoshiService.moshi.adapter(CarryDifficultyModel::class.java).toJson(this)
}

override fun getUpdateModel(): CarryDifficultyUpdateModel {
return CarryDifficultyUpdateModel(null, null, null, null, null, null, null)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as CarryDifficultyModel

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}

companion object {
fun fromJson(json: String): CarryDifficultyModel {
return MoshiService.moshi.adapter(CarryDifficultyModel::class.java).fromJson(json)!!
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package net.dungeonhub.model.carry_difficulty

import net.dungeonhub.service.MoshiService
import net.dungeonhub.structure.model.UpdateModel

class CarryDifficultyUpdateModel(
var displayName: String?,
thumbnailUrl: String?,
bulkPrice: Int?,
bulkAmount: Int?,
priceName: String?,
var price: Int?,
var score: Int?
) : UpdateModel<CarryDifficultyModel> {
var thumbnailUrl = thumbnailUrl
set(value) {
field = value
resetThumbnailUrl = value == null
}

var bulkPrice = bulkPrice
set(value) {
field = value
resetBulkPrice = value == null
}

var bulkAmount = bulkAmount
set(value) {
field = value
resetBulkAmount = value == null
}

var priceName = priceName
set(value) {
field = value
resetPriceName = value == null
}

var resetThumbnailUrl = false
private set
var resetBulkPrice = false
private set
var resetBulkAmount = false
private set
var resetPriceName = false
private set

/*override fun apply(model: CarryDifficultyModel): CarryDifficultyModel {
if (displayName != null) {
model.setDisplayName(displayName)
}
if (thumbnailUrl != null) {
model.setThumbnailUrl(thumbnailUrl)
}
if (bulkPrice != null) {
model.setBulkPrice(bulkPrice)
}
if (bulkAmount != null) {
model.setBulkAmount(bulkAmount)
}
if (priceName != null) {
model.setPriceName(priceName)
}
if (price != null) {
model.setPrice(price)
}
if (score != null) {
model.setScore(score)
}
return model
}*/

fun toJson(): String {
return MoshiService.moshi.adapter(CarryDifficultyUpdateModel::class.java).toJson(this)
}

companion object {
fun fromJson(json: String): CarryDifficultyUpdateModel {
return MoshiService.moshi.adapter(CarryDifficultyUpdateModel::class.java).fromJson(json)!!
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.dungeonhub.model.carry_queue

import net.dungeonhub.enums.QueueStep
import net.dungeonhub.service.MoshiService
import net.dungeonhub.structure.model.CreationModel
import java.time.Instant

class CarryQueueCreationModel(
var queueStep: QueueStep,
var carrier: Long,
var player: Long,
var amount: Long,
var relationId: Long? = null,
var attachmentLink: String? = null,
var time: Instant? = null,
) : CreationModel {
fun toJson(): String {
return MoshiService.moshi.adapter(CarryQueueCreationModel::class.java).toJson(this)
}
}
Loading

0 comments on commit fa46c48

Please sign in to comment.