Skip to content

API for adding entries - #257

Merged
travisdock merged 1 commit into
mainfrom
api-for-entries
Aug 9, 2026
Merged

travisdock merged 1 commit into
mainfrom
api-for-entries

Conversation

@travisdock

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ApiToken model + DB table, plus a web UI (/api_tokens) for creating/listing/deleting tokens.
  • Adds POST /api/entries (Bearer token auth) and GET /api/docs (public) with accompanying specs and documentation artifacts.
  • Enforces Entry model validation requiring date (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.

Comment thread db/migrate/20260806010631_create_api_tokens.rb
Comment thread app/models/api_token.rb

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.",

@travisdock
travisdock merged commit ba2bd37 into main Aug 9, 2026
2 checks passed
@travisdock
travisdock deleted the api-for-entries branch August 9, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants