Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
feat: use new template.js for api generation
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Dec 8, 2023
1 parent 360cee3 commit aef5553
Show file tree
Hide file tree
Showing 24 changed files with 396 additions and 490 deletions.
1 change: 1 addition & 0 deletions bin/hermit.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sources = ["https://github.com/TBD54566975/hermit-ftl.git", "https://github.com/cashapp/hermit-packages.git"]
18 changes: 9 additions & 9 deletions frontend/mobile/lib/api/ad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import 'ftl_client.dart';
class AdRequest {
List<String> contextKeys;

AdRequest({ required this.contextKeys, });
AdRequest({ required this.contextKeys, });

Map<String, dynamic> toMap() {
return {
'contextKeys': ((dynamic v) =>v.map((v) => v).cast<String>().toList())(contextKeys),
'contextKeys': ((dynamic v) => v.map((v) => v).cast<String>().toList())(contextKeys),
};
}

Expand All @@ -31,12 +31,12 @@ class Ad {
String redirectURL;
String text;

Ad({ required this.redirectURL, required this.text, });
Ad({ required this.redirectURL, required this.text, });

Map<String, dynamic> toMap() {
return {
'redirectURL': ((dynamic v) =>v)(redirectURL),
'text': ((dynamic v) =>v)(text),
'redirectURL': ((dynamic v) => v)(redirectURL),
'text': ((dynamic v) => v)(text),
};
}

Expand All @@ -56,12 +56,12 @@ class AdResponse {
String name;
List<Ad> ads;

AdResponse({ required this.name, required this.ads, });
AdResponse({ required this.name, required this.ads, });

Map<String, dynamic> toMap() {
return {
'name': ((dynamic v) =>v)(name),
'ads': ((dynamic v) =>v.map((v) => Ad.fromMap(v)).cast<Ad>().toList())(ads),
'name': ((dynamic v) => v)(name),
'ads': ((dynamic v) => v.map((v) => Ad.fromMap(v)).cast<Ad>().toList())(ads),
};
}

Expand All @@ -85,7 +85,7 @@ class AdClient {


Future<AdResponse> get(AdRequest request) async {
final response = await ftlClient.get('/ad', request: request.toMap());
final response = await ftlClient.get('/ad', requestJson: request.toJson());
if (response.statusCode == 200) {
return AdResponse.fromJson(response.body);
} else {
Expand Down
28 changes: 14 additions & 14 deletions frontend/mobile/lib/api/cart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class Item {
String productID;
int quantity;

Item({ required this.productID, required this.quantity, });
Item({ required this.productID, required this.quantity, });

Map<String, dynamic> toMap() {
return {
'productID': ((dynamic v) =>v)(productID),
'quantity': ((dynamic v) =>v)(quantity),
'productID': ((dynamic v) => v)(productID),
'quantity': ((dynamic v) => v)(quantity),
};
}

Expand All @@ -34,12 +34,12 @@ class AddItemRequest {
String userID;
Item item;

AddItemRequest({ required this.userID, required this.item, });
AddItemRequest({ required this.userID, required this.item, });

Map<String, dynamic> toMap() {
return {
'userID': ((dynamic v) =>v)(userID),
'item': ((dynamic v) =>v.toMap())(item),
'userID': ((dynamic v) => v)(userID),
'item': ((dynamic v) => v.toMap())(item),
};
}

Expand Down Expand Up @@ -77,11 +77,11 @@ class AddItemResponse {
class GetCartRequest {
String userID;

GetCartRequest({ required this.userID, });
GetCartRequest({ required this.userID, });

Map<String, dynamic> toMap() {
return {
'userID': ((dynamic v) =>v)(userID),
'userID': ((dynamic v) => v)(userID),
};
}

Expand All @@ -100,12 +100,12 @@ class Cart {
String userID;
List<Item> items;

Cart({ required this.userID, required this.items, });
Cart({ required this.userID, required this.items, });

Map<String, dynamic> toMap() {
return {
'userID': ((dynamic v) =>v)(userID),
'items': ((dynamic v) =>v.map((v) => Item.fromMap(v)).cast<Item>().toList())(items),
'userID': ((dynamic v) => v)(userID),
'items': ((dynamic v) => v.map((v) => Item.fromMap(v)).cast<Item>().toList())(items),
};
}

Expand All @@ -124,11 +124,11 @@ class Cart {
class EmptyCartRequest {
String userID;

EmptyCartRequest({ required this.userID, });
EmptyCartRequest({ required this.userID, });

Map<String, dynamic> toMap() {
return {
'userID': ((dynamic v) =>v)(userID),
'userID': ((dynamic v) => v)(userID),
};
}

Expand Down Expand Up @@ -179,7 +179,7 @@ class CartClient {
}

Future<Cart> getCart(GetCartRequest request) async {
final response = await ftlClient.get('/cart', request: request.toMap());
final response = await ftlClient.get('/cart', requestJson: request.toJson());
if (response.statusCode == 200) {
return Cart.fromJson(response.body);
} else {
Expand Down
178 changes: 30 additions & 148 deletions frontend/mobile/lib/api/checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,104 +3,39 @@ library checkout;

import 'dart:convert';
import 'ftl_client.dart';
import 'productcatalog.dart' as productcatalog;
import 'currency.dart' as currency;
import 'shipping.dart' as shipping;
import 'payment.dart' as payment;
import 'cart.dart' as cart;
import 'currency.dart' as currency;
import 'productcatalog.dart' as productcatalog;


class Address {
String streetAddress;
String city;
String state;
String country;
int zipCode;

Address({ required this.streetAddress, required this.city, required this.state, required this.country, required this.zipCode, });

Map<String, dynamic> toMap() {
return {
'streetAddress': ((dynamic v) =>v)(streetAddress),
'city': ((dynamic v) =>v)(city),
'state': ((dynamic v) =>v)(state),
'country': ((dynamic v) =>v)(country),
'zipCode': ((dynamic v) =>v)(zipCode),
};
}

factory Address.fromMap(Map<String, dynamic> map) {
return Address(
streetAddress: ((dynamic v) => v)(map['streetAddress']),
city: ((dynamic v) => v)(map['city']),
state: ((dynamic v) => v)(map['state']),
country: ((dynamic v) => v)(map['country']),
zipCode: ((dynamic v) => v)(map['zipCode']),
);
}

String toJson() => json.encode(toMap());

factory Address.fromJson(String source) => Address.fromMap(json.decode(source));
}

class CreditCardInfo {
String number;
int cVV;
int expirationYear;
int expirationMonth;

CreditCardInfo({ required this.number, required this.cVV, required this.expirationYear, required this.expirationMonth, });

Map<String, dynamic> toMap() {
return {
'number': ((dynamic v) =>v)(number),
'cVV': ((dynamic v) =>v)(cVV),
'expirationYear': ((dynamic v) =>v)(expirationYear),
'expirationMonth': ((dynamic v) =>v)(expirationMonth),
};
}

factory CreditCardInfo.fromMap(Map<String, dynamic> map) {
return CreditCardInfo(
number: ((dynamic v) => v)(map['number']),
cVV: ((dynamic v) => v)(map['cVV']),
expirationYear: ((dynamic v) => v)(map['expirationYear']),
expirationMonth: ((dynamic v) => v)(map['expirationMonth']),
);
}

String toJson() => json.encode(toMap());

factory CreditCardInfo.fromJson(String source) => CreditCardInfo.fromMap(json.decode(source));
}

class PlaceOrderRequest {
String userID;
String userCurrency;
Address address;
shipping.Address address;
String email;
CreditCardInfo creditCard;
payment.CreditCardInfo creditCard;

PlaceOrderRequest({ required this.userID, required this.userCurrency, required this.address, required this.email, required this.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),
'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) => Address.fromMap(v))(map['address']),
address: ((dynamic v) => shipping.Address.fromMap(v))(map['address']),
email: ((dynamic v) => v)(map['email']),
creditCard: ((dynamic v) => CreditCardInfo.fromMap(v))(map['creditCard']),
creditCard: ((dynamic v) => payment.CreditCardInfo.fromMap(v))(map['creditCard']),
);
}

Expand All @@ -109,76 +44,23 @@ class PlaceOrderRequest {
factory PlaceOrderRequest.fromJson(String source) => PlaceOrderRequest.fromMap(json.decode(source));
}

class Money {
String currencyCode;
int units;
int nanos;

Money({ required this.currencyCode, required this.units, required this.nanos, });

Map<String, dynamic> toMap() {
return {
'currencyCode': ((dynamic v) =>v)(currencyCode),
'units': ((dynamic v) =>v)(units),
'nanos': ((dynamic v) =>v)(nanos),
};
}

factory Money.fromMap(Map<String, dynamic> map) {
return Money(
currencyCode: ((dynamic v) => v)(map['currencyCode']),
units: ((dynamic v) => v)(map['units']),
nanos: ((dynamic v) => v)(map['nanos']),
);
}

String toJson() => json.encode(toMap());

factory Money.fromJson(String source) => Money.fromMap(json.decode(source));
}

class Item {
String productID;
int quantity;

Item({ required this.productID, required this.quantity, });

Map<String, dynamic> toMap() {
return {
'productID': ((dynamic v) =>v)(productID),
'quantity': ((dynamic v) =>v)(quantity),
};
}

factory Item.fromMap(Map<String, dynamic> map) {
return Item(
productID: ((dynamic v) => v)(map['productID']),
quantity: ((dynamic v) => v)(map['quantity']),
);
}

String toJson() => json.encode(toMap());

factory Item.fromJson(String source) => Item.fromMap(json.decode(source));
}

class OrderItem {
Item item;
Money cost;
cart.Item item;
currency.Money cost;

OrderItem({ required this.item, required this.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),
'item': ((dynamic v) => v.toMap())(item),
'cost': ((dynamic v) => v.toMap())(cost),
};
}

factory OrderItem.fromMap(Map<String, dynamic> map) {
return OrderItem(
item: ((dynamic v) => Item.fromMap(v))(map['item']),
cost: ((dynamic v) => Money.fromMap(v))(map['cost']),
item: ((dynamic v) => cart.Item.fromMap(v))(map['item']),
cost: ((dynamic v) => currency.Money.fromMap(v))(map['cost']),
);
}

Expand All @@ -190,28 +72,28 @@ class OrderItem {
class Order {
String id;
String shippingTrackingID;
Money shippingCost;
Address shippingAddress;
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, });
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) => OrderItem.fromMap(v)).cast<OrderItem>().toList())(items),
'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) => OrderItem.fromMap(v)).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) => Money.fromMap(v))(map['shippingCost']),
shippingAddress: ((dynamic v) => Address.fromMap(v))(map['shippingAddress']),
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']),
);
}
Expand All @@ -229,7 +111,7 @@ class CheckoutClient {


Future<Order> placeOrder(PlaceOrderRequest request) async {
final response = await ftlClient.post('/checkout', request: request.toMap());
final response = await ftlClient.post('/checkout/${request.userID}', request: request.toMap());
if (response.statusCode == 200) {
return Order.fromJson(response.body);
} else {
Expand Down
Loading

0 comments on commit aef5553

Please sign in to comment.