예제 #1
0
// home
package controllers

import (
	"fmt"
	"github.com/QLeelulu/goku"
	"gocbweb"
	"gocbweb/models2"
)

var HomeController = goku.Controller("home").
	Get("index", func(ctx *goku.HttpContext) goku.ActionResulter {
		ctx.ViewData["Title"] = "CD Catalog Site"
		bands := models2.GetAll(gocbweb.BANDTYPE)
		return ctx.View(bands)
	}).Get("genrelist", func(ctx *goku.HttpContext) goku.ActionResulter {
	ctx.ViewData["Title"] = "List of Genres"
	genres := models2.GetAll(gocbweb.GENRETYPE)
	return ctx.View(genres)
}).Get("bygenre", func(ctx *goku.HttpContext) goku.ActionResulter {
	genreId := ctx.RouteData.Params["id"]
	genreName := models2.GetGenreName(genreId)
	ctx.ViewData["Title"] = fmt.Sprintf("%s Albums", genreName)
	ctx.ViewData["GenreId"] = genreId
	bands := models2.GetBandsByGenre(genreId)
	return ctx.View(bands)
})
예제 #2
0
// band
package controllers

import (
	"fmt"
	"github.com/QLeelulu/goku"

	//	"gocbweb/models"
	"gocbweb"
	"gocbweb/models2"
)

var BandController = goku.Controller("band").
	Get("add", func(ctx *goku.HttpContext) goku.ActionResulter {
		ctx.ViewData["Title"] = "Adding A Band"
		locations := models2.GetAll(gocbweb.LOCTYPE)
		return ctx.View(locations)
		//return ctx.Html("not implemented")
	}).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
	errorString := "no errors"
	switch loctype {
	case "existing":
		if ctx.Request.FormValue("location_id") == "" {
			errorString = "No location was selected"
		} else {
			locationId = ctx.Request.FormValue("location_id")
		}
예제 #3
0
var AlbumController = goku.Controller("album").
	Get("index", func(ctx *goku.HttpContext) goku.ActionResulter {
		bandId := ctx.RouteData.Params["id"]
		bandDoc := models2.GetDoc(bandId)
		bandValue := bandDoc.Value.(map[string]interface{})
		ctx.ViewData["Title"] = bandValue["Name"].(string)
		//	ctx.ViewData["Name"] = bandValue["Name"].(string)
		//	ctx.ViewData["Id"] = bandDoc.Id
		//	albums := bandValue["Albums"].([]models2.Album)
		//	albums := bandDoc.GetAlbums()
		return ctx.View(bandDoc)
	}).Get("add", func(ctx *goku.HttpContext) goku.ActionResulter {
	ctx.ViewData["Title"] = "Add Album"
	ctx.ViewData["Id"] = ctx.RouteData.Params["id"]
	genres := models2.GetAll(gocbweb.GENRETYPE)
	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
	errorString := "no errors"
	switch genretype {
	case "existing":
		if ctx.Request.FormValue("genre_id") == "" {
			errorString = "No genre was selected"
		} else {