-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from hashicorp-demoapp/add-product-functionality
Make public API compatible with redesigned frontend
- Loading branch information
Showing
27 changed files
with
1,844 additions
and
340 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION=v0.0.4 | ||
VERSION=v0.0.7 | ||
REPOSITORY=hashicorpdemoapp/public-api | ||
|
||
.PHONY: auth | ||
|
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 |
---|---|---|
@@ -1 +1,26 @@ | ||
package models | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/hashicorp-demoapp/hashicups-client-go" | ||
) | ||
|
||
// IngredientsFromProductAPI is an adaptor function which converts the | ||
// Ingredients API model into the local model | ||
func IngredientsFromProductAPI(pIngs []hashicups.Ingredient) ([]*Ingredient, error) { | ||
ings := make([]*Ingredient, 0) | ||
|
||
for i, pIng := range pIngs { | ||
ing := &Ingredient{ | ||
ID: strconv.Itoa(pIng.ID), | ||
Name: &pIngs[i].Name, | ||
Quantity: &pIngs[i].Quantity, | ||
Unit: &pIngs[i].Unit, | ||
} | ||
|
||
ings = append(ings, ing) | ||
} | ||
|
||
return ings, nil | ||
} |
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,35 @@ | ||
package models | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/hashicorp-demoapp/hashicups-client-go" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIngredientConvertsFromProductsAPI(t *testing.T) { | ||
i, err := IngredientsFromProductAPI(apiIngredientModel) | ||
assert.NoError(t, err) | ||
|
||
assert.Len(t, i, 2) | ||
assert.Equal(t, strconv.Itoa(apiIngredientModel[0].ID), i[0].ID) | ||
assert.Equal(t, apiIngredientModel[0].Name, *i[0].Name) | ||
assert.Equal(t, apiIngredientModel[0].Quantity, *i[0].Quantity) | ||
assert.Equal(t, apiIngredientModel[0].Unit, *i[0].Unit) | ||
} | ||
|
||
var apiIngredientModel = []hashicups.Ingredient{ | ||
{ | ||
ID: 1, | ||
Name: "Espresso", | ||
Quantity: 40, | ||
Unit: "ml", | ||
}, | ||
{ | ||
ID: 1, | ||
Name: "Semi Skimmed Milk", | ||
Quantity: 20, | ||
Unit: "ml", | ||
}, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.