File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
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 { }
Original file line number Diff line number Diff line change @@ -53,7 +53,9 @@ class InvestmentDTOMapper {
5353 )
5454 }
5555
56- return investments
56+ return investments. sorted { lft, rgh in
57+ lft. totalReturn > rgh. totalReturn
58+ }
5759 }
5860
5961 func investmentDetail( from transactions: [ Transaction ] ) async throws -> InvestmentDetailDTO {
You can’t perform that action at this time.
0 commit comments