Skip to content

STORY-142: Reading list (bookmark) API - #1202

Closed
devin-ai-integration[bot] wants to merge 2 commits into
masterfrom
devin/story-142-reading-list
Closed

devin-ai-integration[bot] wants to merge 2 commits into
masterfrom
devin/story-142-reading-list

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Summary

Backend half of STORY-142 — Reading list: save articles for later. Adds private per-user bookmarks: POST/DELETE /articles/{slug}/bookmark, GET /articles/bookmarked, and a bookmarked boolean on every Article JSON response. Implemented by mirroring the existing favorite feature.

Story

As a logged-in reader, I want to save articles to a private reading list, so I can come back to them later without making them public favorites.

Acceptance criteria covered by this PR (backend):

  • AC5: saves are private. There is no bookmark count anywhere, and no endpoint returns another user's bookmarks.
  • AC6: bookmark/unbookmark endpoints return the article with bookmarked. GET /articles/bookmarked?limit=&offset= returns the current user's list in the same shape as GET /articles, newest saved first. All three require auth (401 otherwise).
  • AC7: the existing suite still passes, and the new behavior has tests.
  • AC1–AC4 are UI and belong to the frontend PR.

API contract

No /api context path on this backend (the frontend interceptor adds the base URL).

Method Path Response
POST /articles/{slug}/bookmark 200 {"article": Article} with bookmarked: true. Idempotent. 404 for an unknown slug, 401 without a token
DELETE /articles/{slug}/bookmark 200 {"article": Article} with bookmarked: false. Idempotent. 404 / 401 as above
GET /articles/bookmarked?limit=20&offset=0 200 {"articles": Article[], "articlesCount": n}, only the current user's bookmarks, ordered by bookmark time DESC. 401 without a token

Every Article payload (single article, /articles, /articles/feed, /articles/bookmarked, favorite/unfavorite) now includes "bookmarked": boolean. It is true only for the authenticated user who saved the article and always false for anonymous requests. Auth is the existing Authorization: Token <jwt>.

What changed (by layer)

  • DB: V2__create_article_bookmarks.sql adds article_bookmarks(article_id, user_id, created_at, PK(article_id,user_id)) plus an index on (user_id, created_at). V1 is unchanged.
  • Domain (io.spring.core.bookmark): ArticleBookmark(articleId, userId, createdAt) and ArticleBookmarkRepository (save / find / remove). createdAt is set in Java (new DateTime()) and stored at millisecond resolution through the existing DateTimeHandler, so ordering does not depend on SQLite's second-resolution CURRENT_TIMESTAMP.
  • Infrastructure: ArticleBookmarkMapper(.xml) and MyBatisArticleBookmarkRepository. As with favorites, save does nothing if the row already exists.
  • Read side: ArticleBookmarksReadService(.xml) provides isUserBookmark, userBookmarks(ids, currentUser), userBookmarkedArticleIds(userId, page) and countUserBookmarks(userId).
    • The list query orders by created_at desc, rowid desc. The rowid tie-break keeps back-to-back saves in the same millisecond in a stable order.
    • Both the list and count queries join articles, so leftover bookmark rows for deleted articles are skipped. Article deletion doesn't clean up favorites either, so I didn't add cleanup for bookmarks.
  • ArticleQueryService:
    • New findBookmarkedArticles(User, Page). ArticleReadService.findArticles sorts by A.created_at desc, so the results are re-sorted back into bookmark order before being returned.
    • bookmarked is filled in both fillExtraInfo paths. That covers findById, findBySlug, findRecentArticles, findUserFeed and the cursor variants.
  • ArticleData: new private boolean bookmarked (after favoritesCount). The existing new ArticleData(...) calls in tests and TestHelper are updated. The GraphQL schema is unchanged.
  • API: new ArticleBookmarkApi (articles/{slug}/bookmark, POST/DELETE) and @GetMapping("bookmarked") in ArticlesApi. WebSecurityConfig adds GET /articles/bookmarked to the existing /articles/feed authenticated() rule, which comes before the /articles/** permitAll.

Test results

Full suite, ./gradlew clean test (run with JDK 11; the repo targets 11):

BUILD SUCCESSFUL
total=85 passed=85 failures=0 errors=0 skipped=0

New or extended test classes:

  • ArticleBookmarkApiTest (5): bookmark returns bookmarked=true, unbookmark returns false, unbookmarking an article that isn't saved still returns 200, 401 without a token, 404 for an unknown slug.
  • ArticlesApiTest (+2): GET /articles/bookmarked returns 200 with a token and 401 without one.
  • MyBatisArticleBookmarkRepositoryTest (3): save/find/remove, saving twice keeps the original createdAt, removing a missing row doesn't fail.
  • ArticleQueryServiceTest (+7):
    • ordering is newest saved first, both for back-to-back saves and for explicit timestamps, independent of article creation order
    • pagination and count
    • user B can't see user A's bookmarks
    • bookmarked is true only for the saver, and false for other users and anonymous requests, across findById/findBySlug/findRecentArticles/findUserFeed/cursor
    • favorited/favoritesCount are not affected
    • bookmarks of deleted articles are skipped

./gradlew bootRun sanity check: registered two users (alice, bob) via POST /users, and alice created two articles:

== POST bookmark first (alice)
{'slug': 'first-1793212052', 'bookmarked': True, 'favorited': False, 'favoritesCount': 0}
== POST bookmark second (alice)
{'slug': 'second-1793212052', 'bookmarked': True, 'favorited': False, 'favoritesCount': 0}
== POST bookmark second again (idempotent)
{'slug': 'second-1793212052', 'bookmarked': True, 'favorited': False, 'favoritesCount': 0}
== GET /articles/bookmarked (alice, newest saved first)
{'articlesCount': 2, 'articles': [('second-1793212052', True), ('first-1793212052', True)]}
== GET /articles/bookmarked?limit=1&offset=1 (alice)
{'articlesCount': 2, 'articles': [('first-1793212052', True)]}
== GET /articles/bookmarked (bob)
{'articlesCount': 0, 'articles': []}
== GET /articles/first (bob)
{'slug': 'first-1793212052', 'bookmarked': False, 'favorited': False, 'favoritesCount': 0}
== GET /articles/first (anonymous)
{'slug': 'first-1793212052', 'bookmarked': False, 'favorited': False, 'favoritesCount': 0}
== POST favorite first (alice) keeps bookmarked
{'slug': 'first-1793212052', 'bookmarked': True, 'favorited': True, 'favoritesCount': 1}
== DELETE bookmark first (alice)
{'slug': 'first-1793212052', 'bookmarked': False, 'favorited': True, 'favoritesCount': 1}
== DELETE bookmark first again (idempotent)
{'slug': 'first-1793212052', 'bookmarked': False, 'favorited': True, 'favoritesCount': 1}
== GET /articles/bookmarked (alice)
{'articlesCount': 1, 'articles': [('second-1793212052', True)]}
POST   /articles/first/bookmark (no token)   -> 401
DELETE /articles/first/bookmark (no token)   -> 401
GET    /articles/bookmarked (no token)       -> 401
POST   /articles/no-such-slug/bookmark       -> 404
DELETE /articles/no-such-slug/bookmark       -> 404

End-to-end verification (real frontend + this backend)

Ran locally: Spring Boot bootRun (JDK 11, SQLite) on :8080, and the Angular app from the frontend PR on :4200, with the API interceptor pointed at the local backend only for the run (not committed). Two users, ana and bob. Every STORY-142 acceptance criterion passed in the browser. Separate curl checks:

PASS: POST bookmark returns {article} bookmarked true (duplicate POST idempotent)
PASS: First page newest save sara, total 2 / second page eric, total 2
PASS: Bob list is empty while ana has two saves
PASS: anonymous and bob GET article -> bookmarked false
PASS: DELETE returns {article} bookmarked false; ana list drops to 1
PASS: Unauthenticated POST / DELETE /articles/{slug}/bookmark -> 401
PASS: Unauthenticated GET /articles/bookmarked -> 401

Seen during the run but not caused by this PR: anonymous GET /articles/{slug} returns favoritesCount: 0. On master, ArticleQueryService.findBySlug only fills extra info when user != null, so this is existing behavior and left unchanged.

Screenshots and the recording are on the frontend PR.

Related

Devin-Org: engineering

Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/545bdc3ad8b44f1aa50622bfb619a654
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/545bdc3ad8b44f1aa50622bfb619a654?variant=devin


Devin Review

Status Commit
⚪ Not started —

Run Devin Review

Enable auto-review to review your pull requests automatically.

Devin Review (Staging)


Devin Review

Co-Authored-By: Pedro Tabio <paltat@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +48 to +54
@GetMapping(path = "bookmarked")
public ResponseEntity getBookmarked(
@RequestParam(value = "offset", defaultValue = "0") int offset,
@RequestParam(value = "limit", defaultValue = "20") int limit,
@AuthenticationPrincipal User user) {
return ResponseEntity.ok(
articleQueryService.findBookmarkedArticles(user, new Page(offset, limit)));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🟡 Articles named bookmarked cannot be read

For an article with slug bookmarked, getBookmarked takes its GET route. Readers receive 401 or their reading list instead of the article.

Learn more

The existing article route accepts any slug at /articles/{slug}. Spring selects the exact /articles/bookmarked route ahead of that variable route. An article created with the title Bookmarked has that slug, so its established GET URL no longer serves the article.

Example: Alice creates an article titled Bookmarked. Bob opens /articles/bookmarked and gets a 401 without a token; with a token he sees his saved articles rather than Alice's article.

Recommended fix: Put the private reading-list endpoint at a non-colliding path, such as /user/bookmarks, and update its security matcher and clients. Alternatively, explicitly reserve the slug bookmarked during article creation and migration, with a plan for existing articles using it.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The collision is real, but I'm not changing it in this PR. The STORY-142 contract specifies GET /articles/bookmarked, and the Angular frontend is being built against that path in parallel. The existing GET /articles/feed already has the same issue with an article whose slug is feed. A follow-up could reserve the slugs feed and bookmarked (or add a suffix when one is generated) for both routes together. Leaving this open for the coordinator or a human to decide.

Co-Authored-By: Pedro Tabio <paltat@gmail.com>
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.

0 participants