feat: полноценное Pulse приложение с TabBar

- Auth: переключено на Pulse API (api.digital-home.site) вместо health
- TabBar: Главная, Задачи, Привычки, Здоровье, Финансы
- Models: TaskModels, HabitModels, FinanceModels, обновлённые AuthModels
- Services: APIService (Pulse API), HealthAPIService (health отдельно)
- Dashboard: обзор дня с задачами, привычками, readiness, балансом
- Tasks: список, фильтр, создание, выполнение, удаление
- Habits: список с прогресс-баром, отметка выполнения, стрики
- Health: бывший DashboardView, HealthKit sync через health API key
- Finance: баланс, список транзакций, добавление расхода/дохода
- Health данные через x-api-key вместо JWT токена health сервиса
This commit is contained in:
Cosmo
2026-03-25 11:49:52 +00:00
parent cf0e535639
commit c015824b36
23 changed files with 1090 additions and 202 deletions

View File

@@ -0,0 +1,82 @@
import SwiftUI
struct AddTransactionView: View {
@Binding var isPresented: Bool
@EnvironmentObject var authManager: AuthManager
let categories: [FinanceCategory]
let onAdded: () async -> Void
@State private var amount = ""
@State private var description = ""
@State private var type = "expense"
@State private var selectedCategoryId: Int? = nil
@State private var isLoading = false
var filteredCategories: [FinanceCategory] { categories.filter { $0.type == type } }
var body: some View {
NavigationView {
ZStack {
Color(hex: "0a0a1a").ignoresSafeArea()
VStack(spacing: 16) {
Picker("", selection: $type) {
Text("Расход").tag("expense")
Text("Доход").tag("income")
}
.pickerStyle(.segmented)
TextField("Сумма", text: $amount)
.keyboardType(.decimalPad)
.padding().background(Color.white.opacity(0.08)).cornerRadius(12).foregroundColor(.white)
TextField("Описание", text: $description)
.padding().background(Color.white.opacity(0.08)).cornerRadius(12).foregroundColor(.white)
if !filteredCategories.isEmpty {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 8) {
ForEach(filteredCategories) { cat in
Button(action: { selectedCategoryId = cat.id }) {
HStack(spacing: 4) {
Text(cat.icon ?? "").font(.caption)
Text(cat.name).font(.caption)
}
.padding(.horizontal, 12).padding(.vertical, 6)
.background(RoundedRectangle(cornerRadius: 20)
.fill(selectedCategoryId == cat.id ? Color(hex: "00d4aa").opacity(0.3) : Color.white.opacity(0.08)))
.foregroundColor(selectedCategoryId == cat.id ? Color(hex: "00d4aa") : .white)
}
}
}.padding(.horizontal)
}
}
Spacer()
}.padding()
}
.navigationTitle("Новая операция")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) { Button("Отмена") { isPresented = false } }
ToolbarItem(placement: .confirmationAction) {
Button("Добавить") {
guard let a = Double(amount.replacingOccurrences(of: ",", with: ".")) else { return }
isLoading = true
Task {
let req = CreateTransactionRequest(
amount: a,
categoryId: selectedCategoryId,
description: description.isEmpty ? nil : description,
type: type
)
try? await APIService.shared.createTransaction(token: authManager.token, request: req)
await onAdded()
await MainActor.run { isPresented = false }
}
}
.disabled(amount.isEmpty || isLoading)
}
}
.preferredColorScheme(.dark)
}
}
}

View File

@@ -0,0 +1,125 @@
import SwiftUI
struct FinanceView: View {
@EnvironmentObject var authManager: AuthManager
@State private var summary: FinanceSummary?
@State private var transactions: [FinanceTransaction] = []
@State private var categories: [FinanceCategory] = []
@State private var isLoading = true
@State private var showAddTransaction = false
var body: some View {
ZStack {
Color(hex: "0a0a1a").ignoresSafeArea()
VStack(spacing: 0) {
HStack {
Text("Финансы").font(.title.bold()).foregroundColor(.white)
Spacer()
Button(action: { showAddTransaction = true }) {
Image(systemName: "plus.circle.fill").font(.title2).foregroundColor(Color(hex: "00d4aa"))
}
}.padding()
if isLoading {
ProgressView().tint(Color(hex: "00d4aa")).padding(.top, 40)
Spacer()
} else {
ScrollView {
VStack(spacing: 16) {
// Summary card
if let s = summary {
FinanceSummaryCard(summary: s)
}
// Recent transactions
if !transactions.isEmpty {
VStack(alignment: .leading, spacing: 8) {
Text("Последние операции")
.font(.headline).foregroundColor(.white).padding(.horizontal)
ForEach(transactions.prefix(20)) { tx in
TransactionRowView(transaction: tx, categories: categories)
}
}
}
}
}
}
}
}
.sheet(isPresented: $showAddTransaction) {
AddTransactionView(isPresented: $showAddTransaction, categories: categories) { await loadData() }
}
.task { await loadData() }
.refreshable { await loadData() }
}
func loadData() async {
isLoading = true
async let s = APIService.shared.getFinanceSummary(token: authManager.token)
async let t = APIService.shared.getTransactions(token: authManager.token)
async let c = APIService.shared.getFinanceCategories(token: authManager.token)
summary = try? await s
transactions = (try? await t) ?? []
categories = (try? await c) ?? []
isLoading = false
}
}
// MARK: - FinanceSummaryCard
struct FinanceSummaryCard: View {
let summary: FinanceSummary
var body: some View {
VStack(spacing: 16) {
HStack(spacing: 20) {
VStack(spacing: 4) {
Text("Доходы").font(.caption).foregroundColor(Color(hex: "8888aa"))
Text("+\(Int(summary.totalIncome ?? 0))").font(.headline).foregroundColor(Color(hex: "00d4aa"))
}
Spacer()
VStack(spacing: 4) {
Text("Баланс").font(.subheadline).foregroundColor(Color(hex: "8888aa"))
Text("\(Int(summary.balance ?? 0))").font(.title2.bold()).foregroundColor(.white)
}
Spacer()
VStack(spacing: 4) {
Text("Расходы").font(.caption).foregroundColor(Color(hex: "8888aa"))
Text("-\(Int(summary.totalExpenses ?? 0))").font(.headline).foregroundColor(Color(hex: "ff4757"))
}
}
}
.padding(20)
.background(RoundedRectangle(cornerRadius: 20).fill(Color.white.opacity(0.05)))
.padding(.horizontal)
}
}
// MARK: - TransactionRowView
struct TransactionRowView: View {
let transaction: FinanceTransaction
let categories: [FinanceCategory]
var category: FinanceCategory? { categories.first { $0.id == transaction.categoryId } }
var isIncome: Bool { transaction.type == "income" }
var body: some View {
HStack {
Text(category?.icon ?? (isIncome ? "💰" : "💸")).font(.title2)
VStack(alignment: .leading, spacing: 2) {
Text(transaction.description ?? category?.name ?? "Операция")
.font(.callout).foregroundColor(.white)
Text(transaction.date ?? "").font(.caption).foregroundColor(Color(hex: "8888aa"))
}
Spacer()
Text("\(isIncome ? "+" : "-")\(Int(transaction.amount))")
.font(.callout.bold())
.foregroundColor(isIncome ? Color(hex: "00d4aa") : Color(hex: "ff4757"))
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.04)))
.padding(.horizontal)
.padding(.vertical, 2)
}
}