Refine logic
This commit is contained in:
parent
6ee21f0e87
commit
80fb3db547
|
|
@ -1,16 +1,27 @@
|
||||||
package org.octopus.internal.common.models
|
package org.octopus.internal.common.models
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonGetter
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import org.octopus.internal.common.enums.EEntryType
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
import java.time.Month
|
import java.time.Month
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
data class Entry(
|
data class Entry(
|
||||||
var id: Long?,
|
var id: Long?,
|
||||||
|
val name: String,
|
||||||
val type: EEntryType,
|
val type: EEntryType,
|
||||||
val amount: Double,
|
val amount: Double,
|
||||||
val fixedDate: Date? = null,
|
val fixedDate: Date? = null,
|
||||||
val recurrent: Boolean? = false,
|
val recurrent: Boolean? = false,
|
||||||
|
@get:JsonIgnore
|
||||||
val recurrentMonths: List<Month>? = mutableListOf(),
|
val recurrentMonths: List<Month>? = mutableListOf(),
|
||||||
val startDate: Date? = null,
|
val startDate: Date? = null,
|
||||||
val endDate: Date? = null
|
val endDate: Date? = null,
|
||||||
)
|
val color: String
|
||||||
|
){
|
||||||
|
|
||||||
|
@JsonGetter("recurrentMonths")
|
||||||
|
fun getRecurrentMonthsAsInts(): List<Int>? {
|
||||||
|
return this.recurrentMonths?.map { it.value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ import java.util.Date
|
||||||
data class EntryEntity(
|
data class EntryEntity(
|
||||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
var id: Long = 0L,
|
var id: Long = 0L,
|
||||||
|
val name: String,
|
||||||
val type: EEntryType,
|
val type: EEntryType,
|
||||||
val amount: Double,
|
val amount: Double,
|
||||||
val fixedDate: Date? = null,
|
val fixedDate: Date? = null,
|
||||||
|
|
@ -21,5 +22,6 @@ data class EntryEntity(
|
||||||
@field:Convert(converter = MonthListConverter::class)
|
@field:Convert(converter = MonthListConverter::class)
|
||||||
val recurrentMonths: List<Month>? = mutableListOf(),
|
val recurrentMonths: List<Month>? = mutableListOf(),
|
||||||
val startDate: Date? = null,
|
val startDate: Date? = null,
|
||||||
val endDate: Date? = null
|
val endDate: Date? = null,
|
||||||
|
val color: String
|
||||||
)
|
)
|
||||||
|
|
@ -19,13 +19,15 @@ class EntryServiceImpl(val repo: EntryRepository) : EntryService {
|
||||||
|
|
||||||
return repo.createEntry(Entry(
|
return repo.createEntry(Entry(
|
||||||
id = 0L,
|
id = 0L,
|
||||||
|
name = entry.name,
|
||||||
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,
|
startDate = entry.startDate,
|
||||||
endDate = entry.endDate,
|
endDate = entry.endDate,
|
||||||
recurrent = entry.recurrent,
|
recurrent = entry.recurrent,
|
||||||
recurrentMonths = entry.recurrentMonths?.map { m -> Month.of(m) }?.toList() ?: emptyList()
|
recurrentMonths = entry.recurrentMonths?.map { m -> Month.of(m) }?.toList() ?: emptyList(),
|
||||||
|
color = entry.color
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,10 +47,22 @@ class EntryServiceImpl(val repo: EntryRepository) : EntryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun editEntry(id: Long, entry: EntryDto): Entry {
|
override fun editEntry(id: Long, entry: EntryDto): Entry {
|
||||||
// var savedEntry = repo.getById(id)
|
if (!verifyDto(entry)) {
|
||||||
// savedEntry.startDate = entry.startDate
|
throw OctopusPlanningException.create(EBusinessException.INVALID_REQUEST, entry, "Entry must be either recurring or fixed.")
|
||||||
TODO("FINIRE STA MERDA")
|
}
|
||||||
return repo.getById(id)
|
|
||||||
|
return repo.createEntry(Entry(
|
||||||
|
id = id,
|
||||||
|
name = entry.name,
|
||||||
|
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) }?.toList() ?: emptyList(),
|
||||||
|
color = entry.color
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun verifyDto(entry: EntryDto): Boolean {
|
private fun verifyDto(entry: EntryDto): Boolean {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,12 @@ class EntryController(
|
||||||
return WebResponse.ok(entryService.deleteById(id))
|
return WebResponse.ok(entryService.deleteById(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
fun editEntryById(@PathVariable("id") id: Long,
|
||||||
|
@Valid @RequestBody entryDto: EntryDto): WebResponse<Entry> {
|
||||||
|
return WebResponse.ok(entryService.editEntry(id, entryDto))
|
||||||
|
}
|
||||||
|
|
||||||
// @GetMapping("/{id}")
|
// @GetMapping("/{id}")
|
||||||
// fun getClient(@PathVariable("id") id: String, @RequestParam(
|
// fun getClient(@PathVariable("id") id: String, @RequestParam(
|
||||||
// "includeDeactivated",
|
// "includeDeactivated",
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,14 @@ 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.hibernate.validator.constraints.Length
|
||||||
|
import org.octopus.internal.web.utils.dtos.validators.EntryHexColorValidator
|
||||||
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:Length(min = 1, max = 50, message = "The name must be between 1 and 50 characters long.")
|
||||||
|
val name: String,
|
||||||
@field:EntryTypeValidator.Validate
|
@field:EntryTypeValidator.Validate
|
||||||
val type: String,
|
val type: String,
|
||||||
@field:DecimalMin(value="0.00", inclusive = false, message = "The amount must be greater than 0.00.")
|
@field:DecimalMin(value="0.00", inclusive = false, message = "The amount must be greater than 0.00.")
|
||||||
|
|
@ -18,5 +20,6 @@ data class EntryDto(
|
||||||
val recurrentMonths: List<Int>?,
|
val recurrentMonths: List<Int>?,
|
||||||
val startDate: Date?,
|
val startDate: Date?,
|
||||||
val endDate: Date?,
|
val endDate: Date?,
|
||||||
|
@field:EntryHexColorValidator.Validate
|
||||||
val color: String = "0xFFFFFF"
|
val color: String = "0xFFFFFF"
|
||||||
)
|
)
|
||||||
Loading…
Reference in New Issue