Today's ticket summary for the support desk
Ruby · Rails · intermediate · modification
Adds the endpoint behind the new "Today" tile on the support desk's wall screen. `Ticket` (`app/models/ticket.rb`) gets two scopes, `opened_on(date)` and `resolved_on(date)`, which turn a date into that day's range in the app's time zone with `in_time_zone.all_day` and filter `created_at` or `resolved_at` on it. The new `DailySummariesController#show` (`app/controllers/daily_summaries_controller.rb`) takes today's date and returns it with the two counts; `config/routes.rb` adds `resource :daily_summary, only: :show`. `test/controllers/daily_summaries_controller_test.rb` (new) adds integration tests with `travel_to`: a day with tickets opened and resolved around it, an empty day, and the request without a token.
Ruby 4.0, Rails 8.1 JSON API (`ApplicationController < ActionController::API`), SQLite in development and test, PostgreSQL 16 in production; nothing in this change depends on the database. Existing and unchanged: `config.time_zone = "Europe/Berlin"`, and Active Record keeps its default of storing timestamps in UTC; the production containers and CI run with the process time zone unset, so the operating system clock is UTC there, while developers' laptops are on Berlin time. `ApplicationController` includes the app's `Authentication` concern, whose `before_action :require_authentication` reads the `Authorization: Bearer <token>` header with `authenticate_with_http_token`, looks the agent up with `User.find_by(api_token: token)` (`users.api_token` is `null: false` with a unique index, generated by `has_secure_token`), answers 401 when the header is missing or the token matches no user, and otherwise sets `Current.user`; the app is the desk's single-tenant internal tool, so there is no per-account scoping. The `tickets` table has `subject` (`null: false`), `created_at`, and `resolved_at` (nullable: `nil` while the ticket is open, the time of resolution otherwise, cleared when a ticket is reopened), with indexes on `created_at` and `resolved_at`. The wall screen (shipped separately) polls this endpoint every minute and shows the three fields as they come.
Requirements
- `GET /daily_summary` (new) returns today's numbers for the support desk's wall screen as JSON: `date` (today, `YYYY-MM-DD`), `opened` (tickets whose `created_at` falls on today) and `resolved` (tickets whose `resolved_at` falls on today). A day with no tickets reports zeros.
- "Today" is the current calendar date in the desk's time zone, Europe/Berlin (`config.time_zone`), and a ticket falls on a day when its timestamp, seen in Berlin time, is on that date: a day runs from 00:00 to the end of 23:59:59 Berlin time, including the 23- and 25-hour days when the clocks change.
- The desk works around the clock: the night shift reads the screen after midnight, and from 00:00 Berlin time it must show the new day.
- Every signed-in agent may read the summary; a request without a valid token answers 401. Unchanged: `GET /tickets` keeps its behaviour.
Files touched
- config/routes.rb
- app/models/ticket.rb
- app/controllers/daily_summaries_controller.rb
- test/controllers/daily_summaries_controller_test.rb