Skip to content

Commit

Permalink
Init controller & JSON route for unseen popups
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Sep 12, 2023
1 parent be7abb4 commit 87b366f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions app/controllers/news_popups_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class NewsPopupsController < ApplicationController
def index
respond_to do |format|
format.json { render json: unseen_news_popups }
end
end

private

def unseen_news_popups
HasSeenNewsPopup
.where(user: current_user)
.left_outer_joins(:news_popup)
.select('news_popups.active', 'news_popups.name')
.where(news_popups: { active: true })
end
end
4 changes: 2 additions & 2 deletions app/models/has_seen_news_popup.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class HasSeenNewsPopup < ApplicationRecord
belongs_to :user_id
belongs_to :news_popup_id
belongs_to :user
belongs_to :news_popup
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@
to: 'erdbeere#fill_realizations_select',
as: 'fill_realizations_select'

# News popups routes
resources :news_popups, only: [:index]

# main routes

Expand Down

0 comments on commit 87b366f

Please sign in to comment.