예제 #1
0
func init() {
	var tokenFormValidator = v.NewFormValidator()
	tokenFormValidator.IntField("alert_on").Min(0)

	app.Api.Get("/api_tokens/", lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			d := lib.NewApiTokenDriver(lib.NewAppContextFromRequest(req))
			tokens := make([]*models.ApiToken, 0)
			_, err := d.NewQuery().GetAll(&tokens)
			if err != nil {
				panic(err)
			}
			res.WriteJson(tokens)
		},
	))

	app.Api.Post("/api_tokens/", lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			d := lib.NewApiTokenDriver(lib.NewAppContextFromRequest(req))
			t, err := d.Issue(req.Form("desc"))
			if err != nil {
				app.Api.InternalError(res, req, err)
			}
			app.Api.Created(res, req, t.Token)
		},
	))

	put_fn := lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			err := tokenFormValidator.Eval(req.HttpRequest().PostForm)
			if err != nil {
				app.Api.BadRequest(res, req, err)
				return
			}
			alertOn, _ := strconv.Atoi(req.Form("alert_on"))
			d := lib.NewApiTokenDriver(lib.NewAppContextFromRequest(req))
			err = d.Update(req.Param("token"), req.Form("desc"), time.Duration(alertOn))
			if err != nil {
				app.Api.InternalError(res, req, err)
			}
			app.Api.Ok(res, req)
		},
	)

	app.Api.Put("/api_tokens/:token/", put_fn) // TODO: remove this after client fixed.
	app.Api.Put("/api_tokens/:token.json", put_fn)

	delete_fn := lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			d := lib.NewApiTokenDriver(lib.NewAppContextFromRequest(req))
			err := d.Revoke(req.Param("token"))
			if err != nil {
				app.Api.InternalError(res, req, err)
			}
			app.Api.Ok(res, req)
		},
	)
	app.Api.Delete("/api_tokens/:token/", delete_fn) // TODO: remove this after client fixed.
	app.Api.Delete("/api_tokens/:token.json", delete_fn)
}
예제 #2
0
package pt

import (
	"fmt"
	"github.com/speedland/apps/lib/models/tv"
	"github.com/speedland/apps/lib/util"
	"github.com/speedland/apps/server/lib"
	"github.com/speedland/wcg"
	"github.com/speedland/wcg/gae"
	v "github.com/speedland/wcg/validation"
)

var recordFormValidator = v.NewFormValidator()

func init() {
	recordFormValidator.Field("start_at").Func(util.ValidateDateTimeString)
	recordFormValidator.Field("end_at").Func(util.ValidateDateTimeString)

	app.Api.Get("/records/",
		func(res *wcg.Response, req *wcg.Request) {
			ctx := gae.NewContext(req)
			d := NewRecordCacheDriver(app.Key, ctx, req.Logger)
			if list, err := d.GetRecords(req.Query("force") == "1"); err != nil {
				app.Api.InternalError(res, req, err)
			} else {
				res.WriteJson(list)
			}
		},
	)
	app.Api.Post("/records/", lib.Family.Required(
		func(res *wcg.Response, req *wcg.Request) {
예제 #3
0
package event

import (
	"github.com/speedland/apps/lib/models/event"
	"github.com/speedland/apps/lib/util"
	"github.com/speedland/apps/server/lib"
	. "github.com/speedland/apps/server/lib/artistapp/app"
	"github.com/speedland/wcg"
	v "github.com/speedland/wcg/validation"
	"strconv"
)

var showFormValidator = v.NewFormValidator()

func init() {
	showFormValidator.Field("venue_id").Required()
	showFormValidator.Field("venue_name").Required()
	showFormValidator.Field("latitude").Required()
	showFormValidator.Field("longitude").Required()
	showFormValidator.Field("open_at").Required()
	showFormValidator.Field("start_at").Required()
}

type compositShowList struct {
	*event.Event
	ShowList []event.Show `json:"show_list"`
}

func setupEventShowApi(app *App) {
	app.Api.Get("/events/:event_id/shows/", func(res *wcg.Response, req *wcg.Request) {
		if e, err := loadEvent(app, req, "event_id"); err != nil {
예제 #4
0
파일: api_event.go 프로젝트: speedland/apps
package event

import (
	"github.com/speedland/apps/lib/models/event"
	"github.com/speedland/apps/lib/models/event/importer"
	"github.com/speedland/apps/server/lib"
	. "github.com/speedland/apps/server/lib/artistapp/app"
	"github.com/speedland/wcg"
	v "github.com/speedland/wcg/validation"
)

var eventFormValidator = v.NewFormValidator()

func init() {
	eventFormValidator.Field("title").Min(1).Max(255)       // at leat 1 charactor required.
	eventFormValidator.Field("link").Min(1).Max(8192)       // at leat 1 charactor required.
	eventFormValidator.Field("image_link").Min(1).Max(8192) // at leat 1 charactor required.
}

func setupEventApi(app *App) {
	app.Api.Get("/events/", func(res *wcg.Response, req *wcg.Request) {
		var events []event.Event
		d := NewEventDriver(lib.NewAppContextFromRequest(req))
		if _, err := d.NewQuery().GetAll(&events); err != nil {
			lib.Error(res, req, err)
		} else {
			if events == nil {
				events = make([]event.Event, 0)
			}
			res.WriteJson(events)
		}
예제 #5
0
파일: api_post.go 프로젝트: speedland/apps
package blogapp

import (
	"github.com/speedland/apps/lib/models/blog"
	"github.com/speedland/apps/server/lib"
	"github.com/speedland/wcg"
	v "github.com/speedland/wcg/validation"
)

var postFormValidator = v.NewFormValidator()

func init() {
	postFormValidator.Field("title").Min(1).Max(255)         // at leat 1 charactor required.
	postFormValidator.DateTimeField("publish_at").Required() // at leat 1 charactor required.
}

func setupApi(app *App) {
	app.Api.Get("/posts/", func(res *wcg.Response, req *wcg.Request) {
		if result, err := queryPosts(res, req, 0); err != nil {
			lib.Error(res, req, err)
		} else {
			res.WriteJson(result)
		}
	})

	app.Api.Get("/posts/:id.json", func(res *wcg.Response, req *wcg.Request) {
		var p blog.Post
		driver := NewPostDriver(lib.NewAppContextFromRequest(req))
		key := driver.NewKey(req.Param("id"), 0, nil)
		if err := driver.Get(key, &p); err != nil {
			lib.Error(res, req, err)