示例#1
0
func updateShowAttributes(req *wcg.Request, s *event.Show) *event.Show {
	s.OpenAt, _ = util.ParseDateTime(req.Form("open_at"))
	s.StartAt, _ = util.ParseDateTime(req.Form("start_at"))
	s.Latitude, _ = strconv.ParseFloat(req.Form("latitude"), 64)
	s.Longitude, _ = strconv.ParseFloat(req.Form("longitude"), 64)
	s.VenueId = req.Form("venue_id")
	s.VenueName = req.Form("venue_name")
	s.PiaLink = req.Form("pia_link")
	s.YAKeyword = req.Form("ya_keyword")
	return s
}
示例#2
0
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) {
			if err := recordFormValidator.Eval(req.HttpRequest().PostForm); err != nil {
				app.Api.BadRequest(res, req, err)
				return
			}

			ctx := gae.NewContext(req)
			d := NewRecordCacheDriver(app.Key, ctx, req.Logger)
			start, _ := util.ParseDateTime(req.Form("start_at"))
			end, _ := util.ParseDateTime(req.Form("end_at"))
			rec := tv.NewTvRecord(
				req.Form("title"), req.Form("category"),
				start, end,
				req.Form("cid"), req.Form("sid"),
				req.User.Id(),
			)

			if err := d.Save(rec); err != nil {
				app.Api.InternalError(res, req, err)
			} else {
				app.Api.Created(res, req, fmt.Sprintf("/records/%s.json", rec.Key()))
			}
		},
	))

	app.Api.Delete("/records/:key.json", lib.Family.Required(
		func(res *wcg.Response, req *wcg.Request) {
			d := NewRecordCacheDriver(app.Key, gae.NewContext(req), req.Logger)
			if err := d.Delete(req.Param("key")); err != nil {
				app.Api.InternalError(res, req, err)
				return
			} else {
				app.Api.Ok(res, req)
			}
		},
	))
}
示例#3
0
func TestApiCreateEventShow(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		appCtx := apptest.NewAppContextFromTestServer(app.TestApp().App, ts)
		test.DatastoreFixture(ts.Context, "./fixtures/TestApiCreateEventShow.json", nil)
		d := NewShowDriver(appCtx)

		var respJson map[string]interface{}
		var show event.Show
		p := app.TestApp().Api.Path("/events/event1/shows")
		req := ts.PostForm(p, url.Values{
			"open_at":    []string{"2015-01-02T06:00:00Z"},
			"start_at":   []string{"2015-01-02T07:00:00Z"},
			"latitude":   []string{"37.39"},
			"longitude":  []string{"140.38"},
			"venue_id":   []string{"153237058036933"},
			"venue_name": []string{"郡山市民文化センター"},
			"pia_link":   []string{"http://pia.jp/link"},
			"ya_keyword": []string{"郡山"},
		})
		lib.SetApiTokenForTest(req, lib.Admin)
		res := req.RouteTo(app.TestApp().Routes())
		assert.HttpStatus(201, res)

		err := util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 1
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm the show has been inserted within timeout window.")

		res.Json(&respJson)
		d.Load(respJson["id"].(string), "event1", &show)
		open_at, _ := util.ParseDateTime("2015-01-02T06:00:00Z")
		start_at, _ := util.ParseDateTime("2015-01-02T07:00:00Z")
		assert.EqTime(open_at, show.OpenAt, "OpenAt")
		assert.EqTime(start_at, show.StartAt, "StartAt")
		assert.EqFloat64(37.39, show.Latitude, "Latitude")
		assert.EqFloat64(140.38, show.Longitude, "Longitude")
		assert.EqStr("153237058036933", show.VenueId, "VenueId")
		assert.EqStr("郡山市民文化センター", show.VenueName, "VenueName")
		assert.EqStr("http://pia.jp/link", show.PiaLink, "PiaLink")
		assert.EqStr("郡山", show.YAKeyword, "YAKeyword")
	})
}