mirror of https://github.com/hykilpikonna/AquaDX
[+] More work on import feature (TODO)
parent
ac18234e29
commit
fc8ecb7470
|
@ -20,11 +20,8 @@ import org.apache.tika.Tika
|
||||||
import org.apache.tika.mime.MimeTypes
|
import org.apache.tika.mime.MimeTypes
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.web.bind.annotation.PathVariable
|
import org.springframework.web.bind.annotation.*
|
||||||
import org.springframework.web.bind.annotation.RequestBody
|
import java.lang.reflect.Field
|
||||||
import org.springframework.web.bind.annotation.RequestHeader
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam
|
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
@ -69,6 +66,7 @@ fun <C, T: Any> KMutableProperty1<C, T>.setCast(obj: C, value: String) = set(obj
|
||||||
Boolean::class -> value.toBoolean()
|
Boolean::class -> value.toBoolean()
|
||||||
else -> 400 - "Invalid field type $returnType"
|
else -> 400 - "Invalid field type $returnType"
|
||||||
} as T)
|
} as T)
|
||||||
|
inline fun <reified T: Any> Field.gets(obj: Any) = get(obj) as T
|
||||||
|
|
||||||
// Make it easier to throw a ResponseStatusException
|
// Make it easier to throw a ResponseStatusException
|
||||||
operator fun HttpStatus.invoke(message: String? = null): Nothing = throw ApiException(value(), message ?: this.reasonPhrase)
|
operator fun HttpStatus.invoke(message: String? = null): Nothing = throw ApiException(value(), message ?: this.reasonPhrase)
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package icu.samnyan.aqua.net.games
|
package icu.samnyan.aqua.net.games
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import icu.samnyan.aqua.sega.general.model.Card
|
import icu.samnyan.aqua.sega.general.model.Card
|
||||||
|
import jakarta.persistence.*
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import org.springframework.context.annotation.Import
|
|
||||||
import org.springframework.data.domain.Page
|
import org.springframework.data.domain.Page
|
||||||
import org.springframework.data.domain.Pageable
|
import org.springframework.data.domain.Pageable
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
import org.springframework.data.jpa.repository.Query
|
import org.springframework.data.jpa.repository.Query
|
||||||
import org.springframework.data.repository.NoRepositoryBean
|
import org.springframework.data.repository.NoRepositoryBean
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.system.measureTimeMillis
|
|
||||||
|
|
||||||
data class TrendOut(val date: String, val rating: Int, val plays: Int)
|
data class TrendOut(val date: String, val rating: Int, val plays: Int)
|
||||||
|
|
||||||
|
@ -98,6 +98,22 @@ interface IGenericGamePlaylog {
|
||||||
val isAllPerfect: Boolean
|
val isAllPerfect: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
open class BaseEntity(
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@JsonIgnore
|
||||||
|
var id: Long = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
open class UserMappedEntity<T : IGenericUserData> : BaseEntity() {
|
||||||
|
@JsonIgnore
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "user_id")
|
||||||
|
open var user: T? = null
|
||||||
|
}
|
||||||
|
|
||||||
@NoRepositoryBean
|
@NoRepositoryBean
|
||||||
interface GenericUserDataRepo<T : IGenericUserData> : JpaRepository<T, Long> {
|
interface GenericUserDataRepo<T : IGenericUserData> : JpaRepository<T, Long> {
|
||||||
fun findByCard(card: Card): T?
|
fun findByCard(card: Card): T?
|
||||||
|
|
|
@ -8,6 +8,8 @@ import icu.samnyan.aqua.net.games.*
|
||||||
import icu.samnyan.aqua.net.utils.*
|
import icu.samnyan.aqua.net.utils.*
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.*
|
import icu.samnyan.aqua.sega.maimai2.model.*
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.UserDetail
|
import icu.samnyan.aqua.sega.maimai2.model.userdata.UserDetail
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
@ -24,8 +26,11 @@ class Maimai2(
|
||||||
override val userDataRepo: Mai2UserDataRepo,
|
override val userDataRepo: Mai2UserDataRepo,
|
||||||
val userGeneralDataRepository: Mai2UserGeneralDataRepo,
|
val userGeneralDataRepository: Mai2UserGeneralDataRepo,
|
||||||
val repos: Mai2Repos,
|
val repos: Mai2Repos,
|
||||||
val netProps: AquaNetProps
|
val netProps: AquaNetProps,
|
||||||
|
transManager: PlatformTransactionManager
|
||||||
): GameApiController<UserDetail>("mai2", UserDetail::class) {
|
): GameApiController<UserDetail>("mai2", UserDetail::class) {
|
||||||
|
val trans = TransactionTemplate(transManager)
|
||||||
|
|
||||||
override suspend fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
override suspend fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
||||||
findTrend(playlogRepo.findByUserCardExtId(card.extId)
|
findTrend(playlogRepo.findByUserCardExtId(card.extId)
|
||||||
.map { TrendLog(it.playDate, it.afterRating) })
|
.map { TrendLog(it.playDate, it.afterRating) })
|
||||||
|
@ -77,14 +82,31 @@ class Maimai2(
|
||||||
val export = json.parseJson<Maimai2DataExport>()
|
val export = json.parseJson<Maimai2DataExport>()
|
||||||
if (!export.gameId.equals("SDEZ", true)) 400 - "Invalid game ID"
|
if (!export.gameId.equals("SDEZ", true)) 400 - "Invalid game ID"
|
||||||
|
|
||||||
|
// Validate new user data
|
||||||
|
// Check that all ids are 0 (this should be true since all ids are @JsonIgnore)
|
||||||
|
if (export.userData.id != 0L) 400 - "User ID must be 0"
|
||||||
|
exportFields.keys.forEach { it.gets<BaseEntity>(export).id.let { if (it != 0L) 400 - "ID must be 0" } }
|
||||||
|
|
||||||
|
// Set user card
|
||||||
|
export.userData.card = u.ghostCard
|
||||||
|
// Set user of the remaining data
|
||||||
|
// exportFields.values.forEach { it.setUser(export.userData) }
|
||||||
|
|
||||||
// Check existing data
|
// Check existing data
|
||||||
if (repos.userData.findByCard(u.ghostCard) != null) {
|
val gu = repos.userData.findByCard(u.ghostCard)?.also { gu ->
|
||||||
// Store a backup of the old data
|
// Store a backup of the old data
|
||||||
val fl = "mai2-backup-${u.auId}-${LocalDateTime.now().isoDateTime()}.json"
|
val fl = "mai2-backup-${u.auId}-${LocalDateTime.now().isoDateTime()}.json"
|
||||||
(Path(netProps.importBackupPath) / fl).writeText(export(u).toJson())
|
(Path(netProps.importBackupPath) / fl).writeText(export(u).toJson())
|
||||||
|
}
|
||||||
|
|
||||||
|
trans.execute {
|
||||||
|
gu?.let {
|
||||||
// Delete the old data
|
// Delete the old data
|
||||||
TODO()
|
exportFields.values.forEach { it.deleteByUser(gu) }
|
||||||
|
repos.userData.deleteByCard(u.ghostCard)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert new data
|
||||||
}
|
}
|
||||||
|
|
||||||
TODO()
|
TODO()
|
||||||
|
|
|
@ -67,8 +67,8 @@ public class GetGameSettingHandler implements BaseHandler {
|
||||||
localAddr = "localhost";
|
localAddr = "localhost";
|
||||||
}
|
}
|
||||||
|
|
||||||
String addr = ALLNET_HOST.equals("") ? localAddr : ALLNET_HOST;
|
String addr = ALLNET_HOST.isEmpty() ? localAddr : ALLNET_HOST;
|
||||||
String port = ALLNET_PORT.equals("") ? SERVER_PORT : ALLNET_PORT;
|
String port = ALLNET_PORT.isEmpty() ? SERVER_PORT : ALLNET_PORT;
|
||||||
|
|
||||||
GameSetting gameSetting = new GameSetting(
|
GameSetting gameSetting = new GameSetting(
|
||||||
ROM_VERSION, // Chusan checks these two versions to determine if it can enable game modes
|
ROM_VERSION, // Chusan checks these two versions to determine if it can enable game modes
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
package icu.samnyan.aqua.sega.maimai2.model.gamedata;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Entity(name = "Maimai2GameCharge")
|
|
||||||
@Table(name = "maimai2_game_charge")
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class GameCharge implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@JsonIgnore
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
private int orderId;
|
|
||||||
|
|
||||||
@Column(unique = true)
|
|
||||||
private int chargeId;
|
|
||||||
|
|
||||||
private int price;
|
|
||||||
|
|
||||||
private String startDate;
|
|
||||||
|
|
||||||
private String endDate;
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package icu.samnyan.aqua.sega.maimai2.model.gamedata
|
||||||
|
|
||||||
|
import icu.samnyan.aqua.net.games.BaseEntity
|
||||||
|
import jakarta.persistence.Column
|
||||||
|
import jakarta.persistence.Entity
|
||||||
|
import jakarta.persistence.Table
|
||||||
|
import lombok.AllArgsConstructor
|
||||||
|
import lombok.Data
|
||||||
|
import lombok.NoArgsConstructor
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
|
*/
|
||||||
|
@Entity(name = "Maimai2GameCharge")
|
||||||
|
@Table(name = "maimai2_game_charge")
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
class GameCharge : Serializable, BaseEntity() {
|
||||||
|
val orderId = 0
|
||||||
|
|
||||||
|
@Column(unique = true)
|
||||||
|
var chargeId = 0
|
||||||
|
|
||||||
|
val price = 0
|
||||||
|
|
||||||
|
val startDate: String? = null
|
||||||
|
|
||||||
|
val endDate: String? = null
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val serialVersionUID = 1L
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package icu.samnyan.aqua.sega.maimai2.model.userdata
|
package icu.samnyan.aqua.sega.maimai2.model.userdata
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude
|
import com.fasterxml.jackson.annotation.JsonInclude
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||||
import ext.Str
|
import ext.Str
|
||||||
|
import icu.samnyan.aqua.net.games.BaseEntity
|
||||||
import icu.samnyan.aqua.net.games.IGenericUserData
|
import icu.samnyan.aqua.net.games.IGenericUserData
|
||||||
import icu.samnyan.aqua.sega.general.model.Card
|
import icu.samnyan.aqua.sega.general.model.Card
|
||||||
import icu.samnyan.aqua.sega.maimai2.util.IntegerListConverter
|
import icu.samnyan.aqua.sega.maimai2.util.IntegerListConverter
|
||||||
|
@ -18,11 +18,6 @@ import java.io.Serializable
|
||||||
@Entity(name = "Maimai2UserData")
|
@Entity(name = "Maimai2UserData")
|
||||||
@Table(name = "maimai2_user_detail")
|
@Table(name = "maimai2_user_detail")
|
||||||
class UserDetail(
|
class UserDetail(
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@JsonIgnore
|
|
||||||
var id: Long = 0,
|
|
||||||
|
|
||||||
@JsonSerialize(using = AccessCodeSerializer::class)
|
@JsonSerialize(using = AccessCodeSerializer::class)
|
||||||
@JsonProperty(value = "accessCode", access = JsonProperty.Access.READ_ONLY)
|
@JsonProperty(value = "accessCode", access = JsonProperty.Access.READ_ONLY)
|
||||||
@OneToOne
|
@OneToOne
|
||||||
|
@ -158,7 +153,7 @@ class UserDetail(
|
||||||
// TODO: Make these non-nullable with default value
|
// TODO: Make these non-nullable with default value
|
||||||
var currentPlayCount: Int? = 0,
|
var currentPlayCount: Int? = 0,
|
||||||
var renameCredit: Int? = 0
|
var renameCredit: Int? = 0
|
||||||
) : Serializable, IGenericUserData {
|
) : Serializable, IGenericUserData, BaseEntity() {
|
||||||
override val totalScore: Long
|
override val totalScore: Long
|
||||||
get() = totalDeluxscore
|
get() = totalDeluxscore
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue