feature/creation #2

Merged
zobrock merged 7 commits from feature/creation into main 2025-10-19 15:41:14 +02:00
5 changed files with 44 additions and 8 deletions
Showing only changes of commit 80fb3db547 - Show all commits

View File

@ -1,16 +1,27 @@
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 java.time.Month
import java.util.*
data class Entry(
var id: Long?,
val name: String,
val type: EEntryType,
val amount: Double,
val fixedDate: Date? = null,
val recurrent: Boolean? = false,
@get:JsonIgnore
val recurrentMonths: List<Month>? = mutableListOf(),
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 }
}
}

View File

@ -14,6 +14,7 @@ import java.util.Date
data class EntryEntity(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long = 0L,
val name: String,
val type: EEntryType,
val amount: Double,
val fixedDate: Date? = null,
@ -21,5 +22,6 @@ data class EntryEntity(
@field:Convert(converter = MonthListConverter::class)
val recurrentMonths: List<Month>? = mutableListOf(),
val startDate: Date? = null,
val endDate: Date? = null
val endDate: Date? = null,
val color: String
)

View File

@ -19,13 +19,15 @@ class EntryServiceImpl(val repo: EntryRepository) : EntryService {
return repo.createEntry(Entry(
id = 0L,
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()
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 {
// var savedEntry = repo.getById(id)
// savedEntry.startDate = entry.startDate
TODO("FINIRE STA MERDA")
return repo.getById(id)
if (!verifyDto(entry)) {
throw OctopusPlanningException.create(EBusinessException.INVALID_REQUEST, entry, "Entry must be either recurring or fixed.")
}
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 {

View File

@ -38,6 +38,12 @@ class EntryController(
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}")
// fun getClient(@PathVariable("id") id: String, @RequestParam(
// "includeDeactivated",

View File

@ -2,12 +2,14 @@ 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.EntryHexColorValidator
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.")
val name: String,
@field:EntryTypeValidator.Validate
val type: String,
@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 startDate: Date?,
val endDate: Date?,
@field:EntryHexColorValidator.Validate
val color: String = "0xFFFFFF"
)