This commit is contained in:
xds
2025-05-26 13:59:23 +03:00
parent 5d9cc167fc
commit 1bcbf5e53a
5 changed files with 38 additions and 19 deletions

View File

@@ -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
)

View File

@@ -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<List<Recurrent>> {

View File

@@ -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")

View File

@@ -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)

View File

@@ -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<Void> {
return recurrentRepo.deleteById(id)
suspend fun deleteRecurrent(id: String) {
recurrentRepo.deleteById(id).awaitFirstOrNull()
}