API for adding entries - #257
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an authenticated API surface for creating Entry records, backed by user-managed API tokens, plus a docs endpoint and supporting tests/docs. This fits into the app by extending the existing Entries domain model with an API authentication layer and a small UI for token lifecycle management.
Changes:
- Introduces
ApiTokenmodel + DB table, plus a web UI (/api_tokens) for creating/listing/deleting tokens. - Adds
POST /api/entries(Bearer token auth) andGET /api/docs(public) with accompanying specs and documentation artifacts. - Enforces
Entrymodel validation requiringdate(with the API defaulting it to today when omitted/blank).
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/models/entry_spec.rb | Adds validation coverage for Entry#date presence. |
| spec/models/api_token_spec.rb | Adds model specs for token generation/digesting, uniqueness, and authentication usage tracking. |
| spec/controllers/api/entries_spec.rb | Adds controller specs for API entry creation flows, defaults, and auth behavior. |
| spec/controllers/api/docs_spec.rb | Adds spec ensuring API docs are publicly retrievable as markdown. |
| spec/controllers/api_tokens_spec.rb | Adds controller/view specs for token UI behavior (scoping + one-time token reveal). |
| docs/postman_collection.json | Adds a Postman collection for exercising the API endpoints. |
| docs/api.md | Adds end-user API documentation and examples. |
| db/schema.rb | Reflects new api_tokens table and FK. |
| db/migrate/20260806010631_create_api_tokens.rb | Creates api_tokens table and indexes. |
| config/routes.rb | Adds /api/* routes and api_tokens resource routes. |
| app/views/layouts/application.html.haml | Adds “API Tokens” nav link. |
| app/views/api_tokens/new.html.haml | Adds token creation page. |
| app/views/api_tokens/index.html.haml | Adds token list + one-time plaintext token display. |
| app/views/api_tokens/_form.html.haml | Adds token creation form partial. |
| app/models/user.rb | Adds has_many :api_tokens. |
| app/models/entry.rb | Adds validates :date, presence: true. |
| app/models/api_token.rb | Implements token generation, digesting, authentication, and usage tracking. |
| app/controllers/api/entries_controller.rb | Implements authenticated API endpoint for creating entries with category/tag helpers and validation errors. |
| app/controllers/api/docs_controller.rb | Serves docs/api.md as text/markdown. |
| app/controllers/api/base_controller.rb | Adds API token authentication + standard JSON error responses. |
| app/controllers/api_tokens_controller.rb | Implements token UI controller actions (index/new/create/destroy). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
travisdock
force-pushed
the
api-for-entries
branch
from
August 7, 2026 12:17
1ce6884 to
c8020e7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated no new comments.
Suppressed comments (2)
app/controllers/api_tokens_controller.rb:29
- This rescue treats every RecordNotUnique as a name conflict, but the table also has a unique index on token_digest. If the exception comes from token_digest (or another constraint), the UI will show a misleading "name has already been taken" error. Consider distinguishing the constraint (or at least checking whether the name already exists) and otherwise adding a generic retryable error.
rescue ActiveRecord::RecordNotUnique
@api_token.errors.add(:name, :taken)
render :new, status: :unprocessable_entity
end
docs/api.md:67
- The example error message misspells the category name ("Grocries"). This makes the docs harder to follow and conflicts with the "Groceries" examples elsewhere.
"message": "No category named \"Grocries\" found for this user.",
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.