Commit 88cf08c3 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei

Return only unread notifications

Signed-off-by: Bruno Freitas Tissei's avatarBruno Freitas Tissei <bft15@inf.ufpr.br>
parent 71d3620a
Pipeline #14202 failed with stage
in 1 minute and 28 seconds
......@@ -6,20 +6,30 @@ module Api::V1
# GET /notifications
def index
@notifications = Notification.where(account_id: current_user.first.account_id)
.where(read: false)
render json: @notifications
end
# POST /notifications
def create
notification = notification_params
if notification["account_id"] == nil
notification["account_id"] = current_user.first.account_id
else
notification["account_id"] = Citizen.where(account_id:notification["account_id"]).first.id
end
@notification = Notification.create!(notification)
@notification = Notification.new(notification)
authorize @notification, :create?
render json: @notification, status: :created
if @notification.save
render json: @notification, status: :created
else
render json: @notification.errors, status: :unprocessable_entity
end
end
# GET /notifications/:id
......@@ -30,6 +40,7 @@ module Api::V1
}, status: 404
else
authorize @notification, :show?
render json: @notification
end
end
......@@ -41,8 +52,9 @@ module Api::V1
errors: ["Notification #{params[:id]} does not exist."]
}, status: 404
else
authorize @notification, :update?
if @notification.update(notification_params)
authorize @notification, :update?
render json: @notification
else
render json: @notification.errors, status: :unprocessable_entity
......@@ -88,4 +100,4 @@ module Api::V1
)
end
end
end
\ No newline at end of file
end
class Notification < ApplicationRecord
# belongs_to :account
belongs_to :schedule, optional: true
belongs_to :resource_booking, optional: true
validates_presence_of :account_id,
:reminder_time,
:read,
:content
def get_notification_id
end
# belongs_to :account
belongs_to :schedule, optional: true
belongs_to :resource_booking, optional: true
validates_presence_of :account_id,
:reminder_time,
:read,
:content
end
......@@ -5,7 +5,7 @@ class CreateNotifications < ActiveRecord::Migration[5.0]
t.integer :account_id, foreign_key: true, null: false
t.integer :schedule_id, foreign_key: true
t.integer :resource_schedule_id, foreign_key: true
t.integer :read
t.boolean :read
t.string :content
t.datetime :reminder_time
t.integer :reminder_email_sent
......
......@@ -145,7 +145,7 @@ ActiveRecord::Schema.define(version: 20171109134344) do
t.integer "account_id", null: false
t.integer "schedule_id"
t.integer "resource_schedule_id"
t.integer "read"
t.boolean "read"
t.string "content"
t.datetime "reminder_time"
t.integer "reminder_email_sent"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment