Example #1
0
func deletePinPost(a *application.App, w http.ResponseWriter, r *http.Request) error {
	pm := models.NewPostModel(a.DB)
	post := context.Post(r)
	post.IsPinned = false
	err := pm.Update(nil, post)
	return errors.Wrap(err, "update error")
}
Example #2
0
func updatePostVote(a *application.App, w http.ResponseWriter, r *http.Request, voted bool) error {
	post := context.Post(r)
	user, _ := context.SessionUser(r)
	pm := models.NewPostModel(a.DB)

	if err := pm.UpdatePostVoteForUser(nil, post, user, voted); err != nil {
		return errors.Wrap(err, "update post vote error")
	}
	w.WriteHeader(http.StatusOK)
	return nil
}
Example #3
0
func (m *Middleware) isPostCreator(r *http.Request) bool {
	post := context.Post(r)
	user, ok := context.SessionUser(r)
	return ok && *post.Creator == *user
}