示例#1
0
	Get("add", func(ctx *goku.HttpContext) goku.ActionResulter {
		ctx.ViewData["Title"] = "Add Band"
		locations := models.GetAllLocations()
		return ctx.View(locations)
	}).Post("verify", func(ctx *goku.HttpContext) goku.ActionResulter {
	ctx.ViewData["Title"] = "Verifying Band"
	name := ctx.Request.FormValue("name")
	loctype := ctx.Request.FormValue("loctype")
	var locationId string // for Couchbase
	errorString := "no errors"
	switch loctype {
	case "existing":
		if ctx.Request.FormValue("location_id") == "" {
			errorString = "No location selected"
		} else {
			locationId = models.ConvertToId(ctx.Request.FormValue("location_id"))
		}
		break
	case "new":
		if ctx.Request.FormValue("country") != "" {
			locationId = models.GenerateId("location")
			location := models.Location{Id: locationId, City: ctx.Request.FormValue("city"),
				State: ctx.Request.FormValue("state"), Country: ctx.Request.FormValue("country")}
			err := location.Add()
			if err != nil {
				errorString = fmt.Sprintf("Location: %s", err.Error())
			}
		} else {
			errorString = "Country is required"
		}
		break
示例#2
0
package controllers

import (
	"fmt"
	"github.com/QLeelulu/goku"
	"gomenu1/models"
)

var HomeController = goku.Controller("home").
	Get("index", func(ctx *goku.HttpContext) goku.ActionResulter {
		ctx.ViewData["Title"] = "CD Catalog Home Page"
		bands := models.GetAllBands()
		return ctx.View(bands)
	}).Get("genrelist", func(ctx *goku.HttpContext) goku.ActionResulter {
	ctx.ViewData["Title"] = "List of Genres"
	genres := models.GetAllGenres()
	return ctx.View(genres)
}).Get("bygenre", func(ctx *goku.HttpContext) goku.ActionResulter {
	rawId := ctx.RouteData.Params["id"]
	genreId := models.ConvertToId(rawId)
	genreName := models.GetGenreName(genreId)
	ctx.ViewData["Title"] = fmt.Sprintf("%s Albums", genreName)
	ctx.ViewData["GenreId"] = genreId
	bands := models.GetBandsByGenre(genreId)
	return ctx.View(bands)
})
示例#3
0
package controllers

import (
	"fmt"
	"github.com/QLeelulu/goku"
	"gomenu1/models"
	"strconv"
)

var AlbumController = goku.Controller("album").
	Get("index", func(ctx *goku.HttpContext) goku.ActionResulter {
		rawId := ctx.RouteData.Params["id"]
		bandId := models.ConvertToId(rawId)
		band := models.GetBand(bandId)
		ctx.ViewData["Title"] = band.Name
		return ctx.View(band)
	}).Get("add", func(ctx *goku.HttpContext) goku.ActionResulter {
	ctx.ViewData["Title"] = "Add Album"
	rawId := ctx.RouteData.Params["id"]
	ctx.ViewData["Id"] = rawId
	genres := models.GetAllGenres()
	return ctx.View(genres)
}).Post("verify", func(ctx *goku.HttpContext) goku.ActionResulter {
	ctx.ViewData["Title"] = "Verifying Album"
	rawId := ctx.RouteData.Params["id"]
	name := ctx.Request.FormValue("name")
	yearString := ctx.Request.FormValue("year")
	year, _ := strconv.Atoi(yearString)
	genretype := ctx.Request.FormValue("genretype")
	var genreId string // for Couchbase
	errorString := "no errors"