+
+ def read_notification(%{assigns: %{user: user}} = conn, %{"id" => notification_id}) do
+ with {:ok, notification} <- Notification.read_one(user, notification_id) do
+ conn
+ |> put_view(NotificationView)
+ |> render("show.json", %{notification: notification, for: user})
+ else
+ {:error, message} ->
+ conn
+ |> put_status(:bad_request)
+ |> json(%{"error" => message})
+ end
+ end
+
+ def read_notification(%{assigns: %{user: user}} = conn, %{"max_id" => max_id}) do
+ with notifications <- Notification.set_read_up_to(user, max_id) do
+ notifications = Enum.take(notifications, 80)
+
+ conn
+ |> put_view(NotificationView)
+ |> render("index.json", %{notifications: notifications, for: user})
+ end
+ end