More operations
This commit is contained in:
parent
c93186cc52
commit
8e3f94527d
|
|
@ -11,5 +11,6 @@ data class Entry(
|
|||
val fixedDate: Date? = null,
|
||||
val recurrent: Boolean? = false,
|
||||
val recurrentMonths: List<Month>? = mutableListOf(),
|
||||
val startDate: Date? = null,
|
||||
val endDate: Date? = null
|
||||
)
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
package org.octopus.internal.db.entities
|
||||
|
||||
import jakarta.persistence.Convert
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import org.octopus.internal.common.enums.EEntryType
|
||||
import org.octopus.internal.db.converters.MonthListConverter
|
||||
import java.time.Month
|
||||
import java.util.Date
|
||||
|
||||
|
|
@ -16,6 +18,8 @@ data class EntryEntity(
|
|||
val amount: Double,
|
||||
val fixedDate: Date? = null,
|
||||
val recurrent: Boolean? = false,
|
||||
@field:Convert(converter = MonthListConverter::class)
|
||||
val recurrentMonths: List<Month>? = mutableListOf(),
|
||||
val startDate: Date? = null,
|
||||
val endDate: Date? = null
|
||||
)
|
||||
|
|
@ -13,4 +13,7 @@ interface EntryRepository {
|
|||
fun getAllRecurrentOnAllMonths(): MutableList<Entry>
|
||||
fun getAllFixedUpToEndDate(endDate: Date): MutableList<Entry>
|
||||
fun getAllByType(type: EEntryType): MutableList<Entry>
|
||||
|
||||
fun deleteById(id: Long): Boolean
|
||||
fun deleteAll(): Boolean
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,17 @@ class EntryRepositoryImpl(
|
|||
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> {
|
||||
return mapper.toModels(
|
||||
jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndEndDateIsNotNullAndEndDateBefore(endDate)
|
||||
|
|
|
|||
|
|
@ -6,4 +6,7 @@ import org.octopus.internal.web.utils.dtos.EntryDto
|
|||
interface EntryService {
|
||||
fun createEntry(entry: EntryDto): Entry
|
||||
fun getAllEntries(): MutableList<Entry>
|
||||
fun deleteAll(): Boolean
|
||||
fun deleteById(id: Long): Boolean
|
||||
fun editEntry(id: Long, entry: EntryDto): Entry
|
||||
}
|
||||
|
|
@ -22,22 +22,43 @@ class EntryServiceImpl(val repo: EntryRepository) : EntryService {
|
|||
type = EEntryType.valueOf(entry.type),
|
||||
amount = entry.amount,
|
||||
fixedDate = entry.fixedDate,
|
||||
startDate = entry.startDate,
|
||||
endDate = entry.endDate,
|
||||
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> {
|
||||
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 {
|
||||
val eventIsRecurring = entry.fixedDate == null &&
|
||||
entry.startDate != null &&
|
||||
entry.endDate != null &&
|
||||
entry.recurrent == true &&
|
||||
entry.recurrentMonths?.isNotEmpty() ?: false
|
||||
val eventIsFixed = entry.fixedDate != null &&
|
||||
entry.startDate == null &&
|
||||
entry.endDate == null &&
|
||||
entry.recurrent != true &&
|
||||
entry.recurrentMonths?.isEmpty() ?: true
|
||||
|
|
|
|||
|
|
@ -24,10 +24,19 @@ class EntryController(
|
|||
}
|
||||
|
||||
@GetMapping
|
||||
fun getAllClients(): WebResponse<List<Entry>> {
|
||||
fun getAllEntries(): WebResponse<List<Entry>> {
|
||||
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}")
|
||||
// fun getClient(@PathVariable("id") id: String, @RequestParam(
|
||||
|
|
|
|||
|
|
@ -1,19 +1,22 @@
|
|||
package org.octopus.internal.web.utils.dtos
|
||||
|
||||
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.EntryTypeValidator
|
||||
import java.util.Date
|
||||
|
||||
data class EntryDto(
|
||||
@field:Length(min = 1, max = 50, message = "The name must be between 1 and 50 characters long.")
|
||||
@field:EntryTypeValidator.Validate
|
||||
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 fixedDate: Date?,
|
||||
val recurrent: Boolean?,
|
||||
@field:EntryMonthValidator.Validate
|
||||
val recurrentMonths: List<Int>?,
|
||||
val endDate: Date?
|
||||
|
||||
val startDate: Date?,
|
||||
val endDate: Date?,
|
||||
val color: String = "0xFFFFFF"
|
||||
)
|
||||
Loading…
Reference in New Issue