SPB Git

Repository Public

Endpoints.swift 4.1 KB 91 lines swift

1//2//  Fabri-Ka iOS v23//  File: FabriKa/Core/API/Endpoints.swift4//  Description: un appel par endpoint du contrat (API.md de Fabri-Ka v2).5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//910import Foundation1112extension APIClient {13    /// Identité et règles du service ; gardées pour l'affichage hors ligne.14    @discardableResult15    func version() async throws -> ServiceInfo {16        let v: ServiceInfo = try await get("api/version")17        ServiceInfo.store(v)18        return v19    }2021    func publicRules() async throws -> Fetched<PublicRules> { try await fetch("api/public") }22    func sources() async throws -> Fetched<Sources> { try await fetch("api/sources") }23    func discover() async throws -> Fetched<Discover> { try await fetch("api/discover") }24    func categories() async throws -> Fetched<Categories> { try await fetch("api/categories") }2526    func search(_ f: SearchFilters, page: Int = 1, pageSize: Int = 24, facets: Bool = false, points: Bool = false) async throws -> Fetched<SearchPage> {27        try await fetch("api/search", query: f.query(page: page, pageSize: pageSize, facets: facets, points: points))28    }2930    func count(_ f: SearchFilters) async throws -> CountResult {31        var q = f.query()32        q["page_size"] = nil; q["sort"] = nil33        return try await get("api/count", query: q)34    }3536    func facets(_ f: SearchFilters) async throws -> Facets {37        var q = f.query()38        q["page_size"] = nil; q["sort"] = nil39        return try await get("api/facets", query: q)40    }4142    func suggest(_ q: String, limit: Int = 6) async throws -> Suggestions {43        try await get("api/suggest", query: ["q": q, "limit": String(limit)])44    }4546    /// Fiche d'un produit. Un produit regroupé sous un autre de même nom est suivi une fois vers son représentant.47    func product(_ uid: String) async throws -> Fetched<ProductDetail> {48        do {49            return try await fetch("api/products/" + APIClient.segment(uid))50        } catch APIError.moved(let canonical) where canonical != uid {51            return try await fetch("api/products/" + APIClient.segment(canonical))52        }53    }5455    /// Cartes par lot (100 identifiants au plus) : relecture des favoris en un seul appel.56    func products(ids: [String]) async throws -> ProductBatch {57        try await get("api/products", query: ["ids": ids.prefix(100).joined(separator: ",")])58    }5960    func stores(_ f: StoreFilters, page: Int = 1, pageSize: Int = 30) async throws -> Fetched<StoresPage> {61        try await fetch("api/boutiques", query: f.query(page: page, pageSize: pageSize))62    }6364    /// Tous les points de carte de l'annuaire (un par boutique positionnée).65    func storePoints(_ f: StoreFilters = StoreFilters()) async throws -> Fetched<StoresPage> {66        try await fetch("api/boutiques", query: f.query(page: 1, pageSize: 1, points: true))67    }6869    /// Fiche d'une boutique et première page de son catalogue (filtrable comme la recherche).70    func store(_ id: String, catalogue f: SearchFilters = SearchFilters(), pageSize: Int = 24) async throws -> Fetched<StoreDetail> {71        var q = f.query(pageSize: pageSize)72        q["store"] = nil73        return try await fetch("api/boutiques/" + APIClient.segment(id), query: q)74    }7576    func regions() async throws -> Fetched<Regions> { try await fetch("api/regions") }77    func region(_ slug: String) async throws -> Fetched<Place> { try await fetch("api/regions/" + APIClient.segment(slug)) }78    func city(_ slug: String) async throws -> Fetched<Place> { try await fetch("api/villes/" + APIClient.segment(slug)) }7980    /// Trouvaille au hasard ; sans graine, le service en tire une et la rend.81    func random(kind: String, seed: Int? = nil) async throws -> RandomFind {82        try await get("api/random", query: ["kind": kind, "seed": seed.map(String.init)])83    }8485    func inscriptionForm() async throws -> Fetched<InscriptionForm> { try await fetch("api/inscriptions/form") }8687    func submit(_ request: InscriptionRequest, honeypot: String) async throws -> InscriptionResponse {88        try await post("api/inscriptions", body: request.body(honeypot: honeypot))89    }90}91
Files main
Menu

Theme