Ejemplo n.º 1
0
func retrieveAllCodes(ctx appengine.Context, user *models.User, r *http.Request) *ActionResponse {
	codes, err := models.FindCodesByUserId(ctx, user.Id)
	content := ""

	if err != nil {
		content = createApiError(err).AsJson()
	} else {
		d, _ := json.Marshal(codes)
		content = string(d)
	}

	return (&ActionResponse{
		Code:       http.StatusOK,
		RenderText: content,
	}).AsJson()
}
Ejemplo n.º 2
0
func (c *AppController) CodesRoot(w http.ResponseWriter, r *http.Request, session *sessions.Session) *ActionResponse {
	ctx := appengine.NewContext(r)
	user := c.GetCurrentUser(session)
	codes, err := models.FindCodesByUserId(ctx, user.Id)
	code := &models.Code{}

	if err != nil {
		return &ActionResponse{
			RenderText: fmt.Sprintf("Code loading error: %s", err.Error()),
		}
	} else {
		return &ActionResponse{
			NoLayout: true,
			Render:   "views/codes/angular_index.html",
			Context: &DataContext{
				LoggedIn:    true,
				CurrentUser: c.GetCurrentUser(session),
				Notice:      c.GetNotice(session),
				Code:        code,
				Codes:       codes,
			},
		}
	}
}