Skip to content

Commit 9ce899d

Browse files
committed
Touchups
1 parent feafdd6 commit 9ce899d

19 files changed

+146
-267
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
import Vapor
22

33
func migrations(_ app: Application) throws {
4-
// 1) New tables
54
app.migrations.add(Brokerage.Migration())
65
app.migrations.add(BrokerageAccount.Migration())
76

8-
// 2) Add nullable FK to transactions
9-
app.migrations.add(Transaction.Migration_AddBrokerageAccountID())
10-
11-
// 4) Create historical perf tables
127
app.migrations.add(HistoricalPortfolioPerformanceDaily.Migration())
138
app.migrations.add(HistoricalBrokerageAccountPerformanceDaily.Migration())
149
app.migrations.add(HistoricalBrokeragePerformanceDaily.Migration())
15-
16-
// 5) Drop platform/account and make FK required
17-
app.migrations.add(Transaction.Migration_DropPlatformAccountAndMakeBARequired())
1810

1911
app.migrations.add(User.Migration(preconfigured: app.config.preconfiguredUser, logger: app.logger))
2012
app.migrations.add(UserToken.Migration())
2113
app.migrations.add(Portfolio.Migration())
22-
// app.migrations.add(Transaction.Migration())
14+
15+
app.migrations.add(Transaction.Migration())
16+
app.migrations.add(Transaction.Migration_AddBrokerageAccountID())
17+
if app.environment != .testing {
18+
app.migrations.add(Transaction.Migration_DropPlatformAccountAndMakeBARequired())
19+
}
20+
2321
app.migrations.add(Currency.Migration())
2422
app.migrations.add(Ticker.Migration())
2523
app.migrations.add(Quote.Migration())
2624
app.migrations.add(HistoricalQuote.Migration())
2725

28-
// 6) Drop old portfolio performance
2926
app.migrations.add(DropOldHistoricalPortfolioPerformance())
3027
}

Sources/Grodt/Application/routes.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func routes(_ app: Application) async throws {
88
let currencyDTOMapper = CurrencyDTOMapper()
99
let tickerDTOMapper = TickerDTOMapper()
1010
let loginResponseDTOMapper = LoginResponseDTOMapper()
11-
let transactionDTOMapper = TransactionDTOMapper(currencyDTOMapper: currencyDTOMapper)
11+
let transactionDTOMapper = TransactionDTOMapper(currencyDTOMapper: currencyDTOMapper, database: app.db)
1212
let tickerRepository = PostgresTickerRepository(database: app.db)
1313
let livePriceService = LivePriceService(alphavantage: alphavantage)
1414
let quoteCache = PostgresQuoteRepository(database: app.db)
@@ -90,7 +90,8 @@ func routes(_ app: Application) async throws {
9090
try protected.register(collection: BrokerageController(brokerageRepository: brokerageRepository,
9191
dtoMapper: BrokerageDTOMapper(brokerageRepository: brokerageRepository,
9292
accountDTOMapper: BrokerageAccountDTOMapper(brokerageAccountRepository: brokerageAccountRepository,
93-
currencyMapper: currencyDTOMapper)),
93+
currencyMapper: currencyDTOMapper, database: app.db),
94+
database: app.db),
9495
accounts: brokerageAccountRepository,
9596
currencyMapper: currencyDTOMapper,
9697
performanceRepository: brokerageDailyPerformanceRepository,
@@ -118,7 +119,7 @@ func routes(_ app: Application) async throws {
118119
)
119120
app.queues.schedule(nightlyUpdaterJob)
120121
.daily()
121-
.at(13, 59)
122+
.at(3, 0)
122123

123124
app.queues.add(LoggingJobEventDelegate(logger: app.logger))
124125

Sources/Grodt/DTOs/BrokerageDTO.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ struct BrokerageAccountDTO: Codable {
1717
}
1818

1919
struct PerformanceTotalsDTO: Codable {
20-
let value: Decimal
21-
let moneyIn: Decimal
20+
private let value: Decimal
21+
private let moneyIn: Decimal
22+
23+
init(value: Decimal, moneyIn: Decimal) {
24+
self.value = value
25+
self.moneyIn = moneyIn
26+
}
27+
28+
init() {
29+
self.init(value: 0, moneyIn: 0)
30+
}
2231
}
2332

2433
struct PerformancePointDTO: Codable {

Sources/Grodt/DTOs/CreateTransactionRequestDTO.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import Foundation
33
struct CreateTransactionRequestDTO: Decodable {
44
let portfolio: String
55
let brokerageAccountID: String?
6-
let platform: String
7-
let account: String?
86
let purchaseDate: Date
97
let ticker: String
108
let currency: String
@@ -20,8 +18,6 @@ struct CreateTransactionRequestDTO: Decodable {
2018
let container = try decoder.container(keyedBy: CodingKeys.self)
2119
portfolio = try container.decode(String.self, forKey: .portfolio)
2220
brokerageAccountID = try container.decodeIfPresent(String.self, forKey: .brokerageAccountID)
23-
platform = try container.decode(String.self, forKey: .platform)
24-
account = try container.decodeIfPresent(String.self, forKey: .account)
2521
ticker = try container.decode(String.self, forKey: .ticker)
2622
currency = try container.decode(String.self, forKey: .currency)
2723
fees = try container.decode(Decimal.self, forKey: .fees)

Sources/Grodt/DTOs/DTOMappers/InvestmentDTOMapper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class InvestmentDTOMapper {
5858
}
5959
}
6060

61-
func investmentDetail(from transactions: [Transaction])async throws -> InvestmentDetailDTO {
61+
func investmentDetail(from transactions: [Transaction]) async throws -> InvestmentDetailDTO {
6262
let investmentDTO = try await investments(from: transactions).first!
63-
let transactions = transactions.compactMap { transactionDTOMapper.transaction(from: $0) }
63+
let transactions = try await transactions.asyncCompactMap { try await transactionDTOMapper.transaction(from: $0) }
6464
return InvestmentDetailDTO(name: investmentDTO.name,
6565
shortName: investmentDTO.shortName,
6666
avgBuyPrice: investmentDTO.avgBuyPrice,

Sources/Grodt/DTOs/DTOMappers/PerformancePointDTOMapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ struct PerformancePointDTOMapper {
44
value: enity.value,
55
moneyIn: enity.moneyIn)
66
}
7-
}
7+
}

Sources/Grodt/DTOs/DTOMappers/PortfolioDTOMapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PortfolioDTOMapper {
1717
func portfolio(from portfolio: Portfolio) async throws -> PortfolioDTO {
1818

1919
let investments = try await investmentDTOMapper.investments(from: portfolio.transactions)
20-
let transactions = portfolio.transactions.map { transactionDTOMapper.transaction(from: $0) }
20+
let transactions = try await portfolio.transactions.asyncMap { try await transactionDTOMapper.transaction(from: $0) }
2121
return try await PortfolioDTO(id: portfolio.id?.uuidString ?? "",
2222
name: portfolio.name,
2323
currency: currencyDTOMapper.currency(from: portfolio.currency),

Sources/Grodt/DTOs/DTOMappers/TransactionDTOMapper.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

Sources/Grodt/DTOs/TransactionDTO.swift

Lines changed: 0 additions & 60 deletions
This file was deleted.

Sources/Grodt/Endpoints/TransactionsController.swift

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)