예제 #1
0
func AuthorizationAccountProvider(c appengine.Context, logger *Logger, request *http.Request, render render.Render, martiniContext martini.Context, appx *appx.Datastore) {
	authToken := extractAuthToken(request)

	if authToken == "" {
		render.Status(http.StatusUnauthorized)
		return
	}

	var currentAccount models.Account
	if err := appx.Query(models.Accounts.ByAuthToken(authToken)).Result(&currentAccount); err != nil {
		logger.Errorf("%v", err)
		render.Status(http.StatusUnauthorized)
		return
	}

	martiniContext.Map(&currentAccount)
}
func ListPostsHandler(r render.Render, appx *appx.Datastore, location middleware.RequestLocation) {
	response := model.Response{
		ErrorCode: http.StatusOK,
		Message:   []string{},
		Data:      nil,
	}

	posts := []*model.Post{}
	err := appx.Query(model.Posts.All(location.Country)).Results(&posts)

	response.Data = resources.FromPostResource(posts)

	if err != nil && err != datastore.Done {
		log.Printf("Error: %+v", err)
		response.ErrorCode = http.StatusInternalServerError
		response.Message = append(response.Message, err.Error())
	}

	r.JSON(200, response)
}