File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Sources/Grodt/Controllers Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff 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
3749extension InvestmentDetailDTO : Content { }
50+ extension InvestmentDTO : Content { }
You can’t perform that action at this time.
0 commit comments