Implemented phase 5 for the POC prototype in the Website service.
This commit is contained in:
1 parent
89a7a7b8e5
commit
31d2d98d49
46 files changed
+4039
-162
No files matched your search
@@ -20,6 +20,9 @@ public struct TradeController<Context: RequestContext> {
|
||||
/// The repository listings and shops are read through.
|
||||
private let catalogue: CatalogueRepository
|
||||
|
||||
/// Told whenever the controller changes what is for sale, so pages cached elsewhere can catch up.
|
||||
private let onCatalogueChange: @Sendable () async -> Void
|
||||
|
||||
/// The store the signed-in account is read from.
|
||||
private let sessions: SessionStore
|
||||
|
||||
@@ -35,14 +38,17 @@ public struct TradeController<Context: RequestContext> {
|
||||
/// - sessions: the store the signed-in account is read from.
|
||||
/// - assetVersion: the version token appended to the pages' asset URLs, or `nil` (the default) to leave them unversioned.
|
||||
/// - analytics: the analytics tracker the pages embed, or `nil` (the default) to omit it.
|
||||
/// - onCatalogueChange: told whenever the controller changes what is for sale; does nothing by default.
|
||||
public init(
|
||||
trade: TradeRepository,
|
||||
catalogue: CatalogueRepository,
|
||||
sessions: SessionStore,
|
||||
assetVersion: String? = nil,
|
||||
analytics: Analytics? = nil
|
||||
analytics: Analytics? = nil,
|
||||
onCatalogueChange: @escaping @Sendable () async -> Void = {}
|
||||
) {
|
||||
self.analytics = analytics
|
||||
self.onCatalogueChange = onCatalogueChange
|
||||
self.assetVersion = assetVersion
|
||||
self.catalogue = catalogue
|
||||
self.sessions = sessions
|
||||
@@ -95,7 +101,11 @@ private extension TradeController {
|
||||
}
|
||||
|
||||
do {
|
||||
return .redirect(to: .Route.sale(try await trade.buy(listing: slug, buyer: user)), type: .normal)
|
||||
let number = try await trade.buy(listing: slug, buyer: user)
|
||||
|
||||
await onCatalogueChange()
|
||||
|
||||
return .redirect(to: .Route.sale(number), type: .normal)
|
||||
} catch let error as TradeError {
|
||||
return try await sheet(.buy, slug: slug, error: error, viewer: viewer, request: request, context: context)
|
||||
}
|
||||
@@ -409,6 +419,10 @@ private extension TradeController {
|
||||
let form = try await URLEncodedFormDecoder().decode(AnswerForm.self, from: request, context: context)
|
||||
let number = try? await trade.respond(toOffer: id, accepting: form.answer == "accept", by: user)
|
||||
|
||||
if number.flatMap(\.self) != nil {
|
||||
await onCatalogueChange()
|
||||
}
|
||||
|
||||
return .redirect(
|
||||
to: number.flatMap(\.self).map(String.Route.sale) ?? .Route.safeReturn(form.return),
|
||||
type: .normal
|
||||
|
||||
Reference in new issue
Block a user