init
This commit is contained in:
42
src/main/kotlin/space/luminic/budgerapp/models/Budget.kt
Normal file
42
src/main/kotlin/space/luminic/budgerapp/models/Budget.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
import java.math.BigDecimal
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
|
||||
|
||||
data class BudgetDTO(
|
||||
var id: String? = null,
|
||||
var name: String,
|
||||
var dateFrom: LocalDate,
|
||||
var dateTo: LocalDate,
|
||||
val createdAt: LocalDateTime = LocalDateTime.now(),
|
||||
var plannedExpenses: MutableList<Transaction>? = null,
|
||||
var plannedIncomes: MutableList<Transaction>? = null,
|
||||
var categories: MutableList<BudgetCategory> = mutableListOf(),
|
||||
var transactions: MutableList<Transaction>? = null,
|
||||
|
||||
)
|
||||
|
||||
|
||||
@Document("budgets")
|
||||
data class Budget(
|
||||
@Id var id: String? = null,
|
||||
var name: String,
|
||||
var dateFrom: LocalDate,
|
||||
var dateTo: LocalDate,
|
||||
val createdAt: LocalDateTime = LocalDateTime.now(),
|
||||
var categories: MutableList<BudgetCategory> = mutableListOf(),
|
||||
)
|
||||
|
||||
data class BudgetCategory(
|
||||
@Transient var currentSpent: Double? = null,
|
||||
var currentLimit: Double,
|
||||
@Transient var currentPlanned: Double? = null,
|
||||
@DBRef var category: Category
|
||||
)
|
||||
|
||||
class BudgetNotFoundException(message: String) : NotFoundException(message)
|
||||
21
src/main/kotlin/space/luminic/budgerapp/models/Category.kt
Normal file
21
src/main/kotlin/space/luminic/budgerapp/models/Category.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
|
||||
|
||||
@Document("categories")
|
||||
data class Category(
|
||||
@Id
|
||||
val id: String? = null,
|
||||
var type: CategoryType,
|
||||
val name: String,
|
||||
val description: String? = null,
|
||||
val icon: String? = null
|
||||
)
|
||||
|
||||
|
||||
data class CategoryType(
|
||||
val code: String,
|
||||
val name: String? = null
|
||||
)
|
||||
@@ -0,0 +1,4 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
|
||||
open class NotFoundException(message: String) : Exception(message)
|
||||
@@ -0,0 +1,20 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
||||
@Serializable
|
||||
data class PushMessage(
|
||||
|
||||
// title: str
|
||||
// body: str
|
||||
// icon: str
|
||||
// badge: str
|
||||
// url: str
|
||||
val title: String,
|
||||
val body: String,
|
||||
val icon: String? = null,
|
||||
val budge: String? = null,
|
||||
val url: String? = null
|
||||
|
||||
)
|
||||
17
src/main/kotlin/space/luminic/budgerapp/models/Recurrent.kt
Normal file
17
src/main/kotlin/space/luminic/budgerapp/models/Recurrent.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
import java.util.Date
|
||||
|
||||
@Document(collection = "recurrents")
|
||||
data class Recurrent(
|
||||
@Id val id: String? = null,
|
||||
var atDay: Int,
|
||||
@DBRef var category: Category,
|
||||
var name: String,
|
||||
var description: String,
|
||||
var amount: Int,
|
||||
var createdAt: Date = Date()
|
||||
)
|
||||
13
src/main/kotlin/space/luminic/budgerapp/models/Sort.kt
Normal file
13
src/main/kotlin/space/luminic/budgerapp/models/Sort.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import org.springframework.data.domain.Sort.Direction
|
||||
|
||||
|
||||
enum class SortTypes {
|
||||
ASC, DESC
|
||||
}
|
||||
|
||||
data class SortSetting(
|
||||
val by: String,
|
||||
val order: Direction
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
import java.util.Date
|
||||
|
||||
@Document(collection = "subscriptions")
|
||||
data class Subscription(
|
||||
@Id val id: String? = null,
|
||||
@DBRef val user: User? = null,
|
||||
val endpoint: String,
|
||||
val auth: String,
|
||||
val p256dh: String,
|
||||
var isActive: Boolean,
|
||||
val createdAt: Date = Date()
|
||||
)
|
||||
|
||||
|
||||
data class SubscriptionDTO (
|
||||
val endpoint: String,
|
||||
val keys: Map<String, String>
|
||||
)
|
||||
20
src/main/kotlin/space/luminic/budgerapp/models/Token.kt
Normal file
20
src/main/kotlin/space/luminic/budgerapp/models/Token.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Document(collection = "tokens")
|
||||
data class Token(
|
||||
@Id
|
||||
val id: String? = null,
|
||||
val token: String,
|
||||
val username: String,
|
||||
val issuedAt: LocalDateTime,
|
||||
val expiresAt: LocalDateTime,
|
||||
val status: TokenStatus = TokenStatus.ACTIVE
|
||||
)
|
||||
|
||||
enum class TokenStatus {
|
||||
ACTIVE, REVOKED, EXPIRED
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
import java.math.BigDecimal
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.util.Date
|
||||
|
||||
@Document(collection = "transactions")
|
||||
data class Transaction(
|
||||
@Id var id: String? = null,
|
||||
var type: TransactionType,
|
||||
@DBRef var user: User?=null,
|
||||
@DBRef var category: Category,
|
||||
var comment: String,
|
||||
val date: LocalDate,
|
||||
var amount: Double,
|
||||
val isDone: Boolean,
|
||||
var parentId: String? = null,
|
||||
var createdAt: LocalDateTime? = LocalDateTime.now(),
|
||||
)
|
||||
|
||||
data class TransactionType(
|
||||
val code: String,
|
||||
val name: String
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import org.springframework.context.ApplicationEvent
|
||||
import java.math.BigDecimal
|
||||
|
||||
enum class TransactionEventType {
|
||||
CREATE, EDIT, DELETE
|
||||
}
|
||||
|
||||
class TransactionEvent(
|
||||
source: Any,
|
||||
val eventType: TransactionEventType,
|
||||
val oldTransaction: Transaction,
|
||||
val newTransaction: Transaction,
|
||||
var difference: Double? = null,
|
||||
) : ApplicationEvent(source) {
|
||||
override fun toString(): String {
|
||||
return "${eventType}, ${oldTransaction}, ${newTransaction}, $difference"
|
||||
}
|
||||
}
|
||||
26
src/main/kotlin/space/luminic/budgerapp/models/User.kt
Normal file
26
src/main/kotlin/space/luminic/budgerapp/models/User.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import jakarta.validation.constraints.NotBlank
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
import java.util.Date
|
||||
|
||||
@Document("users")
|
||||
data class User (
|
||||
@Id
|
||||
var id: String? = null,
|
||||
@field:NotBlank val username: String,
|
||||
var firstName: String,
|
||||
var tgId: String? = null,
|
||||
var tgUserName: String? = null,
|
||||
@JsonIgnore // Скрывает пароль при сериализации
|
||||
var password: String? = null,
|
||||
var isActive: Boolean = true,
|
||||
var regDate: Date? = null,
|
||||
val createdAt: Date? = null,
|
||||
var roles: MutableList<String> = mutableListOf(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
22
src/main/kotlin/space/luminic/budgerapp/models/Warn.kt
Normal file
22
src/main/kotlin/space/luminic/budgerapp/models/Warn.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package space.luminic.budgerapp.models
|
||||
|
||||
import org.bson.types.ObjectId
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
|
||||
enum class WarnSerenity(val level: String, val sort: Int) {
|
||||
OTHER("Другое", -10),
|
||||
MAIN("Основное", 0),
|
||||
IMPORTANT("Важное", 10)
|
||||
}
|
||||
|
||||
@Document(collection = "warns")
|
||||
data class Warn(
|
||||
@Id var id: String? = null,
|
||||
var serenity: WarnSerenity,
|
||||
var message: PushMessage,
|
||||
var budgetId: String,
|
||||
var context: String,
|
||||
var isHide: Boolean
|
||||
)
|
||||
Reference in New Issue
Block a user