Created
March 17, 2021 11:57
-
-
Save MaherSaif/c86c306f0974fa610551ca2f1993be3c to your computer and use it in GitHub Desktop.
Sample Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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