swaggeriño 2

This commit is contained in:
Jari 2025-10-19 15:39:19 +02:00
parent f7f3b1c80b
commit e9ccb15b4e
3 changed files with 68 additions and 1 deletions

View File

@ -2,21 +2,32 @@ package org.octopus.internal.common.models
import com.fasterxml.jackson.annotation.JsonGetter
import com.fasterxml.jackson.annotation.JsonIgnore
import io.swagger.v3.oas.annotations.media.Schema
import org.octopus.internal.common.enums.EEntryType
import java.time.Month
import java.util.*
data class Entry(
@field:Schema(description = "The id of the entry in the DB")
var id: Long?,
@field:Schema(description = "The name of the entry (between 1 and 50 characters long).")
val name: String,
@field:Schema(description = "The type of entry (INCOME, OUTCOME, INVESTMENT).")
val type: EEntryType,
@field:Schema(description = "The amount of the entry (greater than 0.00).")
val amount: Double,
@field:Schema(description = "IF NOT recurrent: when is the entry being counted.")
val fixedDate: Date? = null,
@field:Schema(description = "IF recurrent: must be true")
val recurrent: Boolean? = false,
@field:Schema(description = "IF recurrent: list of month in which the event is repeated (1=JAN, 12=DEC)")
@get:JsonIgnore
val recurrentMonths: List<Month>? = mutableListOf(),
@field:Schema(description = "IF recurrent: starting date of the repetition")
val startDate: Date? = null,
@field:Schema(description = "IF recurrent: ending date of the repetition")
val endDate: Date? = null,
@field:Schema(description = "Color of the entry in the UI")
val color: String
){

View File

@ -1,5 +1,8 @@
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 lombok.AllArgsConstructor
import org.octopus.internal.common.models.Entry
@ -12,10 +15,17 @@ import org.springframework.web.bind.annotation.*
@RestController
@RequestMapping("/entries")
@AllArgsConstructor
@Tag(name = "Entries Management", description = "Operations related to entries.")
class EntryController(
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
fun createEntry(
@Valid @RequestBody entryDto: EntryDto
@ -23,21 +33,49 @@ class EntryController(
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
fun getAllEntries(): WebResponse<List<Entry>> {
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
fun deleteAllEntries(): WebResponse<Boolean> {
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}")
fun deleteEntryById(@PathVariable("id") id: Long): WebResponse<Boolean> {
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}")
fun editEntryById(@PathVariable("id") id: Long,
@Valid @RequestBody entryDto: EntryDto): WebResponse<Entry> {

View File

@ -1,5 +1,6 @@
package org.octopus.internal.web.utils.dtos
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.DecimalMin
import org.hibernate.validator.constraints.Length
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
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.")
val name: String,
@field:Schema(description = "The type of entry (INCOME, OUTCOME, INVESTMENT).")
@field:EntryTypeValidator.Validate
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.")
val amount: Double,
@field:Schema(description = "IF NOT recurrent: when is the entry being counted.")
val fixedDate: Date?,
@field:Schema(description = "IF recurrent: must be true")
val recurrent: Boolean?,
@field:Schema(description = "IF recurrent: list of month in which the event is repeated (1=JAN, 12=DEC)")
@field:EntryMonthValidator.Validate
val recurrentMonths: List<Int>?,
@field:Schema(description = "IF recurrent: starting date of the repetition")
val startDate: Date?,
@field:Schema(description = "IF recurrent: ending date of the repetition")
val endDate: Date?,
@field:Schema(description = "Color of the entry in the UI")
@field:EntryHexColorValidator.Validate
val color: String = "0xFFFFFF"
)