This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: code gen with latest ftl updates (#13)
- Loading branch information
1 parent
2f8fffc
commit 0e49c9d
Showing
15 changed files
with
326 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// ignore_for_file: unused_import | ||
library builtin; | ||
|
||
import 'dart:convert'; | ||
import 'dart:typed_data'; | ||
import 'ftl_client.dart'; | ||
|
||
|
||
class HttpRequest { | ||
String method; | ||
String path; | ||
Map<String, String> pathParameters; | ||
Map<String, List<String>> query; | ||
Map<String, List<String>> headers; | ||
Uint8List body; | ||
|
||
HttpRequest({ required this.method, required this.path, required this.pathParameters, required this.query, required this.headers, required this.body, }); | ||
|
||
Map<String, dynamic> toMap() { | ||
return { | ||
'method': ((dynamic v) => v)(method), | ||
'path': ((dynamic v) => v)(path), | ||
'pathParameters': ((dynamic v) => v.map((k, v) => MapEntry(k, v)).cast<String, String>())(pathParameters), | ||
'query': ((dynamic v) => v.map((k, v) => MapEntry(k, v.map((v) => v).cast<String>().toList())).cast<String, List<String>>())(query), | ||
'headers': ((dynamic v) => v.map((k, v) => MapEntry(k, v.map((v) => v).cast<String>().toList())).cast<String, List<String>>())(headers), | ||
'body': ((dynamic v) => v)(body), | ||
}; | ||
} | ||
|
||
factory HttpRequest.fromMap(Map<String, dynamic> map) { | ||
return HttpRequest( | ||
method: ((dynamic v) => v)(map['method']), | ||
path: ((dynamic v) => v)(map['path']), | ||
pathParameters: ((dynamic v) => v.map((k, v) => MapEntry(k, v)).cast<String, String>())(map['pathParameters']), | ||
query: ((dynamic v) => v.map((k, v) => MapEntry(k, v.map((v) => v).cast<String>().toList())).cast<String, List<String>>())(map['query']), | ||
headers: ((dynamic v) => v.map((k, v) => MapEntry(k, v.map((v) => v).cast<String>().toList())).cast<String, List<String>>())(map['headers']), | ||
body: ((dynamic v) => v)(map['body']), | ||
); | ||
} | ||
|
||
String toJson() => json.encode(toMap()); | ||
|
||
factory HttpRequest.fromJson(String source) => HttpRequest.fromMap(json.decode(source)); | ||
} | ||
|
||
class HttpResponse { | ||
int status; | ||
Map<String, List<String>> headers; | ||
Uint8List body; | ||
|
||
HttpResponse({ required this.status, required this.headers, required this.body, }); | ||
|
||
Map<String, dynamic> toMap() { | ||
return { | ||
'status': ((dynamic v) => v)(status), | ||
'headers': ((dynamic v) => v.map((k, v) => MapEntry(k, v.map((v) => v).cast<String>().toList())).cast<String, List<String>>())(headers), | ||
'body': ((dynamic v) => v)(body), | ||
}; | ||
} | ||
|
||
factory HttpResponse.fromMap(Map<String, dynamic> map) { | ||
return HttpResponse( | ||
status: ((dynamic v) => v)(map['status']), | ||
headers: ((dynamic v) => v.map((k, v) => MapEntry(k, v.map((v) => v).cast<String>().toList())).cast<String, List<String>>())(map['headers']), | ||
body: ((dynamic v) => v)(map['body']), | ||
); | ||
} | ||
|
||
String toJson() => json.encode(toMap()); | ||
|
||
factory HttpResponse.fromJson(String source) => HttpResponse.fromMap(json.decode(source)); | ||
} | ||
|
||
|
||
class BuiltinClient { | ||
final FTLHttpClient ftlClient; | ||
|
||
BuiltinClient({required this.ftlClient}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// ignore_for_file: unused_import | ||
library checkout; | ||
|
||
import 'dart:convert'; | ||
import 'dart:typed_data'; | ||
import 'ftl_client.dart'; | ||
import 'cart.dart' as cart; | ||
import 'currency.dart' as currency; | ||
import 'payment.dart' as payment; | ||
import 'productcatalog.dart' as productcatalog; | ||
import 'shipping.dart' as shipping; | ||
|
||
|
||
class PlaceOrderRequest { | ||
String userID; | ||
String userCurrency; | ||
shipping.Address address; | ||
String email; | ||
payment.CreditCardInfo creditCard; | ||
|
||
PlaceOrderRequest({ required this.userID, required this.userCurrency, required this.address, required this.email, required this.creditCard, }); | ||
|
||
Map<String, dynamic> toMap() { | ||
return { | ||
'userID': ((dynamic v) => v)(userID), | ||
'userCurrency': ((dynamic v) => v)(userCurrency), | ||
'address': ((dynamic v) => v.toMap())(address), | ||
'email': ((dynamic v) => v)(email), | ||
'creditCard': ((dynamic v) => v.toMap())(creditCard), | ||
}; | ||
} | ||
|
||
factory PlaceOrderRequest.fromMap(Map<String, dynamic> map) { | ||
return PlaceOrderRequest( | ||
userID: ((dynamic v) => v)(map['userID']), | ||
userCurrency: ((dynamic v) => v)(map['userCurrency']), | ||
address: ((dynamic v) => shipping.Address.fromMap(v))(map['address']), | ||
email: ((dynamic v) => v)(map['email']), | ||
creditCard: ((dynamic v) => payment.CreditCardInfo.fromMap(v))(map['creditCard']), | ||
); | ||
} | ||
|
||
String toJson() => json.encode(toMap()); | ||
|
||
factory PlaceOrderRequest.fromJson(String source) => PlaceOrderRequest.fromMap(json.decode(source)); | ||
} | ||
|
||
class OrderItem { | ||
cart.Item item; | ||
currency.Money cost; | ||
|
||
OrderItem({ required this.item, required this.cost, }); | ||
|
||
Map<String, dynamic> toMap() { | ||
return { | ||
'item': ((dynamic v) => v.toMap())(item), | ||
'cost': ((dynamic v) => v.toMap())(cost), | ||
}; | ||
} | ||
|
||
factory OrderItem.fromMap(Map<String, dynamic> map) { | ||
return OrderItem( | ||
item: ((dynamic v) => cart.Item.fromMap(v))(map['item']), | ||
cost: ((dynamic v) => currency.Money.fromMap(v))(map['cost']), | ||
); | ||
} | ||
|
||
String toJson() => json.encode(toMap()); | ||
|
||
factory OrderItem.fromJson(String source) => OrderItem.fromMap(json.decode(source)); | ||
} | ||
|
||
class Order { | ||
String id; | ||
String shippingTrackingID; | ||
currency.Money shippingCost; | ||
shipping.Address shippingAddress; | ||
List<OrderItem> items; | ||
|
||
Order({ required this.id, required this.shippingTrackingID, required this.shippingCost, required this.shippingAddress, required this.items, }); | ||
|
||
Map<String, dynamic> toMap() { | ||
return { | ||
'id': ((dynamic v) => v)(id), | ||
'shippingTrackingID': ((dynamic v) => v)(shippingTrackingID), | ||
'shippingCost': ((dynamic v) => v.toMap())(shippingCost), | ||
'shippingAddress': ((dynamic v) => v.toMap())(shippingAddress), | ||
'items': ((dynamic v) => v.map((v) => v.toMap()).cast<OrderItem>().toList())(items), | ||
}; | ||
} | ||
|
||
factory Order.fromMap(Map<String, dynamic> map) { | ||
return Order( | ||
id: ((dynamic v) => v)(map['id']), | ||
shippingTrackingID: ((dynamic v) => v)(map['shippingTrackingID']), | ||
shippingCost: ((dynamic v) => currency.Money.fromMap(v))(map['shippingCost']), | ||
shippingAddress: ((dynamic v) => shipping.Address.fromMap(v))(map['shippingAddress']), | ||
items: ((dynamic v) => v.map((v) => OrderItem.fromMap(v)).cast<OrderItem>().toList())(map['items']), | ||
); | ||
} | ||
|
||
String toJson() => json.encode(toMap()); | ||
|
||
factory Order.fromJson(String source) => Order.fromMap(json.decode(source)); | ||
} | ||
|
||
|
||
class CheckoutClient { | ||
final FTLHttpClient ftlClient; | ||
|
||
CheckoutClient({required this.ftlClient}); | ||
|
||
|
||
Future<Order> placeOrder(PlaceOrderRequest request) async { | ||
final response = await ftlClient.post('/checkout/userID', request: request.toMap()); | ||
if (response.statusCode == 200) { | ||
return Order.fromJson(response.body); | ||
} else { | ||
throw Exception('Failed to get placeOrder response'); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
library currency; | ||
|
||
import 'dart:convert'; | ||
import 'dart:typed_data'; | ||
import 'ftl_client.dart'; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck | ||
// eslint-disable @typescript-eslint/no-unused-vars | ||
// | ||
// Automatically generated by | ||
// ____________ | ||
// / __/_ __/ / | ||
// / _/ / / / /__ | ||
// /_/ /_/ /____/ | ||
// | ||
// | ||
export interface HttpRequest { | ||
method: string; | ||
path: string; | ||
pathParameters: Map<string, string>; | ||
query: Map<string, string[]>; | ||
headers: Map<string, string[]>; | ||
body: Uint8Array; | ||
} | ||
|
||
export interface HttpResponse { | ||
status: number; | ||
headers: Map<string, string[]>; | ||
body: Uint8Array; | ||
} | ||
|
||
|
||
export class BuiltinClient { | ||
private baseUrl: string; | ||
|
||
constructor(baseUrl: string) { | ||
this.baseUrl = baseUrl; | ||
} | ||
} |
Oops, something went wrong.