+ bot + notifications
This commit is contained in:
@@ -10,10 +10,7 @@ import org.springframework.web.bind.annotation.*
|
||||
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
|
||||
import space.luminic.budgerapp.services.FinancialService
|
||||
import space.luminic.budgerapp.services.RecurrentService
|
||||
import space.luminic.budgerapp.services.SpaceService
|
||||
import space.luminic.budgerapp.services.*
|
||||
import java.time.LocalDate
|
||||
|
||||
@RestController
|
||||
@@ -22,7 +19,8 @@ class SpaceController(
|
||||
private val spaceService: SpaceService,
|
||||
private val financialService: FinancialService,
|
||||
private val categoryService: CategoryService,
|
||||
private val recurrentService: RecurrentService
|
||||
private val recurrentService: RecurrentService,
|
||||
private val authService: AuthService
|
||||
) {
|
||||
|
||||
private val log = LoggerFactory.getLogger(SpaceController::class.java)
|
||||
@@ -57,13 +55,16 @@ class SpaceController(
|
||||
|
||||
@DeleteMapping("/{spaceId}")
|
||||
suspend fun deleteSpace(@PathVariable spaceId: String) {
|
||||
return spaceService.deleteSpace(spaceService.isValidRequest(spaceId))
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return spaceService.deleteSpace(space)
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/{spaceId}/invite")
|
||||
suspend fun inviteSpace(@PathVariable spaceId: String): SpaceInvite {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return spaceService.createInviteSpace(spaceId)
|
||||
}
|
||||
|
||||
@@ -74,13 +75,15 @@ class SpaceController(
|
||||
|
||||
@DeleteMapping("/{spaceId}/leave")
|
||||
suspend fun leaveSpace(@PathVariable spaceId: String) {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return spaceService.leaveSpace(spaceId)
|
||||
}
|
||||
|
||||
@DeleteMapping("/{spaceId}/members/kick/{username}")
|
||||
suspend fun kickMembers(@PathVariable spaceId: String, @PathVariable username: String) {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return spaceService.kickMember(spaceId, username)
|
||||
}
|
||||
|
||||
@@ -90,7 +93,8 @@ class SpaceController(
|
||||
//
|
||||
@GetMapping("/{spaceId}/budgets")
|
||||
suspend fun getBudgets(@PathVariable spaceId: String): List<Budget> {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return financialService.getBudgets(spaceId).awaitSingleOrNull().orEmpty()
|
||||
|
||||
}
|
||||
@@ -98,7 +102,8 @@ class SpaceController(
|
||||
@GetMapping("/{spaceId}/budgets/{id}")
|
||||
suspend fun getBudget(@PathVariable spaceId: String, @PathVariable id: String): BudgetDTO? {
|
||||
log.info("Getting budget for spaceId=$spaceId, id=$id")
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return financialService.getBudget(spaceId, id)
|
||||
}
|
||||
|
||||
@@ -107,8 +112,10 @@ class SpaceController(
|
||||
@PathVariable spaceId: String,
|
||||
@RequestBody budgetCreationDTO: BudgetCreationDTO,
|
||||
): Budget? {
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return financialService.createBudget(
|
||||
spaceService.isValidRequest(spaceId),
|
||||
space,
|
||||
budgetCreationDTO.budget,
|
||||
budgetCreationDTO.createRecurrent
|
||||
)
|
||||
@@ -116,7 +123,8 @@ class SpaceController(
|
||||
|
||||
@DeleteMapping("/{spaceId}/budgets/{id}")
|
||||
suspend fun deleteBudget(@PathVariable spaceId: String, @PathVariable id: String) {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
financialService.deleteBudget(spaceId, id)
|
||||
|
||||
}
|
||||
@@ -128,7 +136,8 @@ class SpaceController(
|
||||
@PathVariable catId: String,
|
||||
@RequestBody limit: LimitValue,
|
||||
): BudgetCategory {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return financialService.setCategoryLimit(spaceId, budgetId, catId, limit.limit)
|
||||
}
|
||||
|
||||
@@ -174,7 +183,8 @@ class SpaceController(
|
||||
|
||||
@PostMapping("/{spaceId}/transactions")
|
||||
suspend fun createTransaction(@PathVariable spaceId: String, @RequestBody transaction: Transaction): Transaction {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return financialService.createTransaction(space, transaction)
|
||||
|
||||
|
||||
@@ -184,14 +194,16 @@ class SpaceController(
|
||||
suspend fun editTransaction(
|
||||
@PathVariable spaceId: String, @PathVariable id: String, @RequestBody transaction: Transaction
|
||||
): Transaction {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
transaction.space = space
|
||||
return financialService.editTransaction(transaction)
|
||||
return financialService.editTransaction(transaction, user)
|
||||
}
|
||||
|
||||
@DeleteMapping("/{spaceId}/transactions/{id}")
|
||||
suspend fun deleteTransaction(@PathVariable spaceId: String, @PathVariable id: String) {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
val transaction = financialService.getTransactionById(id)
|
||||
financialService.deleteTransaction(transaction)
|
||||
}
|
||||
@@ -206,7 +218,8 @@ class SpaceController(
|
||||
@RequestParam("sort") sortBy: String = "name",
|
||||
@RequestParam("direction") direction: String = "ASC"
|
||||
): List<Category> {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return categoryService.getCategories(spaceId, type, sortBy, direction).awaitSingleOrNull().orEmpty()
|
||||
}
|
||||
|
||||
@@ -219,7 +232,8 @@ class SpaceController(
|
||||
suspend fun createCategory(
|
||||
@PathVariable spaceId: String, @RequestBody category: Category
|
||||
): Category {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return financialService.createCategory(space, category).awaitSingle()
|
||||
}
|
||||
|
||||
@@ -229,33 +243,38 @@ class SpaceController(
|
||||
@RequestBody category: Category,
|
||||
@PathVariable spaceId: String
|
||||
): Category {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return categoryService.editCategory(space, category)
|
||||
}
|
||||
|
||||
@DeleteMapping("/{spaceId}/categories/{categoryId}")
|
||||
suspend fun deleteCategory(@PathVariable categoryId: String, @PathVariable spaceId: String) {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
categoryService.deleteCategory(space, categoryId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
categoryService.deleteCategory(space, categoryId, user)
|
||||
}
|
||||
|
||||
@GetMapping("/{spaceId}/categories/tags")
|
||||
suspend fun getTags(@PathVariable spaceId: String): List<Tag> {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return spaceService.getTags(space)
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/{spaceId}/categories/tags")
|
||||
suspend fun createTags(@PathVariable spaceId: String, @RequestBody tag: Tag): Tag {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return spaceService.createTag(space, tag)
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("/{spaceId}/categories/tags/{tagId}")
|
||||
suspend fun deleteTags(@PathVariable spaceId: String, @PathVariable tagId: String) {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return spaceService.deleteTag(space, tagId)
|
||||
}
|
||||
|
||||
@@ -271,7 +290,8 @@ class SpaceController(
|
||||
|
||||
@GetMapping("/{spaceId}/recurrents")
|
||||
suspend fun getRecurrents(@PathVariable spaceId: String): List<Recurrent> {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return recurrentService.getRecurrents(spaceId)
|
||||
|
||||
}
|
||||
@@ -279,13 +299,15 @@ class SpaceController(
|
||||
|
||||
@GetMapping("/{spaceId}/recurrents/{id}")
|
||||
suspend fun getRecurrent(@PathVariable spaceId: String, @PathVariable id: String): Recurrent {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return recurrentService.getRecurrentById(space, id).awaitSingle()
|
||||
}
|
||||
|
||||
@PostMapping("/{spaceId}/recurrent")
|
||||
suspend fun createRecurrent(@PathVariable spaceId: String, @RequestBody recurrent: Recurrent): Recurrent {
|
||||
val space = spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
val space = spaceService.isValidRequest(spaceId, user)
|
||||
return recurrentService.createRecurrent(space, recurrent).awaitSingle()
|
||||
}
|
||||
|
||||
@@ -295,14 +317,16 @@ class SpaceController(
|
||||
@PathVariable id: String,
|
||||
@RequestBody recurrent: Recurrent
|
||||
): Recurrent {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
return recurrentService.editRecurrent(recurrent).awaitSingle()
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/{spaceId}/recurrent/{id}")
|
||||
suspend fun deleteRecurrent(@PathVariable spaceId: String, @PathVariable id: String) {
|
||||
spaceService.isValidRequest(spaceId)
|
||||
val user = authService.getSecurityUser()
|
||||
spaceService.isValidRequest(spaceId, user)
|
||||
recurrentService.deleteRecurrent(id).awaitSingle()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user