Skip to content

Commit

Permalink
feat: add ingress annotations to boutique (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman authored Oct 19, 2023
1 parent 9d0efcc commit d51f20e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions examples/online-boutique/services/ad/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type AdResponse struct {
}

//ftl:verb
//ftl:ingress GET /ad
func Get(ctx context.Context, req AdRequest) (AdResponse, error) {
resp := AdResponse{}
if len(req.ContextKeys) > 0 {
Expand Down
3 changes: 3 additions & 0 deletions examples/online-boutique/services/cart/cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Cart struct {
}

//ftl:verb
//ftl:ingress POST /cart/add
func AddItem(ctx context.Context, req AddItemRequest) (AddItemResponse, error) {
store.Add(req.UserID, req.Item)
return AddItemResponse{}, nil
Expand All @@ -35,6 +36,7 @@ type GetCartRequest struct {
}

//ftl:verb
//ftl:ingress GET /cart
func GetCart(ctx context.Context, req GetCartRequest) (Cart, error) {
return Cart{Items: store.Get(req.UserID)}, nil
}
Expand All @@ -46,6 +48,7 @@ type EmptyCartRequest struct {
type EmptyCartResponse struct{}

//ftl:verb
//ftl:ingress POST /cart/empty
func EmptyCart(ctx context.Context, req EmptyCartRequest) (EmptyCartResponse, error) {
store.Empty(req.UserID)
return EmptyCartResponse{}, nil
Expand Down
1 change: 1 addition & 0 deletions examples/online-boutique/services/checkout/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Order struct {
}

//ftl:verb
//ftl:ingress POST /checkout
func PlaceOrder(ctx context.Context, req PlaceOrderRequest) (Order, error) {
cartItems, err := ftl.Call(ctx, cart.GetCart, cart.GetCartRequest{UserID: req.UserID})
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions examples/online-boutique/services/currency/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type GetSupportedCurrenciesResponse struct {
}

//ftl:verb
//ftl:ingress GET /currency/supported
func GetSupportedCurrencies(ctx context.Context, req GetSupportedCurrenciesRequest) (GetSupportedCurrenciesResponse, error) {
return GetSupportedCurrenciesResponse{CurrencyCodes: maps.Keys(database)}, nil
}
Expand All @@ -37,6 +38,7 @@ type ConvertRequest struct {
}

//ftl:verb
//ftl:ingress POST /currency/convert
func Convert(ctx context.Context, req ConvertRequest) (money.Money, error) {
from := req.From
fromRate, ok := database[from.CurrencyCode]
Expand Down
1 change: 1 addition & 0 deletions examples/online-boutique/services/payment/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ChargeResponse struct {
}

//ftl:verb
//ftl:ingress POST /payment/charge
func Charge(ctx context.Context, req ChargeRequest) (ChargeResponse, error) {
card := req.CreditCard
number := strings.ReplaceAll(card.Number, "-", "")
Expand Down
20 changes: 10 additions & 10 deletions examples/online-boutique/services/productcatalog/database.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "OLJCESPC7Z",
"name": "Sunglasses",
"description": "Add a modern touch to your outfits with these sleek aviator sunglasses.",
"picture": "/static/img/products/sunglasses.jpg",
"picture": "https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/static/img/products/sunglasses.jpg?raw=true",
"priceUsd": {
"currencyCode": "USD",
"units": 19,
Expand All @@ -15,7 +15,7 @@
"id": "66VCHSJNUP",
"name": "Tank Top",
"description": "Perfectly cropped cotton tank, with a scooped neckline.",
"picture": "/static/img/products/tank-top.jpg",
"picture": "https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/static/img/products/tank-top.jpg?raw=true",
"priceUsd": {
"currencyCode": "USD",
"units": 18,
Expand All @@ -27,7 +27,7 @@
"id": "1YMWWN1N4O",
"name": "Watch",
"description": "This gold-tone stainless steel watch will work with most of your outfits.",
"picture": "/static/img/products/watch.jpg",
"picture": "https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/static/img/products/watch.jpg?raw=true",
"priceUsd": {
"currencyCode": "USD",
"units": 109,
Expand All @@ -39,7 +39,7 @@
"id": "L9ECAV7KIM",
"name": "Loafers",
"description": "A neat addition to your summer wardrobe.",
"picture": "/static/img/products/loafers.jpg",
"picture": "https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/static/img/products/loafers.jpg?raw=true",
"priceUsd": {
"currencyCode": "USD",
"units": 89,
Expand All @@ -51,7 +51,7 @@
"id": "2ZYFJ3GM2N",
"name": "Hairdryer",
"description": "This lightweight hairdryer has 3 heat and speed settings. It's perfect for travel.",
"picture": "/static/img/products/hairdryer.jpg",
"picture": "https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/static/img/products/hairdryer.jpg?raw=true",
"priceUsd": {
"currencyCode": "USD",
"units": 24,
Expand All @@ -63,7 +63,7 @@
"id": "0PUK6V6EV0",
"name": "Candle Holder",
"description": "This small but intricate candle holder is an excellent gift.",
"picture": "/static/img/products/candle-holder.jpg",
"picture": "https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/static/img/products/candle-holder.jpg?raw=true",
"priceUsd": {
"currencyCode": "USD",
"units": 18,
Expand All @@ -75,7 +75,7 @@
"id": "LS4PSXUNUM",
"name": "Salt & Pepper Shakers",
"description": "Add some flavor to your kitchen.",
"picture": "/static/img/products/salt-and-pepper-shakers.jpg",
"picture": "https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/static/img/products/salt-and-pepper-shakers.jpg?raw=true",
"priceUsd": {
"currencyCode": "USD",
"units": 18,
Expand All @@ -87,7 +87,7 @@
"id": "9SIQT8TOJO",
"name": "Bamboo Glass Jar",
"description": "This bamboo glass jar can hold 57 oz (1.7 l) and is perfect for any kitchen.",
"picture": "/static/img/products/bamboo-glass-jar.jpg",
"picture": "https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/main/src/frontend/static/img/products/bamboo-glass-jar.jpg",
"priceUsd": {
"currencyCode": "USD",
"units": 5,
Expand All @@ -99,12 +99,12 @@
"id": "6E92ZMYYFZ",
"name": "Mug",
"description": "A simple mug with a mustard interior.",
"picture": "/static/img/products/mug.jpg",
"picture": "https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/static/img/products/mug.jpg?raw=true",
"priceUsd": {
"currencyCode": "USD",
"units": 8,
"nanos": 990000000
},
"categories": ["kitchen"]
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ListResponse struct {
}

//ftl:verb
//ftl:ingress GET /productcatalog
func List(ctx context.Context, req ListRequest) (ListResponse, error) {
return ListResponse{Products: database}, nil
}
Expand All @@ -46,6 +47,7 @@ type GetRequest struct {
}

//ftl:verb
//ftl:ingress GET /productcatalog/id
func Get(ctx context.Context, req GetRequest) (Product, error) {
for _, p := range database {
if p.ID == req.ID {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ListResponse struct {
}

//ftl:verb
//ftl:ingress GET /recommendation
func List(ctx context.Context, req ListRequest) (ListResponse, error) {

catalog, err := ftl.Call(ctx, productcatalog.List, productcatalog.ListRequest{})
Expand Down
2 changes: 2 additions & 0 deletions examples/online-boutique/services/shipping/shipping.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ShippingRequest struct {
}

//ftl:verb
//ftl:ingress POST /shipping/quote
func GetQuote(ctx context.Context, req ShippingRequest) (money.Money, error) {
return moneyFromUSD(8.99), nil
}
Expand All @@ -33,6 +34,7 @@ type ShipOrderResponse struct {
}

//ftl:verb
//ftl:ingress POST /shipping/ship
func ShipOrder(ctx context.Context, req ShippingRequest) (ShipOrderResponse, error) {
baseAddress := fmt.Sprintf("%s, %s, %s", req.Address.StreetAddress, req.Address.City, req.Address.State)
return ShipOrderResponse{ID: createTrackingID(baseAddress)}, nil
Expand Down

0 comments on commit d51f20e

Please sign in to comment.