More operations

This commit is contained in:
Jari 2025-10-18 17:17:47 +02:00
parent c93186cc52
commit 8e3f94527d
8 changed files with 61 additions and 6 deletions

View File

@ -11,5 +11,6 @@ data class Entry(
val fixedDate: Date? = null, val fixedDate: Date? = null,
val recurrent: Boolean? = false, val recurrent: Boolean? = false,
val recurrentMonths: List<Month>? = mutableListOf(), val recurrentMonths: List<Month>? = mutableListOf(),
val startDate: Date? = null,
val endDate: Date? = null val endDate: Date? = null
) )

View File

@ -1,10 +1,12 @@
package org.octopus.internal.db.entities package org.octopus.internal.db.entities
import jakarta.persistence.Convert
import jakarta.persistence.Entity import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType import jakarta.persistence.GenerationType
import jakarta.persistence.Id import jakarta.persistence.Id
import org.octopus.internal.common.enums.EEntryType import org.octopus.internal.common.enums.EEntryType
import org.octopus.internal.db.converters.MonthListConverter
import java.time.Month import java.time.Month
import java.util.Date import java.util.Date
@ -16,6 +18,8 @@ data class EntryEntity(
val amount: Double, val amount: Double,
val fixedDate: Date? = null, val fixedDate: Date? = null,
val recurrent: Boolean? = false, val recurrent: Boolean? = false,
@field:Convert(converter = MonthListConverter::class)
val recurrentMonths: List<Month>? = mutableListOf(), val recurrentMonths: List<Month>? = mutableListOf(),
val startDate: Date? = null,
val endDate: Date? = null val endDate: Date? = null
) )

View File

@ -13,4 +13,7 @@ interface EntryRepository {
fun getAllRecurrentOnAllMonths(): MutableList<Entry> fun getAllRecurrentOnAllMonths(): MutableList<Entry>
fun getAllFixedUpToEndDate(endDate: Date): MutableList<Entry> fun getAllFixedUpToEndDate(endDate: Date): MutableList<Entry>
fun getAllByType(type: EEntryType): MutableList<Entry> fun getAllByType(type: EEntryType): MutableList<Entry>
fun deleteById(id: Long): Boolean
fun deleteAll(): Boolean
} }

View File

@ -37,6 +37,17 @@ class EntryRepositoryImpl(
return mapper.toModels(jpa.findAllByType(type)) return mapper.toModels(jpa.findAllByType(type))
} }
override fun deleteById(id: Long): Boolean {
jpa.deleteById(id)
return true
}
override fun deleteAll(): Boolean {
jpa.deleteAll()
return true
}
override fun getAllRecurrentMonthlyToEndDate(endDate: Date): MutableList<Entry> { override fun getAllRecurrentMonthlyToEndDate(endDate: Date): MutableList<Entry> {
return mapper.toModels( return mapper.toModels(
jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndEndDateIsNotNullAndEndDateBefore(endDate) jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndEndDateIsNotNullAndEndDateBefore(endDate)

View File

@ -6,4 +6,7 @@ import org.octopus.internal.web.utils.dtos.EntryDto
interface EntryService { interface EntryService {
fun createEntry(entry: EntryDto): Entry fun createEntry(entry: EntryDto): Entry
fun getAllEntries(): MutableList<Entry> fun getAllEntries(): MutableList<Entry>
fun deleteAll(): Boolean
fun deleteById(id: Long): Boolean
fun editEntry(id: Long, entry: EntryDto): Entry
} }

View File

@ -22,22 +22,43 @@ class EntryServiceImpl(val repo: EntryRepository) : EntryService {
type = EEntryType.valueOf(entry.type), type = EEntryType.valueOf(entry.type),
amount = entry.amount, amount = entry.amount,
fixedDate = entry.fixedDate, fixedDate = entry.fixedDate,
startDate = entry.startDate,
endDate = entry.endDate, endDate = entry.endDate,
recurrent = entry.recurrent, recurrent = entry.recurrent,
recurrentMonths = entry.recurrentMonths?.map { m -> Month.of(m) } recurrentMonths = entry.recurrentMonths?.map { m -> Month.of(m) }?.toList() ?: emptyList()
)) ))
} }
override fun getAllEntries(): MutableList<Entry> { override fun getAllEntries(): MutableList<Entry> {
TODO("Not yet implemented") val income = repo.getAllByType(EEntryType.INCOME)
val outcome = repo.getAllByType(EEntryType.OUTCOME)
val invest = repo.getAllByType(EEntryType.INVESTMENT)
return (income + outcome + invest).toMutableList()
}
override fun deleteAll(): Boolean {
return repo.deleteAll()
}
override fun deleteById(id: Long): Boolean {
return repo.deleteById(id)
}
override fun editEntry(id: Long, entry: EntryDto): Entry {
// var savedEntry = repo.getById(id)
// savedEntry.startDate = entry.startDate
TODO("FINIRE STA MERDA")
return repo.getById(id)
} }
private fun verifyDto(entry: EntryDto): Boolean { private fun verifyDto(entry: EntryDto): Boolean {
val eventIsRecurring = entry.fixedDate == null && val eventIsRecurring = entry.fixedDate == null &&
entry.startDate != null &&
entry.endDate != null && entry.endDate != null &&
entry.recurrent == true && entry.recurrent == true &&
entry.recurrentMonths?.isNotEmpty() ?: false entry.recurrentMonths?.isNotEmpty() ?: false
val eventIsFixed = entry.fixedDate != null && val eventIsFixed = entry.fixedDate != null &&
entry.startDate == null &&
entry.endDate == null && entry.endDate == null &&
entry.recurrent != true && entry.recurrent != true &&
entry.recurrentMonths?.isEmpty() ?: true entry.recurrentMonths?.isEmpty() ?: true

View File

@ -24,10 +24,19 @@ class EntryController(
} }
@GetMapping @GetMapping
fun getAllClients(): WebResponse<List<Entry>> { fun getAllEntries(): WebResponse<List<Entry>> {
return WebResponse.ok(entryService.getAllEntries()) return WebResponse.ok(entryService.getAllEntries())
} }
@DeleteMapping
fun deleteAllEntries(): WebResponse<Boolean> {
return WebResponse.ok(entryService.deleteAll())
}
@DeleteMapping("/{id}")
fun deleteEntryById(@PathVariable("id") id: Long): WebResponse<Boolean> {
return WebResponse.ok(entryService.deleteById(id))
}
// @GetMapping("/{id}") // @GetMapping("/{id}")
// fun getClient(@PathVariable("id") id: String, @RequestParam( // fun getClient(@PathVariable("id") id: String, @RequestParam(

View File

@ -1,19 +1,22 @@
package org.octopus.internal.web.utils.dtos package org.octopus.internal.web.utils.dtos
import jakarta.validation.constraints.DecimalMin import jakarta.validation.constraints.DecimalMin
import org.hibernate.validator.constraints.Length
import org.octopus.internal.web.utils.dtos.validators.EntryMonthValidator import org.octopus.internal.web.utils.dtos.validators.EntryMonthValidator
import org.octopus.internal.web.utils.dtos.validators.EntryTypeValidator import org.octopus.internal.web.utils.dtos.validators.EntryTypeValidator
import java.util.Date import java.util.Date
data class EntryDto( data class EntryDto(
@field:Length(min = 1, max = 50, message = "The name must be between 1 and 50 characters long.")
@field:EntryTypeValidator.Validate @field:EntryTypeValidator.Validate
val type: String, val type: String,
@field:DecimalMin(value="0.00", inclusive = false, message = "Amount value cannot be lower than 0.01") @field:DecimalMin(value="0.00", inclusive = false, message = "The amount must be greater than 0.00.")
val amount: Double, val amount: Double,
val fixedDate: Date?, val fixedDate: Date?,
val recurrent: Boolean?, val recurrent: Boolean?,
@field:EntryMonthValidator.Validate @field:EntryMonthValidator.Validate
val recurrentMonths: List<Int>?, val recurrentMonths: List<Int>?,
val endDate: Date? val startDate: Date?,
val endDate: Date?,
val color: String = "0xFFFFFF"
) )