feature/creation #2
|
|
@ -2,21 +2,32 @@ package org.octopus.internal.common.models
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonGetter
|
import com.fasterxml.jackson.annotation.JsonGetter
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
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(
|
||||||
|
@field:Schema(description = "The id of the entry in the DB")
|
||||||
var id: Long?,
|
var id: Long?,
|
||||||
|
@field:Schema(description = "The name of the entry (between 1 and 50 characters long).")
|
||||||
val name: String,
|
val name: String,
|
||||||
|
@field:Schema(description = "The type of entry (INCOME, OUTCOME, INVESTMENT).")
|
||||||
val type: EEntryType,
|
val type: EEntryType,
|
||||||
|
@field:Schema(description = "The amount of the entry (greater than 0.00).")
|
||||||
val amount: Double,
|
val amount: Double,
|
||||||
|
@field:Schema(description = "IF NOT recurrent: when is the entry being counted.")
|
||||||
val fixedDate: Date? = null,
|
val fixedDate: Date? = null,
|
||||||
|
@field:Schema(description = "IF recurrent: must be true")
|
||||||
val recurrent: Boolean? = false,
|
val recurrent: Boolean? = false,
|
||||||
|
@field:Schema(description = "IF recurrent: list of month in which the event is repeated (1=JAN, 12=DEC)")
|
||||||
@get:JsonIgnore
|
@get:JsonIgnore
|
||||||
val recurrentMonths: List<Month>? = mutableListOf(),
|
val recurrentMonths: List<Month>? = mutableListOf(),
|
||||||
|
@field:Schema(description = "IF recurrent: starting date of the repetition")
|
||||||
val startDate: Date? = null,
|
val startDate: Date? = null,
|
||||||
|
@field:Schema(description = "IF recurrent: ending date of the repetition")
|
||||||
val endDate: Date? = null,
|
val endDate: Date? = null,
|
||||||
|
@field:Schema(description = "Color of the entry in the UI")
|
||||||
val color: String
|
val color: String
|
||||||
){
|
){
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package org.octopus.internal.web.controllers
|
package org.octopus.internal.web.controllers
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag
|
||||||
import jakarta.validation.Valid
|
import jakarta.validation.Valid
|
||||||
import lombok.AllArgsConstructor
|
import lombok.AllArgsConstructor
|
||||||
import org.octopus.internal.common.models.Entry
|
import org.octopus.internal.common.models.Entry
|
||||||
|
|
@ -12,10 +15,17 @@ import org.springframework.web.bind.annotation.*
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/entries")
|
@RequestMapping("/entries")
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Tag(name = "Entries Management", description = "Operations related to entries.")
|
||||||
class EntryController(
|
class EntryController(
|
||||||
val entryService: EntryService
|
val entryService: EntryService
|
||||||
) {
|
) {
|
||||||
|
@Operation(
|
||||||
|
summary = "Create a new planning entry",
|
||||||
|
description = "Adds a new income, outcome, or investment entry to the system.",
|
||||||
|
responses = [
|
||||||
|
ApiResponse(responseCode = "200", description = "Entry created successfully. Returned with ID")
|
||||||
|
]
|
||||||
|
)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
fun createEntry(
|
fun createEntry(
|
||||||
@Valid @RequestBody entryDto: EntryDto
|
@Valid @RequestBody entryDto: EntryDto
|
||||||
|
|
@ -23,21 +33,49 @@ class EntryController(
|
||||||
return WebResponse.ok(entryService.createEntry(entryDto))
|
return WebResponse.ok(entryService.createEntry(entryDto))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(
|
||||||
|
summary = "Get all entries in the DB",
|
||||||
|
description = "Returns a list containing all entries.",
|
||||||
|
responses = [
|
||||||
|
ApiResponse(responseCode = "200", description = "A valid list.")
|
||||||
|
]
|
||||||
|
)
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun getAllEntries(): WebResponse<List<Entry>> {
|
fun getAllEntries(): WebResponse<List<Entry>> {
|
||||||
return WebResponse.ok(entryService.getAllEntries())
|
return WebResponse.ok(entryService.getAllEntries())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(
|
||||||
|
summary = "Delete all entries in the DB",
|
||||||
|
description = "Returns the result of the operation.",
|
||||||
|
responses = [
|
||||||
|
ApiResponse(responseCode = "200", description = "Whether the operation succeeded.")
|
||||||
|
]
|
||||||
|
)
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
fun deleteAllEntries(): WebResponse<Boolean> {
|
fun deleteAllEntries(): WebResponse<Boolean> {
|
||||||
return WebResponse.ok(entryService.deleteAll())
|
return WebResponse.ok(entryService.deleteAll())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(
|
||||||
|
summary = "Delete a specific entry in the DB",
|
||||||
|
description = "Returns the result of the operation.",
|
||||||
|
responses = [
|
||||||
|
ApiResponse(responseCode = "200", description = "Whether the operation succeeded.")
|
||||||
|
]
|
||||||
|
)
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
fun deleteEntryById(@PathVariable("id") id: Long): WebResponse<Boolean> {
|
fun deleteEntryById(@PathVariable("id") id: Long): WebResponse<Boolean> {
|
||||||
return WebResponse.ok(entryService.deleteById(id))
|
return WebResponse.ok(entryService.deleteById(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(
|
||||||
|
summary = "Updates a specific entry in the DB",
|
||||||
|
description = "Returns the updated entry.",
|
||||||
|
responses = [
|
||||||
|
ApiResponse(responseCode = "200", description = "The updated entry.")
|
||||||
|
]
|
||||||
|
)
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
fun editEntryById(@PathVariable("id") id: Long,
|
fun editEntryById(@PathVariable("id") id: Long,
|
||||||
@Valid @RequestBody entryDto: EntryDto): WebResponse<Entry> {
|
@Valid @RequestBody entryDto: EntryDto): WebResponse<Entry> {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package org.octopus.internal.web.utils.dtos
|
package org.octopus.internal.web.utils.dtos
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
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.EntryHexColorValidator
|
||||||
|
|
@ -8,18 +9,35 @@ import org.octopus.internal.web.utils.dtos.validators.EntryTypeValidator
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
data class EntryDto(
|
data class EntryDto(
|
||||||
|
@field:Schema(description = "The name of the entry (between 1 and 50 characters long).")
|
||||||
@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,
|
val name: String,
|
||||||
|
|
||||||
|
@field:Schema(description = "The type of entry (INCOME, OUTCOME, INVESTMENT).")
|
||||||
@field:EntryTypeValidator.Validate
|
@field:EntryTypeValidator.Validate
|
||||||
val type: String,
|
val type: String,
|
||||||
|
|
||||||
|
@field:Schema(description = "The amount of the entry (greater than 0.00).")
|
||||||
@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.")
|
||||||
val amount: Double,
|
val amount: Double,
|
||||||
|
|
||||||
|
@field:Schema(description = "IF NOT recurrent: when is the entry being counted.")
|
||||||
val fixedDate: Date?,
|
val fixedDate: Date?,
|
||||||
|
|
||||||
|
@field:Schema(description = "IF recurrent: must be true")
|
||||||
val recurrent: Boolean?,
|
val recurrent: Boolean?,
|
||||||
|
|
||||||
|
@field:Schema(description = "IF recurrent: list of month in which the event is repeated (1=JAN, 12=DEC)")
|
||||||
@field:EntryMonthValidator.Validate
|
@field:EntryMonthValidator.Validate
|
||||||
val recurrentMonths: List<Int>?,
|
val recurrentMonths: List<Int>?,
|
||||||
|
|
||||||
|
@field:Schema(description = "IF recurrent: starting date of the repetition")
|
||||||
val startDate: Date?,
|
val startDate: Date?,
|
||||||
|
|
||||||
|
@field:Schema(description = "IF recurrent: ending date of the repetition")
|
||||||
val endDate: Date?,
|
val endDate: Date?,
|
||||||
|
|
||||||
|
@field:Schema(description = "Color of the entry in the UI")
|
||||||
@field:EntryHexColorValidator.Validate
|
@field:EntryHexColorValidator.Validate
|
||||||
val color: String = "0xFFFFFF"
|
val color: String = "0xFFFFFF"
|
||||||
)
|
)
|
||||||
Loading…
Reference in New Issue