From 1bcbf5e53abfafbe6beb86188894c9f794e8d3cf Mon Sep 17 00:00:00 2001 From: xds Date: Mon, 26 May 2025 13:59:23 +0300 Subject: [PATCH] + fixes --- .../budgerapp/configs/TelegramBotConfig.kt | 3 +- .../controllers/RecurrentController.kt | 31 +++++++++++++------ .../budgerapp/controllers/SpaceController.kt | 16 +++++++--- .../budgerapp/services/CategoryService.kt | 2 -- .../budgerapp/services/RecurrentService.kt | 5 +-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/space/luminic/budgerapp/configs/TelegramBotConfig.kt b/src/main/kotlin/space/luminic/budgerapp/configs/TelegramBotConfig.kt index cf9ec34..9653821 100644 --- a/src/main/kotlin/space/luminic/budgerapp/configs/TelegramBotConfig.kt +++ b/src/main/kotlin/space/luminic/budgerapp/configs/TelegramBotConfig.kt @@ -21,5 +21,6 @@ class TelegramBotConfig { @ConfigurationProperties(prefix = "telegram.bot") data class TelegramBotProperties( val username: String, - val token: String + val token: String, + val enable:Int ) diff --git a/src/main/kotlin/space/luminic/budgerapp/controllers/RecurrentController.kt b/src/main/kotlin/space/luminic/budgerapp/controllers/RecurrentController.kt index a758e8e..f877aaf 100644 --- a/src/main/kotlin/space/luminic/budgerapp/controllers/RecurrentController.kt +++ b/src/main/kotlin/space/luminic/budgerapp/controllers/RecurrentController.kt @@ -1,22 +1,35 @@ package space.luminic.budgerapp.controllers 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.PutMapping -import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import reactor.core.publisher.Mono -import space.luminic.budgerapp.models.Recurrent +import space.luminic.budgerapp.configs.AuthException +import space.luminic.budgerapp.services.AuthService import space.luminic.budgerapp.services.RecurrentService +import space.luminic.budgerapp.services.SpaceService @RestController -@RequestMapping("/recurrents") -class RecurrentController ( - private val recurrentService: RecurrentService +@RequestMapping("/spaces/{spaceId}") +class RecurrentController( + private val recurrentService: RecurrentService, + private val authService: AuthService, + private val spaceService: SpaceService ){ + +// @DeleteMapping("/recurrents/{recurrentId}") +// suspend fun delete( +// @PathVariable spaceId: String, +// @PathVariable recurrentId: String): String { +// val user = authService.getSecurityUser() +// val space = spaceService.isValidRequest(spaceId, user) +// if (space.owner?.id == user.id) { +// recurrentService.deleteRecurrent(recurrentId) +// return "Cool" +// } else { +// throw AuthException("Only owners allowed") +// } +// } // // @GetMapping("/") // fun getRecurrents(): Mono> { diff --git a/src/main/kotlin/space/luminic/budgerapp/controllers/SpaceController.kt b/src/main/kotlin/space/luminic/budgerapp/controllers/SpaceController.kt index 8c6a62d..1785bdb 100644 --- a/src/main/kotlin/space/luminic/budgerapp/controllers/SpaceController.kt +++ b/src/main/kotlin/space/luminic/budgerapp/controllers/SpaceController.kt @@ -11,6 +11,7 @@ import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* +import space.luminic.budgerapp.configs.AuthException import space.luminic.budgerapp.controllers.BudgetController.LimitValue import space.luminic.budgerapp.controllers.dtos.BudgetCreationDTO import space.luminic.budgerapp.models.* @@ -357,14 +358,14 @@ class SpaceController( return recurrentService.getRecurrentById(space, id).awaitSingle() } - @PostMapping("/{spaceId}/recurrent") + @PostMapping("/{spaceId}/recurrents") suspend fun createRecurrent(@PathVariable spaceId: String, @RequestBody recurrent: Recurrent): Recurrent { val user = authService.getSecurityUser() val space = spaceService.isValidRequest(spaceId, user) return recurrentService.createRecurrent(space, recurrent).awaitSingle() } - @PutMapping("/{spaceId}/recurrent/{id}") + @PutMapping("/{spaceId}/recurrents/{id}") suspend fun editRecurrent( @PathVariable spaceId: String, @PathVariable id: String, @@ -376,11 +377,16 @@ class SpaceController( } - @DeleteMapping("/{spaceId}/recurrent/{id}") + @DeleteMapping("/{spaceId}/recurrents/{id}") suspend fun deleteRecurrent(@PathVariable spaceId: String, @PathVariable id: String) { val user = authService.getSecurityUser() - spaceService.isValidRequest(spaceId, user) - recurrentService.deleteRecurrent(id).awaitSingle() + val space = spaceService.isValidRequest(spaceId, user) + if (space.owner?.id == user.id) { + recurrentService.deleteRecurrent(id) + } else { + throw AuthException("Only owners allowed") + } + } // @GetMapping("/regen") diff --git a/src/main/kotlin/space/luminic/budgerapp/services/CategoryService.kt b/src/main/kotlin/space/luminic/budgerapp/services/CategoryService.kt index 57a37c9..a75e46d 100644 --- a/src/main/kotlin/space/luminic/budgerapp/services/CategoryService.kt +++ b/src/main/kotlin/space/luminic/budgerapp/services/CategoryService.kt @@ -68,7 +68,6 @@ class CategoryService( }.awaitFirstOrNull() ?: throw NotFoundException("Category not found") } - @Cacheable(cacheNames = ["categories"]) suspend fun getCategories( spaceId: String, type: String? = null, @@ -133,7 +132,6 @@ class CategoryService( } - @CacheEvict(cacheNames = ["getAllCategories"], allEntries = true) suspend fun editCategory(space: Space, category: Category): Category { val oldCategory = findCategory(space, id = category.id) diff --git a/src/main/kotlin/space/luminic/budgerapp/services/RecurrentService.kt b/src/main/kotlin/space/luminic/budgerapp/services/RecurrentService.kt index abad179..b2902b8 100644 --- a/src/main/kotlin/space/luminic/budgerapp/services/RecurrentService.kt +++ b/src/main/kotlin/space/luminic/budgerapp/services/RecurrentService.kt @@ -1,6 +1,7 @@ package space.luminic.budgerapp.services +import kotlinx.coroutines.reactive.awaitFirstOrNull import kotlinx.coroutines.reactive.awaitLast import kotlinx.coroutines.reactive.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull @@ -124,8 +125,8 @@ class RecurrentService( ) } - fun deleteRecurrent(id: String): Mono { - return recurrentRepo.deleteById(id) + suspend fun deleteRecurrent(id: String) { + recurrentRepo.deleteById(id).awaitFirstOrNull() }