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> { override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
val token = exchange.request.headers.getFirst(HttpHeaders.AUTHORIZATION)?.removePrefix("Bearer ") 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() if (exchange.request.path.value() == "/api/auth/login" || exchange.request.path.value()
.startsWith("/api/actuator") .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.BudgetDTO
import space.luminic.budgerapp.models.Transaction import space.luminic.budgerapp.models.Transaction
import space.luminic.budgerapp.models.Warn import space.luminic.budgerapp.models.Warn
import space.luminic.budgerapp.services.BudgetService
import space.luminic.budgerapp.services.FinancialService
import java.time.LocalDate import java.time.LocalDate
@RestController @RestController
@RequestMapping("/budgets") @RequestMapping("/budgets")
class BudgetController( class BudgetController(
val budgetService: BudgetService val financialService: FinancialService
) { ) {
private val logger = LoggerFactory.getLogger(BudgetController::class.java) private val logger = LoggerFactory.getLogger(BudgetController::class.java)
@GetMapping @GetMapping
fun getBudgets(): Mono<MutableList<Budget>> { fun getBudgets(): Mono<MutableList<Budget>> {
return budgetService.getBudgets() return financialService.getBudgets()
} }
@GetMapping("/{id}") @GetMapping("/{id}")
fun getBudget(@PathVariable id: String): Mono<BudgetDTO> { fun getBudget(@PathVariable id: String): Mono<BudgetDTO> {
logger.info("here }") return financialService.getBudget(id)
return budgetService.getBudget(id)
} }
@GetMapping("/by-dates") @GetMapping("/by-dates")
fun getBudgetByDate(@RequestParam date: LocalDate): ResponseEntity<Any> { fun getBudgetByDate(@RequestParam date: LocalDate): ResponseEntity<Any> {
return ResponseEntity.ok(budgetService.getBudgetByDate(date)) return ResponseEntity.ok(financialService.getBudgetByDate(date))
} }
@GetMapping("/{id}/categories") @GetMapping("/{id}/categories")
fun getBudgetCategories(@PathVariable id: String): ResponseEntity<Any> { fun getBudgetCategories(@PathVariable id: String): ResponseEntity<Any> {
return ResponseEntity.ok(budgetService.getBudgetCategories(id)) return ResponseEntity.ok(financialService.getBudgetCategories(id))
} }
@GetMapping("/{id}/transactions") @GetMapping("/{id}/transactions")
fun getBudgetTransactions(@PathVariable id: String):Mono<Map<String,List<Transaction>>> { fun getBudgetTransactions(@PathVariable id: String):Mono<Map<String,List<Transaction>>> {
return budgetService.getBudgetTransactionsByType(id) return financialService.getBudgetTransactionsByType(id)
} }
@PostMapping("/") @PostMapping("/")
fun createBudget(@RequestBody budgetCreationDTO: BudgetCreationDTO): Mono<Budget> { fun createBudget(@RequestBody budgetCreationDTO: BudgetCreationDTO): Mono<Budget> {
return budgetService.createBudget( return financialService.createBudget(
budgetCreationDTO.budget, budgetCreationDTO.budget,
budgetCreationDTO.createRecurrent budgetCreationDTO.createRecurrent
) )
@@ -66,7 +66,7 @@ class BudgetController(
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
fun deleteBudget(@PathVariable id: String): Mono<Void> { fun deleteBudget(@PathVariable id: String): Mono<Void> {
return budgetService.deleteBudget(id) return financialService.deleteBudget(id)
} }
@PostMapping("/{budgetId}/categories/{catId}/limit") @PostMapping("/{budgetId}/categories/{catId}/limit")
@@ -76,7 +76,7 @@ class BudgetController(
@RequestBody limit: LimitValue, @RequestBody limit: LimitValue,
): ResponseEntity<Any> { ): ResponseEntity<Any> {
return try { return try {
ResponseEntity.ok(budgetService.setCategoryLimit(budgetId, catId, limit.limit)) ResponseEntity.ok(financialService.setCategoryLimit(budgetId, catId, limit.limit))
} catch (e: Exception) { } catch (e: Exception) {
ResponseEntity.badRequest().body(e.message) ResponseEntity.badRequest().body(e.message)
} }
@@ -86,14 +86,17 @@ class BudgetController(
@GetMapping("/{id}/warns") @GetMapping("/{id}/warns")
fun budgetWarns(@PathVariable id: String, @RequestParam hidden: Boolean? = null): Mono<List<Warn>> { 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") @PostMapping("/{id}/warns/{warnId}/hide")
fun setWarnHide(@PathVariable id: String, @PathVariable warnId: String): Mono<Warn> { 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( data class LimitValue(

View File

@@ -17,8 +17,8 @@ import org.springframework.web.client.HttpClientErrorException
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
import space.luminic.budgerapp.models.BudgetCategory import space.luminic.budgerapp.models.BudgetCategory
import space.luminic.budgerapp.models.Category import space.luminic.budgerapp.models.Category
import space.luminic.budgerapp.services.BudgetService
import space.luminic.budgerapp.services.CategoryService import space.luminic.budgerapp.services.CategoryService
import space.luminic.budgerapp.services.FinancialService
import java.time.LocalDate import java.time.LocalDate
@@ -26,7 +26,7 @@ import java.time.LocalDate
@RequestMapping("/categories") @RequestMapping("/categories")
class CategoriesController( class CategoriesController(
private val categoryService: CategoryService, 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 dateFrom = LocalDate.parse("2025-01-10")
var dateTo = LocalDate.parse("2025-02-09") var dateTo = LocalDate.parse("2025-02-09")
return categoryService.getCategoryTransactionPipeline(dateFrom, dateTo) return financialService.getCategoryTransactionPipeline(dateFrom, dateTo)
} }
@GetMapping("/by-month") @GetMapping("/by-month")
fun getCategoriesSumsByMonths(): Mono<List<Document>> { 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") @GetMapping("/by-month2")
fun getCategoriesSumsByMonthsV2(): Mono<List<Document>> { 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 org.springframework.web.client.HttpClientErrorException
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
import space.luminic.budgerapp.models.Transaction 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 @RestController
@RequestMapping("/transactions") @RequestMapping("/transactions")
class TransactionController(private val transactionService: TransactionService) { class TransactionController(private val financialService: FinancialService) {
@GetMapping @GetMapping
@@ -34,7 +35,7 @@ class TransactionController(private val transactionService: TransactionService)
): ResponseEntity<Any> { ): ResponseEntity<Any> {
try { try {
return ResponseEntity.ok( return ResponseEntity.ok(
transactionService.getTransactions( financialService.getTransactions(
transactionType = transactionType, transactionType = transactionType,
categoryType = categoryType, categoryType = categoryType,
userId = userId, userId = userId,
@@ -52,7 +53,7 @@ class TransactionController(private val transactionService: TransactionService)
@GetMapping("/{id}") @GetMapping("/{id}")
fun getTransaction(@PathVariable id: String): ResponseEntity<Any> { fun getTransaction(@PathVariable id: String): ResponseEntity<Any> {
try { try {
return ResponseEntity.ok(transactionService.getTransactionById(id)) return ResponseEntity.ok(financialService.getTransactionById(id))
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR) return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR)
@@ -62,7 +63,7 @@ class TransactionController(private val transactionService: TransactionService)
@PostMapping @PostMapping
fun createTransaction(@RequestBody transaction: Transaction): ResponseEntity<Any> { fun createTransaction(@RequestBody transaction: Transaction): ResponseEntity<Any> {
try { try {
return ResponseEntity.ok(transactionService.createTransaction(transaction)) return ResponseEntity.ok(financialService.createTransaction(transaction))
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR) return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR)
@@ -73,7 +74,7 @@ class TransactionController(private val transactionService: TransactionService)
@PutMapping("/{id}") @PutMapping("/{id}")
fun editTransaction(@PathVariable id: String, @RequestBody transaction: Transaction): ResponseEntity<Any> { fun editTransaction(@PathVariable id: String, @RequestBody transaction: Transaction): ResponseEntity<Any> {
try { try {
return ResponseEntity.ok(transactionService.editTransaction(transaction)) return ResponseEntity.ok(financialService.editTransaction(transaction))
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR) return ResponseEntity(e.message, HttpStatus.INTERNAL_SERVER_ERROR)
@@ -83,32 +84,30 @@ class TransactionController(private val transactionService: TransactionService)
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
fun deleteTransaction(@PathVariable id: String): Mono<Void> { fun deleteTransaction(@PathVariable id: String): Mono<Void> {
return transactionService.deleteTransaction(id) return financialService.deleteTransaction(id)
} }
@GetMapping("/{id}/child") @GetMapping("/{id}/child")
fun getChildTransactions(@PathVariable id: String): ResponseEntity<Any> { fun getChildTransactions(@PathVariable id: String): ResponseEntity<Any> {
return ResponseEntity.ok(transactionService.getChildTransaction(id)) return ResponseEntity.ok(financialService.getChildTransaction(id))
} }
@GetMapping("/avg-by-category") @GetMapping("/avg-by-category")
fun getAvgSums(): ResponseEntity<Any> { fun getAvgSums(): ResponseEntity<Any> {
return ResponseEntity.ok(transactionService.getAverageSpendingByCategory()) return ResponseEntity.ok(financialService.getAverageSpendingByCategory())
} }
@GetMapping("/types") @GetMapping("/types")
fun getTypes(): ResponseEntity<Any> { fun getTypes(): ResponseEntity<Any> {
return try { return try {
ResponseEntity.ok(transactionService.getTransactionTypes()) ResponseEntity.ok(financialService.getTransactionTypes())
} catch (e: Exception) { } catch (e: Exception) {
ResponseEntity(HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR), HttpStatus.INTERNAL_SERVER_ERROR) 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 plannedExpenses: MutableList<Transaction>? = null,
var plannedIncomes: MutableList<Transaction>? = null, var plannedIncomes: MutableList<Transaction>? = null,
var categories: MutableList<BudgetCategory> = mutableListOf(), var categories: MutableList<BudgetCategory> = mutableListOf(),
var incomeCategories: MutableList<BudgetCategory> = mutableListOf(),
var transactions: MutableList<Transaction>? = null, var transactions: MutableList<Transaction>? = null,
) )
@@ -30,6 +31,7 @@ data class Budget(
var dateTo: LocalDate, var dateTo: LocalDate,
val createdAt: LocalDateTime = LocalDateTime.now(), val createdAt: LocalDateTime = LocalDateTime.now(),
var categories: MutableList<BudgetCategory> = mutableListOf(), var categories: MutableList<BudgetCategory> = mutableListOf(),
var incomeCategories: MutableList<BudgetCategory> = mutableListOf(),
) )
data class BudgetCategory( data class BudgetCategory(

View File

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