fix spaces
This commit is contained in:
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.*
|
||||
import org.springframework.web.client.HttpClientErrorException
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
import space.luminic.budgerapp.controllers.BudgetController.LimitValue
|
||||
import space.luminic.budgerapp.controllers.dtos.BudgetCreationDTO
|
||||
import space.luminic.budgerapp.models.*
|
||||
import space.luminic.budgerapp.services.CategoryService
|
||||
@@ -39,7 +40,10 @@ class SpaceController(
|
||||
|
||||
@PostMapping
|
||||
fun createSpace(@RequestBody space: SpaceCreateDTO): Mono<Space> {
|
||||
return spaceService.createSpace(Space(name=space.name, description = space.description), space.createCategories)
|
||||
return spaceService.createSpace(
|
||||
Space(name = space.name, description = space.description),
|
||||
space.createCategories
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -81,21 +85,53 @@ class SpaceController(
|
||||
//
|
||||
//Budgets API
|
||||
//
|
||||
@GetMapping("{spaceId}/budgets")
|
||||
@GetMapping("/{spaceId}/budgets")
|
||||
fun getBudgets(@PathVariable spaceId: String): Mono<List<Budget>> {
|
||||
return financialService.getBudgets(spaceId)
|
||||
}
|
||||
|
||||
@GetMapping("/{spaceId}/budgets/{id}")
|
||||
fun getBudget(@PathVariable spaceId: String, @PathVariable id: String): Mono<BudgetDTO> {
|
||||
return spaceService.isValidRequest(spaceId).flatMap {
|
||||
financialService.getBudget(spaceId, id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/{spaceId}/budgets")
|
||||
fun createBudget(
|
||||
@PathVariable spaceId: String,
|
||||
@RequestBody budgetCreationDTO: BudgetCreationDTO,
|
||||
): Mono<Budget> {
|
||||
return financialService.createBudget(spaceId, budgetCreationDTO.budget, budgetCreationDTO.createRecurrent)
|
||||
return spaceService.isValidRequest(spaceId).flatMap {
|
||||
financialService.createBudget(spaceId, budgetCreationDTO.budget, budgetCreationDTO.createRecurrent)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("/{spaceId}/budgets/{id}")
|
||||
fun deleteBudget(@PathVariable spaceId: String, @PathVariable id: String): Mono<Void> {
|
||||
return spaceService.isValidRequest(spaceId).flatMap {
|
||||
financialService.deleteBudget(spaceId, id)
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/{spaceId}/budgets/{budgetId}/categories/{catId}/limit")
|
||||
fun setCategoryLimit(
|
||||
@PathVariable spaceId: String,
|
||||
@PathVariable budgetId: String,
|
||||
@PathVariable catId: String,
|
||||
@RequestBody limit: LimitValue,
|
||||
): Mono<BudgetCategory> {
|
||||
return spaceService.isValidRequest(spaceId).flatMap {
|
||||
financialService.setCategoryLimit(it.id!!,budgetId, catId, limit.limit)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Transactions API
|
||||
//
|
||||
@GetMapping("/{spaceId}/transactions")
|
||||
fun getTransactions(
|
||||
@PathVariable spaceId: String,
|
||||
@@ -125,7 +161,6 @@ class SpaceController(
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/{spaceId}/transactions/{id}")
|
||||
fun getTransaction(
|
||||
@PathVariable spaceId: String,
|
||||
@@ -140,31 +175,29 @@ class SpaceController(
|
||||
}
|
||||
|
||||
@PostMapping("/{spaceId}/transactions")
|
||||
fun createTransaction(@PathVariable spaceId: String, @RequestBody transaction: Transaction): ResponseEntity<Any> {
|
||||
try {
|
||||
return ResponseEntity.ok(financialService.createTransaction(spaceId, transaction))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
|
||||
fun createTransaction(@PathVariable spaceId: String, @RequestBody transaction: Transaction): Mono<Transaction> {
|
||||
return spaceService.isValidRequest(spaceId).flatMap {
|
||||
financialService.createTransaction(spaceId, transaction)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@PutMapping("/{spaceId}/transactions/{id}")
|
||||
fun editTransaction(
|
||||
@PathVariable spaceId: String, @PathVariable id: String, @RequestBody transaction: Transaction
|
||||
): ResponseEntity<Any> {
|
||||
try {
|
||||
return ResponseEntity.ok(financialService.editTransaction(transaction))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
): Mono<Transaction> {
|
||||
return spaceService.isValidRequest(spaceId).flatMap {
|
||||
transaction.space = it
|
||||
financialService.editTransaction(transaction)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("/{spaceId}/transactions/{id}")
|
||||
fun deleteTransaction(@PathVariable spaceId: String, @PathVariable id: String): Mono<Void> {
|
||||
return financialService.deleteTransaction(id)
|
||||
return spaceService.isValidRequest(spaceId).flatMap {
|
||||
financialService.getTransactionById(id).flatMap { financialService.deleteTransaction(it) }
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -200,7 +233,7 @@ class SpaceController(
|
||||
@PathVariable spaceId: String, @RequestBody category: Category
|
||||
): Mono<Category> {
|
||||
return spaceService.isValidRequest(spaceId).flatMap {
|
||||
categoryService.createCategory(it,category)
|
||||
financialService.createCategory(it, category)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user