Explorar el Código

Adding pagination to GET request

v2_uploadImages
Bill Ryckman hace 2 años
padre
commit
46d69a83dc
Se han modificado 1 ficheros con 14 adiciones y 2 borrados
  1. +14
    -2
      Sources/App/Controllers/FuelEntryV2Controller.swift

+ 14
- 2
Sources/App/Controllers/FuelEntryV2Controller.swift Ver fichero

@@ -6,6 +6,7 @@
// //


import Vapor import Vapor
import FluentKit


struct FuelEntryV2Controller: RouteCollection { struct FuelEntryV2Controller: RouteCollection {
func boot(routes: RoutesBuilder) throws { func boot(routes: RoutesBuilder) throws {
@@ -19,8 +20,8 @@ struct FuelEntryV2Controller: RouteCollection {
} }
} }
func index(req: Request) async throws -> [FuelEntry] {
try await FuelEntry.query(on: req.db).all()
func index(req: Request) async throws -> Page<FuelEntry> {
try await FuelEntry.query(on: req.db).paginate(for: req)
} }
// func getAllEntriesWithImages(req: Request) async throws -> [FuelEntry] { // func getAllEntriesWithImages(req: Request) async throws -> [FuelEntry] {
@@ -109,6 +110,17 @@ struct FuelEntryV2Controller: RouteCollection {
// } // }
} }


struct PageRequest: Content {
var page: Int
var size: Int
// Add any other properties needed for pagination
init(page: Int, size: Int) {
self.page = page
self.size = size
}
}









Cargando…
Cancelar
Guardar