init
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
package space.luminic.budgerapp.controllers
|
||||
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.DeleteMapping
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import reactor.core.publisher.Mono
|
||||
import space.luminic.budgerapp.controllers.dtos.BudgetCreationDTO
|
||||
import space.luminic.budgerapp.models.Budget
|
||||
import space.luminic.budgerapp.models.BudgetDTO
|
||||
import space.luminic.budgerapp.models.Transaction
|
||||
import space.luminic.budgerapp.models.Warn
|
||||
|
||||
import space.luminic.budgerapp.services.BudgetService
|
||||
import space.luminic.budgerapp.services.CacheInspector
|
||||
import java.math.BigDecimal
|
||||
import java.sql.Date
|
||||
import java.time.LocalDate
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/budgets")
|
||||
class BudgetController(
|
||||
val budgetService: BudgetService
|
||||
) {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(BudgetController::class.java)
|
||||
|
||||
@GetMapping
|
||||
fun getBudgets(): Mono<MutableList<Budget>> {
|
||||
return budgetService.getBudgets()
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
fun getBudget(@PathVariable id: String): Mono<BudgetDTO> {
|
||||
// logger.info(cacheInspector.getCacheContent("budgets").toString())
|
||||
return budgetService.getBudget(id)
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/by-dates")
|
||||
fun getBudgetByDate(@RequestParam date: LocalDate): ResponseEntity<Any> {
|
||||
return ResponseEntity.ok(budgetService.getBudgetByDate(date))
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/{id}/categories")
|
||||
fun getBudgetCategories(@PathVariable id: String): ResponseEntity<Any> {
|
||||
return ResponseEntity.ok(budgetService.getBudgetCategories(id))
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/transactions")
|
||||
fun getBudgetTransactions(@PathVariable id: String):Mono<Map<String,List<Transaction>>> {
|
||||
return budgetService.getBudgetTransactionsByType(id)
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
fun createBudget(@RequestBody budgetCreationDTO: BudgetCreationDTO): Mono<Budget> {
|
||||
return budgetService.createBudget(
|
||||
budgetCreationDTO.budget,
|
||||
budgetCreationDTO.createRecurrent
|
||||
)
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
fun deleteBudget(@PathVariable id: String): Mono<Void> {
|
||||
return budgetService.deleteBudget(id)
|
||||
}
|
||||
|
||||
@PostMapping("/{budgetId}/categories/{catId}/limit")
|
||||
fun setCategoryLimit(
|
||||
@PathVariable budgetId: String,
|
||||
@PathVariable catId: String,
|
||||
@RequestBody limit: LimitValue,
|
||||
): ResponseEntity<Any> {
|
||||
return try {
|
||||
ResponseEntity.ok(budgetService.setCategoryLimit(budgetId, catId, limit.limit))
|
||||
} catch (e: Exception) {
|
||||
ResponseEntity.badRequest().body(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/recalc-categories")
|
||||
fun recalcCategories(): Mono<Void> {
|
||||
return budgetService.recalcBudgetCategory()
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/warns")
|
||||
fun budgetWarns(@PathVariable id: String, @RequestParam hidden: Boolean? = null): Mono<List<Warn>> {
|
||||
return budgetService.getWarns(id, hidden)
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/warns/{warnId}/hide")
|
||||
fun setWarnHide(@PathVariable id: String, @PathVariable warnId: String): Mono<Warn> {
|
||||
return budgetService.hideWarn(id, warnId)
|
||||
|
||||
|
||||
}
|
||||
|
||||
data class LimitValue(
|
||||
var limit: Double
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user