Exemple #1
0
// Create records a new bottle.
func (b *BottleController) Create(ctx *app.CreateBottleContext) error {
	bottle := b.db.NewBottle(ctx.AccountID)
	payload := ctx.Payload
	bottle.Name = payload.Name
	bottle.Vintage = payload.Vintage
	bottle.Vineyard = payload.Vineyard
	if payload.Varietal != "" {
		bottle.Varietal = payload.Varietal
	}
	if payload.Color != "" {
		bottle.Color = payload.Color
	}
	if payload.Sweetness != 0 {
		bottle.Sweetness = payload.Sweetness
	}
	if payload.Country != "" {
		bottle.Country = payload.Country
	}
	if payload.Region != "" {
		bottle.Region = payload.Region
	}
	if payload.Review != "" {
		bottle.Review = payload.Review
	}
	ctx.Header().Set("Location", app.BottleHref(ctx.AccountID, bottle.ID))
	return ctx.Created()
}
Exemple #2
0
Fichier : db.go Projet : 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}
}