Skip to content

Instantly share code, notes, and snippets.

@MaherSaif
Created March 17, 2021 11:57
Show Gist options
  • Save MaherSaif/c86c306f0974fa610551ca2f1993be3c to your computer and use it in GitHub Desktop.
Save MaherSaif/c86c306f0974fa610551ca2f1993be3c to your computer and use it in GitHub Desktop.
Sample Code
module Api
class NotificationsController < ApiController
before_action :authorize_request
def index
notifications = current_user.notifications.recent
json = NotificationSerializer.new(notifications, is_collection: true).serializable_hash
render json: json
end
def mark_as_seen
current_user.notifications.mark_as_seen!
end
end
end
def index
playground = Playground.find params[:playground_id]
reviews = playground.reviews.desc_order.limit(5)
render json: reviews
end
def create
review = PlaygroundReview.new review_params
review.user = current_user
if review.save
OwnerReservationMailer
.with(owner: review.playground_owner, playground: review.playground, review: review)
.new_review_mail
.deliver_later
review.playground_owner.notifications.create({
title: 'Playground Review',
message: "New review for #{review.playground&.name}."
})
end
render json: {
ok: true,
review: review
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment