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.slf4j.LoggerFactory
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestHeader
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.lang.reflect.Field
|
||||
import java.nio.file.Path
|
||||
import java.time.LocalDate
|
||||
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()
|
||||
else -> 400 - "Invalid field type $returnType"
|
||||
} as T)
|
||||
inline fun <reified T: Any> Field.gets(obj: Any) = get(obj) as T
|
||||
|
||||
// Make it easier to throw a ResponseStatusException
|
||||
operator fun HttpStatus.invoke(message: String? = null): Nothing = throw ApiException(value(), message ?: this.reasonPhrase)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package icu.samnyan.aqua.net.games
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import icu.samnyan.aqua.sega.general.model.Card
|
||||
import jakarta.persistence.*
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.springframework.context.annotation.Import
|
||||
import org.springframework.data.domain.Page
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.NoRepositoryBean
|
||||
import java.util.*
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
data class TrendOut(val date: String, val rating: Int, val plays: Int)
|
||||
|
||||
|
@ -98,6 +98,22 @@ interface IGenericGamePlaylog {
|
|||
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
|
||||
interface GenericUserDataRepo<T : IGenericUserData> : JpaRepository<T, Long> {
|
||||
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.sega.maimai2.model.*
|
||||
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 java.lang.reflect.Field
|
||||
import java.time.LocalDateTime
|
||||
|
@ -24,8 +26,11 @@ class Maimai2(
|
|||
override val userDataRepo: Mai2UserDataRepo,
|
||||
val userGeneralDataRepository: Mai2UserGeneralDataRepo,
|
||||
val repos: Mai2Repos,
|
||||
val netProps: AquaNetProps
|
||||
val netProps: AquaNetProps,
|
||||
transManager: PlatformTransactionManager
|
||||
): GameApiController<UserDetail>("mai2", UserDetail::class) {
|
||||
val trans = TransactionTemplate(transManager)
|
||||
|
||||
override suspend fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
||||
findTrend(playlogRepo.findByUserCardExtId(card.extId)
|
||||
.map { TrendLog(it.playDate, it.afterRating) })
|
||||
|
@ -77,14 +82,31 @@ class Maimai2(
|
|||
val export = json.parseJson<Maimai2DataExport>()
|
||||
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
|
||||
if (repos.userData.findByCard(u.ghostCard) != null) {
|
||||
val gu = repos.userData.findByCard(u.ghostCard)?.also { gu ->
|
||||
// Store a backup of the old data
|
||||
val fl = "mai2-backup-${u.auId}-${LocalDateTime.now().isoDateTime()}.json"
|
||||
(Path(netProps.importBackupPath) / fl).writeText(export(u).toJson())
|
||||
}
|
||||
|
||||
// Delete the old data
|
||||
TODO()
|
||||
trans.execute {
|
||||
gu?.let {
|
||||
// Delete the old data
|
||||
exportFields.values.forEach { it.deleteByUser(gu) }
|
||||
repos.userData.deleteByCard(u.ghostCard)
|
||||
}
|
||||
|
||||
// Insert new data
|
||||
}
|
||||
|
||||
TODO()
|
||||
|
|
|
@ -67,8 +67,8 @@ public class GetGameSettingHandler implements BaseHandler {
|
|||
localAddr = "localhost";
|
||||
}
|
||||
|
||||
String addr = ALLNET_HOST.equals("") ? localAddr : ALLNET_HOST;
|
||||
String port = ALLNET_PORT.equals("") ? SERVER_PORT : ALLNET_PORT;
|
||||
String addr = ALLNET_HOST.isEmpty() ? localAddr : ALLNET_HOST;
|
||||
String port = ALLNET_PORT.isEmpty() ? SERVER_PORT : ALLNET_PORT;
|
||||
|
||||
GameSetting gameSetting = new GameSetting(
|
||||
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
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||
import ext.Str
|
||||
import icu.samnyan.aqua.net.games.BaseEntity
|
||||
import icu.samnyan.aqua.net.games.IGenericUserData
|
||||
import icu.samnyan.aqua.sega.general.model.Card
|
||||
import icu.samnyan.aqua.sega.maimai2.util.IntegerListConverter
|
||||
|
@ -18,11 +18,6 @@ import java.io.Serializable
|
|||
@Entity(name = "Maimai2UserData")
|
||||
@Table(name = "maimai2_user_detail")
|
||||
class UserDetail(
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@JsonIgnore
|
||||
var id: Long = 0,
|
||||
|
||||
@JsonSerialize(using = AccessCodeSerializer::class)
|
||||
@JsonProperty(value = "accessCode", access = JsonProperty.Access.READ_ONLY)
|
||||
@OneToOne
|
||||
|
@ -158,7 +153,7 @@ class UserDetail(
|
|||
// TODO: Make these non-nullable with default value
|
||||
var currentPlayCount: Int? = 0,
|
||||
var renameCredit: Int? = 0
|
||||
) : Serializable, IGenericUserData {
|
||||
) : Serializable, IGenericUserData, BaseEntity() {
|
||||
override val totalScore: Long
|
||||
get() = totalDeluxscore
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue