コード例 #1
0
ファイル: cron.go プロジェクト: speedland/apps
func setupYAuctionCron(app *App) {
	app.Cron.Get(
		"Crawl registered keywords and generate AuctionItem with Assoc.",
		"every 1 hours synchronized",
		"/yauction/keywords/",
		lib.Admin.Required(func(res *wcg.Response, req *wcg.Request) {
			err := crawlKeywords(lib.NewAppContextFromRequest(req))
			if err != nil {
				lib.Error(res, req, err)
				return
			}
			app.Api.Ok(res, req)
		}),
	)

	app.Cron.Get(
		"Crawl expired AuctionItems to finalize properties.",
		"every 1 hours from 02:00 to 22:00",
		"/yauction/auctions/",
		lib.Admin.Required(func(res *wcg.Response, req *wcg.Request) {
			err := crawlExpiredAuctions(lib.NewAppContextFromRequest(req))
			if err != nil {
				lib.Error(res, req, err)
				return
			}
			app.Api.Ok(res, req)
		}),
	)

	app.Cron.Get(
		"Crawl expired AuctionItems to finalize properties.",
		"every 10 minutes from 00:00 to 02:00",
		"/yauction/auctions/",
		lib.Admin.Required(func(res *wcg.Response, req *wcg.Request) {
			err := crawlExpiredAuctions(lib.NewAppContextFromRequest(req))
			if err != nil {
				lib.Error(res, req, err)
				return
			}
			app.Api.Ok(res, req)
		}),
	)

	app.Cron.Get(
		"Crawl expired AuctionItems to finalize properties.",
		"every 10 minutes from 22:00 to 23:59",
		"/yauction/auctions/",
		lib.Admin.Required(func(res *wcg.Response, req *wcg.Request) {
			err := crawlExpiredAuctions(lib.NewAppContextFromRequest(req))
			if err != nil {
				lib.Error(res, req, err)
				return
			}
			app.Api.Ok(res, req)
		}),
	)

}
コード例 #2
0
ファイル: page.go プロジェクト: speedland/apps
func setupPages(app *App) {
	app.Page.Navi("/", "記事一覧").
		AssetPath("/blogapp/index.js").
		Templates("./blogapp/list.html", "./blogapp/post_part.html").
		Handler(
			func(res *wcg.Response, req *wcg.Request, p *lib.Page) {
				result, err := queryPosts(res, req, 20)
				if err != nil {
					panic(err)
				}
				p.Ogp("type", "blog")
				res.SetLocal("Posts", result.Posts)
				res.SetLocal("Next", result.Next)
				res.SetLocal("Previous", result.Previous)
			},
		)

	app.Page.Navi("/admin/editor.html", "記事管理").
		RequireAuth(lib.Admin).
		Templates("./blogapp/admin/editor.html").
		AssetPath("/blogapp/admin/editor.js")

	app.Page.Page("/posts/:id.html", "").
		Templates("./blogapp/show.html", "./blogapp/post_part.html").
		AssetPath("/blogapp/posts/show.js").
		Handler(
			func(res *wcg.Response, req *wcg.Request, p *lib.Page) {
				var post blog.Post
				driver := NewPostDriver(lib.NewAppContextFromRequest(req))
				key := driver.NewKey(req.Param("id"), 0, nil)
				err := driver.Get(key, &post)
				if err != nil {
					lib.Error(res, req, err)
					return
				}
				p.Title = post.Title
				p.Canonical = wcg.AbsoluteUrl(req, app.Page.Path(fmt.Sprintf("/posts/%s.html", post.Id)))
				p.Ogp("title", fmt.Sprintf("%s: %s", p.App.Title, p.Title))
				p.Ogp("url", p.Canonical)
				p.Ogp("type", "article")
				p.Ogp("description", post.Summary())
				imageUrl := post.ExtractFirstImageUrl()
				if imageUrl != "" {
					p.Ogp("image", imageUrl)
				}
				res.SetLocal("Post", post)
			})
}
コード例 #3
0
ファイル: cron.go プロジェクト: speedland/apps
func setupEventCron(app *App) {
	app.Cron.Get(
		"Generate YAKeyword crawling metadata for registered event show entries.",
		"every 1 hours synchronized",
		"/event/yakeywords/",
		lib.Admin.Required(func(res *wcg.Response, req *wcg.Request) {
			updateKeys, err := generateYACrawlerKeywords(lib.NewAppContextFromRequest(req))
			if err != nil {
				lib.Error(res, req, err)
				return
			}
			req.Logger.Info("Updating %d yauction keyword entries from event.", len(updateKeys))
			app.Api.Ok(res, req)
		}),
	)
}
コード例 #4
0
ファイル: func.go プロジェクト: speedland/apps
func historyInsights(res *wcg.Response, req *wcg.Request, app *App) {
	var appCtx = lib.NewAppContextFromRequest(req)
	member, ok := app.Members[req.Param("member")]
	if !ok {
		lib.NotFound(res, req)
		return
	}
	var insights amebloHistoryInsights
	mckey := fmt.Sprintf(MC_KEY_HISTORY, app.Key, member.Name)
	dent := NewAmebloEntryDriver(appCtx)
	dref := NewAmebloRefDriver(appCtx)
	mc := appCtx.NewMemcacheDriver()
	err := mc.CachedObject(mckey, &insights, func() (interface{}, error) {
		return getAmebloHistoryInsights(member, dent, dref)
	}, req.Query("force") == "1")
	if err != nil {
		lib.Error(res, req, err)
		return
	}
	res.WriteJson(insights)
}
コード例 #5
0
ファイル: api_event.go プロジェクト: speedland/apps
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)
		}
	})

	app.Api.Get("/events/importer/", lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			var appCtx = lib.NewAppContextFromRequest(req)
			url := req.Query("url")
			if eventShowList, err := importer.Import(url, appCtx.NewHttpClient()); err != nil {
				lib.Error(res, req, err)
			} else {
				res.WriteJson(eventShowList)
			}
		},
	))

	app.Api.Post("/events/", lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			t := &event.Event{}
			d := NewEventDriver(lib.NewAppContextFromRequest(req))
			if err := updateAttributesFromForm(res, req, t); err != nil {
				lib.Error(res, req, err)
				return
			}
			if t, err := d.Save(t); err != nil {
				lib.Error(res, req, err)
			} else {
				app.Api.Created(res, req, t.Id)
			}
		},
	))

	app.Api.Put("/events/:id.json", lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			if t, err := loadEvent(app, req, "id"); err != nil {
				lib.Error(res, req, err)
				return
			} else {
				if err := updateAttributesFromForm(res, req, t); err != nil {
					lib.Error(res, req, err)
					return
				}
				d := NewEventDriver(lib.NewAppContextFromRequest(req))
				if _, err := d.Save(t); err != nil {
					lib.Error(res, req, err)
				} else {
					app.Api.Ok(res, req)
				}
			}
		},
	))

	app.Api.Delete("/events/:id.json", lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			d := NewEventDriver(lib.NewAppContextFromRequest(req))
			if err := d.Delete(req.Param("id")); err != nil {
				lib.Error(res, req, err)
			} else {
				app.Api.Ok(res, req)
			}
		},
	))
}
コード例 #6
0
ファイル: api_event_show.go プロジェクト: speedland/apps
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 {
			lib.Error(res, req, err)
			return
		} else {
			var list []event.Show
			d := NewShowDriver(lib.NewAppContextFromRequest(req))
			if _, err = d.NewQueryWithEventId(e.Id).GetAll(&list); err != nil {
				lib.Error(res, req, err)
				return
			}
			if list == nil {
				list = make([]event.Show, 0)
			}
			if req.Query("composit") == "1" {
				res.WriteJson(compositShowList{
					Event:    e,
					ShowList: list,
				})
			} else {
				res.WriteJson(list)
			}
		}
	})

	app.Api.Post("/events/:event_id/shows/", func(res *wcg.Response, req *wcg.Request) {
		if e, err := loadEvent(app, req, "event_id"); err != nil {
			lib.Error(res, req, err)
			return
		} else {
			if err := showFormValidator.Eval(req.HttpRequest().PostForm); err != nil {
				lib.Error(res, req, err)
				return
			}
			d := NewShowDriver(lib.NewAppContextFromRequest(req))
			s := updateShowAttributes(req, &event.Show{
				EventId: e.Id,
			})
			if s, err := d.Save(s); err != nil {
				lib.Error(res, req, err)
				return
			} else {
				app.Api.Created(res, req, s.Id)
			}
		}
	})

	app.Api.Put("/events/:event_id/shows/:id.json", func(res *wcg.Response, req *wcg.Request) {
		if _, err := loadEvent(app, req, "event_id"); err != nil {
			lib.Error(res, req, err)
			return
		} else {
			var show event.Show
			d := NewShowDriver(lib.NewAppContextFromRequest(req))
			if _, err := d.Load(req.Param("id"), req.Param("event_id"), &show); err != nil {
				lib.Error(res, req, err)
				return
			} else {
				if _, err = d.Save(updateShowAttributes(req, &show)); err != nil {
					lib.Error(res, req, err)
					return
				}
				res.WriteJson(show)
			}
		}
	})

	app.Api.Delete("/events/:event_id/shows/:id.json", func(res *wcg.Response, req *wcg.Request) {
		if e, err := loadEvent(app, req, "event_id"); err != nil {
			lib.Error(res, req, err)
			return
		} else {
			d := NewShowDriver(lib.NewAppContextFromRequest(req))
			if err := d.Delete(req.Param("id"), e.Id); err != nil {
				lib.Error(res, req, err)
				return
			} else {
				app.Api.Ok(res, req)
			}
		}
	})
}
コード例 #7
0
ファイル: page.go プロジェクト: speedland/apps
func setupEventPages(app *App) {
	app.Page.Navi("/events/", "イベント").
		Templates("./artistapp/events.html", "./artistapp/show_part.html").
		AssetPath("/artistapp/events.js").
		Handler(
			func(res *wcg.Response, req *wcg.Request, p *lib.Page) {
				var appCtx = lib.NewAppContextFromRequest(req)
				var all = req.Query("all") == "1"
				q := NewShowDriver(appCtx).NewQuery()
				if all {
					q = q.Order("-StartAt")
				} else {
					q = q.Filter("StartAt >=", util.Date(now())).Order("StartAt")
				}
				if result, err := queryShows(res, req, q); err != nil {
					lib.Error(res, req, err)
					return
				} else {
					p.Ogp("type", "blog")
					res.SetLocal("Shows", result.Shows)
					if all {
						res.SetLocal("Future", result.Current)
						res.SetLocal("Next", fmt.Sprintf("%s&all=1", result.Next))
						res.SetLocal("Previous", fmt.Sprintf("%s&all=1", result.Previous))
					} else {
						res.SetLocal("All", fmt.Sprintf("%s&all=1", result.Current))
						res.SetLocal("Next", result.Next)
						res.SetLocal("Previous", result.Previous)
					}
				}
			})

	app.Page.Page("/events/:name.html", "イベント").
		Templates("./artistapp/events.html").
		Handler(
			func(res *wcg.Response, req *wcg.Request, p *lib.Page) {
				//d := NewShowDriver(app.Key, gae.NewContext(req), req.Logger)
			})

	app.Page.Navi("/admin/events.html", "イベント管理").
		Templates("./artistapp/admin/events.html").
		AssetPath("/artistapp/admin/events.js").
		RequireAuth(lib.Admin)

	app.Page.Page("/admin/events/:id.html", "").
		Templates("./artistapp/admin/events.html").
		AssetPath("/artistapp/admin/shows.js").
		Handler(
			func(res *wcg.Response, req *wcg.Request, p *lib.Page) {
				var e event.Event
				d := NewEventDriver(lib.NewAppContextFromRequest(req))
				key := d.NewKey(req.Param("id"), 0, nil)
				if err := d.Get(key, &e); err != nil {
					lib.Error(res, req, err)
					return
				}
				p.Title = fmt.Sprintf("公演一覧 - %s", e.Title)
			})

	app.Page.Page("/venues/:id/", "").
		AssetPath("/artistapp/venues.js").
		Templates("./artistapp/venues.html").
		Handler(
			func(res *wcg.Response, req *wcg.Request, p *lib.Page) {
				var appCtx = lib.NewAppContextFromRequest(req)
				var showList []event.Show
				q := NewShowDriver(appCtx).NewQuery()
				q = q.Filter("VenueId =", req.Param("id"))
				if _, err := q.Limit(1).GetAll(&showList); err != nil {
					lib.Error(res, req, err)
					return
				}
				if len(showList) == 0 {
					app.Page.NotFound(res, req)
					return
				}
				if list, err := NewEventShowList(appCtx, showList); err != nil {
					lib.Error(res, req, err)
					return
				} else {
					ev := list[0]
					p.Title = fmt.Sprintf("会場情報 - %s", ev.VenueName)
					res.SetLocal("VenueName", ev.VenueName)
					res.SetLocal("Latitude", ev.Latitude)
					res.SetLocal("Longitude", ev.Longitude)
				}
			})

}
コード例 #8
0
ファイル: api_post.go プロジェクト: speedland/apps
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)
			return
		}
		if p.IsDraft && lib.GetUserKind(req) != lib.Admin {
			app.Api.NotFound(res, req)
		} else {
			res.WriteJson(p)
		}
	})

	app.Api.Post("/posts/", lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			driver := NewPostDriver(lib.NewAppContextFromRequest(req))
			p := &blog.Post{}
			if err := updateAttributesFromForm(res, req, p); err != nil {
				lib.Error(res, req, err)
				return
			}
			if _, err := driver.Save(p); err != nil {
				lib.Error(res, req, err)
			}
			app.Api.Created(res, req, p.Id)
		},
	))

	app.Api.Put("/posts/:id.json", lib.Admin.Required(
		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)
				return
			}
			if err := updateAttributesFromForm(res, req, &p); err != nil {
				lib.Error(res, req, err)
				return
			}
			if _, err := driver.Save(&p); err != nil {
				lib.Error(res, req, err)
				return
			} else {
				app.Api.Ok(res, req)
			}
		},
	))

	app.Api.Delete("/posts/:id.json", lib.Admin.Required(
		func(res *wcg.Response, req *wcg.Request) {
			driver := NewPostDriver(lib.NewAppContextFromRequest(req))
			key := driver.NewKey(req.Param("id"), 0, nil)
			if err := driver.Delete(key); err != nil {
				lib.Error(res, req, err)
				return
			} else {
				app.Api.Ok(res, req)
			}
		},
	))
}
コード例 #9
0
ファイル: api.go プロジェクト: speedland/apps
func setupYAuctionApi(app *App) {
	app.Api.Get("/yauction/admin/closed/", lib.Admin.Required(func(res *wcg.Response, req *wcg.Request) {
		var appCtx = lib.NewAppContextFromRequest(req)
		keyword := req.Query("q")
		if keyword == "" {
			app.Api.BadRequest(res, req, fmt.Errorf("Missing 'q' parameter."))
			return
		}
		ids, err := crawlClosedKeyword(appCtx, keyword)
		if err != nil && ids == nil {
			lib.Error(res, req, err)
			return
		}
		if err != nil {
			res.WriteJson(map[string]interface{}{
				"num_updates": len(ids),
				"auction_ids": ids,
				"error":       err.Error(),
			})
		} else {
			res.WriteJson(map[string]interface{}{
				"num_updates": len(ids),
				"auction_ids": ids,
			})
		}
	}))

	app.Api.Get("/yauction/keywords/", func(res *wcg.Response, req *wcg.Request) {
		keyword, _ := url.QueryUnescape(req.Query("q"))
		var appCtx = lib.NewAppContextFromRequest(req)
		var ckeyword yauction.CrawlerKeyword
		var assocs []yauction.AssocCrawlerKeywordAuctionItem

		ckdriver := NewCrawlerKeywordDriver(appCtx)
		assocdriver := NewAssocCrawlerKeywordAuctionItemDriver(appCtx)
		aidriver := NewAuctionItemDriver(appCtx)

		if err := ckdriver.Get(ckdriver.NewKey(keyword, 0, nil), &ckeyword); err != nil {
			if err == ds.ErrNoSuchEntity {
				app.Api.NotFound(res, req)
			} else {
				app.Api.InternalError(res, req, err)
			}
			return
		}

		if _, err := assocdriver.NewQuery().Filter("Keyword =", keyword).GetAll(&assocs); err != nil {
			app.Api.InternalError(res, req, err)
			return
		}

		itemKeys := make([]*datastore.Key, len(assocs))
		items := make([]yauction.AuctionItem, len(assocs))
		for i, assoc := range assocs {
			itemKeys[i] = aidriver.NewKey(assoc.AuctionId, 0, nil)
		}

		err := aidriver.GetMulti(itemKeys, items)
		if ds.IsDatastoreError(err) {
			app.Api.InternalError(res, req, err)
			return
		}

		res.WriteJson(map[string]interface{}{
			"keyword":  ckeyword,
			"auctions": items,
		})
	})
}