Repository navigation
STORY-142: Reading list (bookmark) API - #1202
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Pedro Tabio <paltat@gmail.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| @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))); |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
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>
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 abookmarkedboolean 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):
bookmarked.GET /articles/bookmarked?limit=&offset=returns the current user's list in the same shape asGET /articles, newest saved first. All three require auth (401 otherwise).API contract
No
/apicontext path on this backend (the frontend interceptor adds the base URL).POST/articles/{slug}/bookmark{"article": Article}withbookmarked: true. Idempotent. 404 for an unknown slug, 401 without a tokenDELETE/articles/{slug}/bookmark{"article": Article}withbookmarked: false. Idempotent. 404 / 401 as aboveGET/articles/bookmarked?limit=20&offset=0{"articles": Article[], "articlesCount": n}, only the current user's bookmarks, ordered by bookmark time DESC. 401 without a tokenEvery 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 existingAuthorization: Token <jwt>.What changed (by layer)
V2__create_article_bookmarks.sqladdsarticle_bookmarks(article_id, user_id, created_at, PK(article_id,user_id))plus an index on(user_id, created_at). V1 is unchanged.io.spring.core.bookmark):ArticleBookmark(articleId, userId, createdAt)andArticleBookmarkRepository(save / find / remove).createdAtis set in Java (new DateTime()) and stored at millisecond resolution through the existingDateTimeHandler, so ordering does not depend on SQLite's second-resolutionCURRENT_TIMESTAMP.ArticleBookmarkMapper(.xml)andMyBatisArticleBookmarkRepository. As with favorites,savedoes nothing if the row already exists.ArticleBookmarksReadService(.xml)providesisUserBookmark,userBookmarks(ids, currentUser),userBookmarkedArticleIds(userId, page)andcountUserBookmarks(userId).created_at desc, rowid desc. Therowidtie-break keeps back-to-back saves in the same millisecond in a stable order.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:findBookmarkedArticles(User, Page).ArticleReadService.findArticlessorts byA.created_at desc, so the results are re-sorted back into bookmark order before being returned.bookmarkedis filled in bothfillExtraInfopaths. That coversfindById,findBySlug,findRecentArticles,findUserFeedand the cursor variants.ArticleData: newprivate boolean bookmarked(afterfavoritesCount). The existingnew ArticleData(...)calls in tests andTestHelperare updated. The GraphQL schema is unchanged.ArticleBookmarkApi(articles/{slug}/bookmark, POST/DELETE) and@GetMapping("bookmarked")inArticlesApi.WebSecurityConfigaddsGET /articles/bookmarkedto the existing/articles/feedauthenticated()rule, which comes before the/articles/**permitAll.Test results
Full suite,
./gradlew clean test(run with JDK 11; the repo targets 11):New or extended test classes:
ArticleBookmarkApiTest(5): bookmark returnsbookmarked=true, unbookmark returnsfalse, unbookmarking an article that isn't saved still returns 200, 401 without a token, 404 for an unknown slug.ArticlesApiTest(+2):GET /articles/bookmarkedreturns 200 with a token and 401 without one.MyBatisArticleBookmarkRepositoryTest(3): save/find/remove, saving twice keeps the originalcreatedAt, removing a missing row doesn't fail.ArticleQueryServiceTest(+7):bookmarkedis true only for the saver, and false for other users and anonymous requests, acrossfindById/findBySlug/findRecentArticles/findUserFeed/cursorfavorited/favoritesCountare not affected./gradlew bootRunsanity check: registered two users (alice, bob) viaPOST /users, and alice created two articles: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:Seen during the run but not caused by this PR: anonymous
GET /articles/{slug}returnsfavoritesCount: 0. Onmaster,ArticleQueryService.findBySlugonly fills extra info whenuser != 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