new updated

This commit is contained in:
xds
2025-02-11 13:46:50 +03:00
parent 510f527bec
commit c1d7e42a29
11 changed files with 3014 additions and 1220 deletions

View File

@@ -26,7 +26,6 @@ class BearerTokenFilter(private val authService: AuthService) : SecurityContextS
override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
val token = exchange.request.headers.getFirst(HttpHeaders.AUTHORIZATION)?.removePrefix("Bearer ")
logger.info("here ${exchange.request.path.value()}")
if (exchange.request.path.value() == "/api/auth/login" || exchange.request.path.value()
.startsWith("/api/actuator")
) {

View File

@@ -16,49 +16,49 @@ 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.FinancialService
import java.time.LocalDate
@RestController
@RequestMapping("/budgets")
class BudgetController(
val budgetService: BudgetService
val financialService: FinancialService
) {
private val logger = LoggerFactory.getLogger(BudgetController::class.java)
@GetMapping
fun getBudgets(): Mono<MutableList<Budget>> {
return budgetService.getBudgets()
return financialService.getBudgets()
}
@GetMapping("/{id}")
fun getBudget(@PathVariable id: String): Mono<BudgetDTO> {
logger.info("here }")
return budgetService.getBudget(id)
return financialService.getBudget(id)
}
@GetMapping("/by-dates")
fun getBudgetByDate(@RequestParam date: LocalDate): ResponseEntity<Any> {
return ResponseEntity.ok(budgetService.getBudgetByDate(date))
return ResponseEntity.ok(financialService.getBudgetByDate(date))
}
@GetMapping("/{id}/categories")
fun getBudgetCategories(@PathVariable id: String): ResponseEntity<Any> {
return ResponseEntity.ok(budgetService.getBudgetCategories(id))
return ResponseEntity.ok(financialService.getBudgetCategories(id))
}
@GetMapping("/{id}/transactions")
fun getBudgetTransactions(@PathVariable id: String):Mono<Map<String,List<Transaction>>> {
return budgetService.getBudgetTransactionsByType(id)
return financialService.getBudgetTransactionsByType(id)
}
@PostMapping("/")
fun createBudget(@RequestBody budgetCreationDTO: BudgetCreationDTO): Mono<Budget> {
return budgetService.createBudget(
return financialService.createBudget(
budgetCreationDTO.budget,
budgetCreationDTO.createRecurrent
)
@@ -66,7 +66,7 @@ class BudgetController(
@DeleteMapping("/{id}")
fun deleteBudget(@PathVariable id: String): Mono<Void> {
return budgetService.deleteBudget(id)
return financialService.deleteBudget(id)
}
@PostMapping("/{budgetId}/categories/{catId}/limit")
@@ -76,7 +76,7 @@ class BudgetController(
@RequestBody limit: LimitValue,
): ResponseEntity<Any> {
return try {
ResponseEntity.ok(budgetService.setCategoryLimit(budgetId, catId, limit.limit))
ResponseEntity.ok(financialService.setCategoryLimit(budgetId, catId, limit.limit))
} catch (e: Exception) {
ResponseEntity.badRequest().body(e.message)
}
@@ -86,14 +86,17 @@ class BudgetController(
@GetMapping("/{id}/warns")
fun budgetWarns(@PathVariable id: String, @RequestParam hidden: Boolean? = null): Mono<List<Warn>> {
return budgetService.getWarns(id, hidden)
return financialService.getWarns(id, hidden)
}
@PostMapping("/{id}/warns/{warnId}/hide")
fun setWarnHide(@PathVariable id: String, @PathVariable warnId: String): Mono<Warn> {
return budgetService.hideWarn( warnId)
return financialService.hideWarn( warnId)
}
@GetMapping("/regencats")
fun regenCats(): Mono<Void>{
return financialService.regenCats()
}
data class LimitValue(

View File

@@ -17,8 +17,8 @@ import org.springframework.web.client.HttpClientErrorException
import reactor.core.publisher.Mono
import space.luminic.budgerapp.models.BudgetCategory
import space.luminic.budgerapp.models.Category
import space.luminic.budgerapp.services.BudgetService
import space.luminic.budgerapp.services.CategoryService
import space.luminic.budgerapp.services.FinancialService
import java.time.LocalDate
@@ -26,7 +26,7 @@ import java.time.LocalDate
@RequestMapping("/categories")
class CategoriesController(
private val categoryService: CategoryService,
private val budgetService: BudgetService
private val financialService: FinancialService
) {
@@ -72,19 +72,19 @@ class CategoriesController(
var dateFrom = LocalDate.parse("2025-01-10")
var dateTo = LocalDate.parse("2025-02-09")
return categoryService.getCategoryTransactionPipeline(dateFrom, dateTo)
return financialService.getCategoryTransactionPipeline(dateFrom, dateTo)
}
@GetMapping("/by-month")
fun getCategoriesSumsByMonths(): Mono<List<Document>> {
return categoryService.getCategorySumsPipeline(LocalDate.of(2024, 8, 1), LocalDate.of(2025, 1, 12))
return financialService.getCategorySumsPipeline(LocalDate.of(2024, 8, 1), LocalDate.of(2025, 1, 12))
}
@GetMapping("/by-month2")
fun getCategoriesSumsByMonthsV2(): Mono<List<Document>> {
return categoryService.getCategorySummaries(LocalDate.now().minusMonths(6))
return financialService.getCategorySummaries(LocalDate.now().minusMonths(6))
}

View File

@@ -14,13 +14,14 @@ import org.springframework.web.bind.annotation.RestController
import org.springframework.web.client.HttpClientErrorException
import reactor.core.publisher.Mono
import space.luminic.budgerapp.models.Transaction
import space.luminic.budgerapp.services.BudgetService
import space.luminic.budgerapp.services.TransactionService
import space.luminic.budgerapp.services.FinancialService
@RestController
@RequestMapping("/transactions")
class TransactionController(private val transactionService: TransactionService) {
class TransactionController(private val financialService: FinancialService) {
@GetMapping
@@ -34,7 +35,7 @@ class TransactionController(private val transactionService: TransactionService)
): ResponseEntity<Any> {
try {
return ResponseEntity.ok(
transactionService.getTransactions(
financialService.getTransactions(
transactionType = transactionType,
categoryType = categoryType,
userId = userId,
@@ -52,7 +53,7 @@ class TransactionController(private val transactionService: TransactionService)
@GetMapping("/{id}")
fun getTransaction(@PathVariable id: String): ResponseEntity<Any> {
try {
return ResponseEntity.ok(transactionService.getTransactionById(id))
return ResponseEntity.ok(financialService.getTransactionById(id))
} catch (e: Exception) {
e.printStackTrace()
return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR)
@@ -62,7 +63,7 @@ class TransactionController(private val transactionService: TransactionService)
@PostMapping
fun createTransaction(@RequestBody transaction: Transaction): ResponseEntity<Any> {
try {
return ResponseEntity.ok(transactionService.createTransaction(transaction))
return ResponseEntity.ok(financialService.createTransaction(transaction))
} catch (e: Exception) {
e.printStackTrace()
return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR)
@@ -73,7 +74,7 @@ class TransactionController(private val transactionService: TransactionService)
@PutMapping("/{id}")
fun editTransaction(@PathVariable id: String, @RequestBody transaction: Transaction): ResponseEntity<Any> {
try {
return ResponseEntity.ok(transactionService.editTransaction(transaction))
return ResponseEntity.ok(financialService.editTransaction(transaction))
} catch (e: Exception) {
e.printStackTrace()
return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR)
@@ -83,32 +84,30 @@ class TransactionController(private val transactionService: TransactionService)
@DeleteMapping("/{id}")
fun deleteTransaction(@PathVariable id: String): Mono<Void> {
return transactionService.deleteTransaction(id)
return financialService.deleteTransaction(id)
}
@GetMapping("/{id}/child")
fun getChildTransactions(@PathVariable id: String): ResponseEntity<Any> {
return ResponseEntity.ok(transactionService.getChildTransaction(id))
return ResponseEntity.ok(financialService.getChildTransaction(id))
}
@GetMapping("/avg-by-category")
fun getAvgSums(): ResponseEntity<Any> {
return ResponseEntity.ok(transactionService.getAverageSpendingByCategory())
return ResponseEntity.ok(financialService.getAverageSpendingByCategory())
}
@GetMapping("/types")
fun getTypes(): ResponseEntity<Any> {
return try {
ResponseEntity.ok(transactionService.getTransactionTypes())
ResponseEntity.ok(financialService.getTransactionTypes())
} catch (e: Exception) {
ResponseEntity(HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR), HttpStatus.INTERNAL_SERVER_ERROR)
}
}
}

View File

@@ -17,6 +17,7 @@ data class BudgetDTO(
var plannedExpenses: MutableList<Transaction>? = null,
var plannedIncomes: MutableList<Transaction>? = null,
var categories: MutableList<BudgetCategory> = mutableListOf(),
var incomeCategories: MutableList<BudgetCategory> = mutableListOf(),
var transactions: MutableList<Transaction>? = null,
)
@@ -30,6 +31,7 @@ data class Budget(
var dateTo: LocalDate,
val createdAt: LocalDateTime = LocalDateTime.now(),
var categories: MutableList<BudgetCategory> = mutableListOf(),
var incomeCategories: MutableList<BudgetCategory> = mutableListOf(),
)
data class BudgetCategory(

View File

@@ -6,6 +6,7 @@ import org.bson.types.ObjectId
import org.slf4j.LoggerFactory
import org.springframework.cache.annotation.CacheEvict
import org.springframework.cache.annotation.Cacheable
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Sort
import org.springframework.data.domain.Sort.Direction
import org.springframework.data.mongodb.core.ReactiveMongoTemplate
@@ -37,8 +38,9 @@ import java.util.Date
@Service
class CategoryService(
private val categoryRepo: CategoryRepo,
private val transactionService: TransactionService,
private val mongoTemplate: ReactiveMongoTemplate
private val financialService: FinancialService,
private val mongoTemplate: ReactiveMongoTemplate,
private val eventPublisher: ApplicationEventPublisher
) {
private val logger = LoggerFactory.getLogger(javaClass)
@@ -115,7 +117,7 @@ class CategoryService(
return categoryRepo.findById(categoryId).switchIfEmpty(
Mono.error(IllegalArgumentException("Category with id: $categoryId not found"))
).flatMap {
transactionService.getTransactions(categoryId = categoryId)
financialService.getTransactions(categoryId = categoryId)
.flatMapMany { transactions ->
categoryRepo.findByName("Другое").switchIfEmpty(
categoryRepo.save(
@@ -126,10 +128,10 @@ class CategoryService(
icon = "🚮"
)
)
).flatMapMany { Category ->
).flatMapMany { category ->
Flux.fromIterable(transactions).flatMap { transaction ->
transaction.category = Category // Присваиваем конкретный объект категории
transactionService.editTransaction(transaction) // Сохраняем изменения
transaction.category = category // Присваиваем конкретный объект категории
financialService.editTransaction(transaction) // Сохраняем изменения
}
}
}
@@ -140,7 +142,6 @@ class CategoryService(
fun getBudgetCategories(dateFrom: LocalDate, dateTo: LocalDate): Mono<Map<String, Map<String, Double>>> {
logger.info("here cat starts")
val pipeline = listOf(
Document(
"\$lookup",
@@ -265,7 +266,6 @@ class CategoryService(
)
id to values
}
logger.info("here cat ends")
Mono.just(categories)
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,12 +5,12 @@ spring.application.name=budger-app
spring.data.mongodb.uri=mongodb://budger-app:BA1q2w3e4r!@luminic.space:27017/budger-app?authSource=admin&minPoolSize=10&maxPoolSize=100
logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.data = DEBUG
#logging.level.org.springframework.web=DEBUG
#logging.level.org.springframework.data = DEBUG
logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=DEBUG
logging.level.org.springframework.security = DEBUG
#logging.level.org.springframework.security = DEBUG
logging.level.org.springframework.data.mongodb.code = DEBUG
logging.level.org.springframework.web.reactive=DEBUG
#logging.level.org.springframework.web.reactive=DEBUG
#management.endpoints.web.exposure.include=*
#management.endpoint.metrics.access=read_only

View File

@@ -9,12 +9,12 @@ spring.main.web-application-type=reactive
logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.data = DEBUG
logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=DEBUG
logging.level.org.springframework.security = DEBUG
logging.level.org.springframework.data.mongodb.code = DEBUG
logging.level.org.springframework.web.reactive=DEBUG
logging.level.org.springframework.web=INFO
logging.level.org.springframework.data = INFO
logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=INFO
logging.level.org.springframework.security = INFO
logging.level.org.springframework.data.mongodb.code = INFO
logging.level.org.springframework.web.reactive=INFO
server.compression.enabled=true
server.compression.mime-types=application/json