ソースを参照

Adding pagination to GET request

v2_uploadImages
Bill Ryckman 2年前
コミット
46d69a83dc
1個のファイルの変更14行の追加2行の削除
  1. +14
    -2
      Sources/App/Controllers/FuelEntryV2Controller.swift

+ 14
- 2
Sources/App/Controllers/FuelEntryV2Controller.swift ファイルの表示

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

import Vapor
import FluentKit

struct FuelEntryV2Controller: RouteCollection {
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] {
@@ -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
}
}






読み込み中…
キャンセル
保存