Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add thumbnail URL in print command #1031

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func printHandler(cmd *cobra.Command, args []string) {
OrderMethod: orderMethod,
}

bookmarks, err := deps.Database.GetBookmarks(cmd.Context(), searchOptions)
bookmarks, err := deps.Domains.Bookmarks.GetBookmarks(cmd.Context(), searchOptions)
if err != nil {
cError.Printf("Failed to get bookmarks: %v\n", err)
return
Expand Down
9 changes: 9 additions & 0 deletions internal/domains/bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ func (d *BookmarksDomain) GetBookmark(ctx context.Context, id model.DBID) (*mode
bookmark.HasEbook = d.HasEbook(&bookmark)
bookmark.HasArchive = d.HasArchive(&bookmark)

// Populate imageURL field
d.populateImageURL(&bookmark)

return &bookmark, nil
}

func (d *BookmarksDomain) populateImageURL(b *model.BookmarkDTO) {
if d.HasThumbnail(b) {
b.ImageURL = fmt.Sprintf("/bookmark/%d/thumb", b.ID)
}
}

func NewBookmarksDomain(deps *dependencies.Dependencies) *BookmarksDomain {
return &BookmarksDomain{
deps: deps,
Expand Down
26 changes: 26 additions & 0 deletions internal/domains/bookmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,30 @@
require.True(t, bookmark.HasArchive)
})
})

t.Run("populateImageURL", func(t *testing.T) {
t.Run("With Thumbnail", func(t *testing.T) {
bookmark := &model.BookmarkDTO{ID: 1}
domain.populateImageURL(bookmark)

Check failure on line 86 in internal/domains/bookmarks_test.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (ubuntu-latest)

domain.populateImageURL undefined (type *domains.BookmarksDomain has no field or method populateImageURL)

Check failure on line 86 in internal/domains/bookmarks_test.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (macos-latest)

domain.populateImageURL undefined (type *domains.BookmarksDomain has no field or method populateImageURL)
require.Equal(t, "/bookmark/1/thumb", bookmark.ImageURL)
})
t.Run("Without Thumbnail", func(t *testing.T) {
bookmark := &model.BookmarkDTO{ID: 2}
domain.populateImageURL(bookmark)

Check failure on line 91 in internal/domains/bookmarks_test.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (ubuntu-latest)

domain.populateImageURL undefined (type *domains.BookmarksDomain has no field or method populateImageURL)

Check failure on line 91 in internal/domains/bookmarks_test.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (macos-latest)

domain.populateImageURL undefined (type *domains.BookmarksDomain has no field or method populateImageURL)
require.Empty(t, bookmark.ImageURL)
})
})

t.Run("TestImageURLField", func(t *testing.T) {
t.Run("ImageURL is populated", func(t *testing.T) {
bookmark := &model.BookmarkDTO{ID: 1}
domain.populateImageURL(bookmark)

Check failure on line 99 in internal/domains/bookmarks_test.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (ubuntu-latest)

domain.populateImageURL undefined (type *domains.BookmarksDomain has no field or method populateImageURL)

Check failure on line 99 in internal/domains/bookmarks_test.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (macos-latest)

domain.populateImageURL undefined (type *domains.BookmarksDomain has no field or method populateImageURL)
require.Equal(t, "/bookmark/1/thumb", bookmark.ImageURL)
})
t.Run("ImageURL is empty", func(t *testing.T) {
bookmark := &model.BookmarkDTO{ID: 2}
domain.populateImageURL(bookmark)

Check failure on line 104 in internal/domains/bookmarks_test.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (ubuntu-latest)

domain.populateImageURL undefined (type *domains.BookmarksDomain has no field or method populateImageURL)

Check failure on line 104 in internal/domains/bookmarks_test.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (macos-latest)

domain.populateImageURL undefined (type *domains.BookmarksDomain has no field or method populateImageURL)
require.Empty(t, bookmark.ImageURL)
})
})
}
3 changes: 3 additions & 0 deletions internal/http/routes/api/v1/bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
return nil, model.ErrBookmarkNotFound
}

// Populate imageURL field
r.deps.Domains.Bookmarks.populateImageURL(bookmark)

Check failure on line 87 in internal/http/routes/api/v1/bookmarks.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (ubuntu-latest)

r.deps.Domains.Bookmarks.populateImageURL undefined (type model.BookmarksDomain has no field or method populateImageURL)

Check failure on line 87 in internal/http/routes/api/v1/bookmarks.go

View workflow job for this annotation

GitHub Actions / call-test / Go unit tests (macos-latest)

r.deps.Domains.Bookmarks.populateImageURL undefined (type model.BookmarksDomain has no field or method populateImageURL)

return bookmark, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/http/routes/api/v1/bookmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestUpdateBookmarkCache(t *testing.T) {
})
}

func TestReadableeBookmarkContent(t *testing.T) {
func TestReadableBookmarkContent(t *testing.T) {
logger := logrus.New()
ctx := context.TODO()

Expand All @@ -62,7 +62,7 @@ func TestReadableeBookmarkContent(t *testing.T) {
bookmark := testutil.GetValidBookmark()
_, err = deps.Database.SaveBookmarks(ctx, true, *bookmark)
require.NoError(t, err)
response := `{"ok":true,"message":{"content":"","html":""}}`
response := `{"ok":true,"message":{"content":"","html":"","imageURL":""}}`

t.Run("require authentication", func(t *testing.T) {
w := testutil.PerformRequest(g, "GET", "/1/readable")
Expand Down
Loading