Beispiel #1
0
// Create records a new account.
func (b *AccountController) Create(c *app.CreateAccountContext) error {
	account := b.db.NewAccount()
	payload := c.Payload
	account.Name = payload.Name
	c.Header().Set("Location", app.AccountHref(account.ID))
	return c.Created()
}
Beispiel #2
0
Datei: db.go Projekt: tylerb/goa
// NewDB initializes a new "DB" with dummy data.
func NewDB() *DB {
	account := &app.Account{ID: 1, Name: "account 1", Href: app.AccountHref(1)}
	account2 := &app.Account{ID: 2, Name: "account 2", Href: app.AccountHref(2)}
	bottles := map[int][]*app.Bottle{
		1: []*app.Bottle{
			&app.Bottle{
				ID:        100,
				Account:   account,
				Href:      app.BottleHref(1, 100),
				Name:      "Number 8",
				Vineyard:  "Asti Winery",
				Varietal:  "Merlot",
				Vintage:   2012,
				Color:     "red",
				Sweetness: 1,
				Country:   "USA",
				Region:    "California",
				Review:    "Great value",
				Rating:    4,
			},
			&app.Bottle{
				ID:        101,
				Account:   account,
				Href:      app.BottleHref(1, 101),
				Name:      "Mourvedre",
				Vineyard:  "Rideau",
				Varietal:  "Mourvedre",
				Vintage:   2012,
				Color:     "red",
				Sweetness: 1,
				Country:   "USA",
				Region:    "California",
				Review:    "Good but expensive",
				Rating:    3,
			},
			&app.Bottle{
				ID:        102,
				Account:   account,
				Href:      app.BottleHref(1, 102),
				Name:      "Blue's Cuvee",
				Vineyard:  "Longoria",
				Varietal:  "Cabernet Franc with Merlot, Malbec, Cabernet Sauvignon and Syrah",
				Vintage:   2012,
				Color:     "red",
				Sweetness: 1,
				Country:   "USA",
				Region:    "California",
				Review:    "Favorite",
				Rating:    5,
			},
		},
		2: []*app.Bottle{
			&app.Bottle{
				ID:        200,
				Account:   account2,
				Href:      app.BottleHref(42, 200),
				Name:      "Blackstone Merlot",
				Vineyard:  "Blackstone",
				Varietal:  "Merlot",
				Vintage:   2012,
				Color:     "red",
				Sweetness: 1,
				Country:   "USA",
				Region:    "California",
				Review:    "OK",
				Rating:    3,
			},
			&app.Bottle{
				ID:        201,
				Account:   account2,
				Href:      app.BottleHref(42, 201),
				Name:      "Wild Horse",
				Vineyard:  "Wild Horse",
				Varietal:  "Pinot Noir",
				Vintage:   2012,
				Color:     "red",
				Sweetness: 1,
				Country:   "USA",
				Region:    "California",
				Review:    "Solid Pinot",
				Rating:    4,
			},
		},
	}
	return &DB{accounts: map[int]*app.Account{1: account, 2: account2}, bottles: bottles, maxAccountID: 2}
}