diff --git a/src/main/kotlin/com/wbrawner/budgetserver/budget/Budget.kt b/src/main/kotlin/com/wbrawner/budgetserver/budget/Budget.kt index 5001d40..33eebfa 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/budget/Budget.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/budget/Budget.kt @@ -16,7 +16,9 @@ data class Budget( @OneToMany(mappedBy = "budget") val transactions: Set = TreeSet(), @OneToMany(mappedBy = "budget") val categories: Set = TreeSet(), @ManyToMany val users: Set = mutableSetOf(), - @ManyToOne val owner: User + @Column(nullable = false) + @ManyToOne + val owner: User? = null ) data class NewBudgetRequest(val name: String, val description: String?, val userIds: Set) diff --git a/src/main/kotlin/com/wbrawner/budgetserver/category/Category.kt b/src/main/kotlin/com/wbrawner/budgetserver/category/Category.kt index 113f2fc..b51c756 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/category/Category.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/category/Category.kt @@ -11,7 +11,9 @@ data class Category( val title: String = "", val description: String? = null, val amount: Long = 0, - @ManyToOne val budget: Budget, + @Column(nullable = false) + @ManyToOne + val budget: Budget? = null, @OneToMany(mappedBy = "category") val transactions: Set = emptySet(), val expense: Boolean? = true ) : Comparable { @@ -31,7 +33,7 @@ data class CategoryResponse( category.title, category.description, category.amount, - category.budget.id!!, + category.budget!!.id!!, category.expense ) } diff --git a/src/main/kotlin/com/wbrawner/budgetserver/transaction/Transaction.kt b/src/main/kotlin/com/wbrawner/budgetserver/transaction/Transaction.kt index 6d4c9aa..336e1c4 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/transaction/Transaction.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/transaction/Transaction.kt @@ -15,8 +15,12 @@ data class Transaction( val amount: Long = 0, @ManyToOne val category: Category? = null, val expense: Boolean = true, - @ManyToOne val createdBy: User, - @ManyToOne val budget: Budget + @ManyToOne + @Column(nullable = false) + val createdBy: User? = null, + @ManyToOne + @Column(nullable = false) + val budget: Budget? = null ) : Comparable { override fun compareTo(other: Transaction): Int = this.date.compareTo(other.date) } @@ -39,9 +43,9 @@ data class TransactionResponse( transaction.date.toString(), transaction.amount, transaction.expense, - transaction.budget.id!!, + transaction.budget!!.id!!, if (transaction.category != null) transaction.category.id!! else null, - transaction.createdBy.id!! + transaction.createdBy!!.id!! ) }