forked from exercism/exercism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notification API responding from the DB
- Loading branch information
1 parent
cb1d774
commit dc67dad
Showing
8 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,28 @@ | ||
#requiring here doesn't feel right | ||
require_relative '../helpers/fuzzy_time_helper' | ||
|
||
class NotificationsPresenter | ||
include Sinatra::FuzzyTimeHelper | ||
|
||
def initialize(notifications) | ||
@notifications = transform(notifications) | ||
end | ||
|
||
def to_json | ||
@notifications.to_json | ||
end | ||
|
||
def transform(notifications) | ||
notifications.map { |notification| | ||
{ | ||
id: notification.id, | ||
kind: notification.kind, | ||
read: notification.read, | ||
link: notification.link, | ||
from: notification.from, | ||
date: notification.at.to_time.to_i, | ||
humanReadableDate: ago(notification.at), | ||
} | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 1,16 @@ | ||
class Notification | ||
include Mongoid::Document | ||
|
||
field :re, as: :regarding, type: String | ||
field :r, as: :read, type: Boolean, default: false | ||
field :l, as: :link, type: String | ||
field :f, as: :from, type: String | ||
field :at, type: Time, default: ->{ Time.now.utc } | ||
|
||
belongs_to :user | ||
|
||
def self.recent_for_user(user) | ||
where(user: user).limit(100).descending(:at) | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,5 @@ | ||
class Dispatch | ||
def self.notifications_for_user(user) | ||
Notification.recent_for_user(user) | ||
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