Skip to content

Commit 8a0ea48

Browse files
committed
Add endpoint for all investments
1 parent 9d6ec38 commit 8a0ea48

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Sources/Grodt/Controllers/InvestmentController.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@ struct InvestmentController: RouteCollection {
1313

1414
func boot(routes: Vapor.RoutesBuilder) throws {
1515
let investments = routes.grouped("investments")
16+
investments.get(use: allInvestments)
1617

1718
investments.group(":ticker") { investment in
1819
investment.get(use: invesetmentDetail)
1920
}
2021
}
2122

23+
func allInvestments(req: Request) async throws -> [InvestmentDTO] {
24+
guard let userID = req.auth.get(User.self)?.id else {
25+
throw Abort(.badRequest)
26+
}
27+
28+
let transactions = try await portfolioRepository.allPortfolios(for: userID)
29+
.flatMap { $0.transactions }
30+
31+
return try await dataMapper.investments(from: transactions)
32+
}
33+
2234
func invesetmentDetail(req: Request) async throws -> InvestmentDetailDTO {
2335
let ticker: String = try req.requiredParameter(named: "ticker")
2436

@@ -35,3 +47,4 @@ struct InvestmentController: RouteCollection {
3547
}
3648

3749
extension InvestmentDetailDTO: Content { }
50+
extension InvestmentDTO: Content { }

0 commit comments

Comments
 (0)