mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Add Chapters for Galleries (#3289)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package gallery
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/models/json"
|
||||
@@ -9,6 +10,10 @@ import (
|
||||
"github.com/stashapp/stash/pkg/studio"
|
||||
)
|
||||
|
||||
type ChapterFinder interface {
|
||||
FindByGalleryID(ctx context.Context, galleryID int) ([]*models.GalleryChapter, error)
|
||||
}
|
||||
|
||||
// ToBasicJSON converts a gallery object into its JSON object equivalent. It
|
||||
// does not convert the relationships to other objects.
|
||||
func ToBasicJSON(gallery *models.Gallery) (*jsonschema.Gallery, error) {
|
||||
@@ -58,6 +63,30 @@ func GetStudioName(ctx context.Context, reader studio.Finder, gallery *models.Ga
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// GetGalleryChaptersJSON returns a slice of GalleryChapter JSON representation
|
||||
// objects corresponding to the provided gallery's chapters.
|
||||
func GetGalleryChaptersJSON(ctx context.Context, chapterReader ChapterFinder, gallery *models.Gallery) ([]jsonschema.GalleryChapter, error) {
|
||||
galleryChapters, err := chapterReader.FindByGalleryID(ctx, gallery.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting gallery chapters: %v", err)
|
||||
}
|
||||
|
||||
var results []jsonschema.GalleryChapter
|
||||
|
||||
for _, galleryChapter := range galleryChapters {
|
||||
galleryChapterJSON := jsonschema.GalleryChapter{
|
||||
Title: galleryChapter.Title,
|
||||
ImageIndex: galleryChapter.ImageIndex,
|
||||
CreatedAt: json.JSONTime{Time: galleryChapter.CreatedAt.Timestamp},
|
||||
UpdatedAt: json.JSONTime{Time: galleryChapter.UpdatedAt.Timestamp},
|
||||
}
|
||||
|
||||
results = append(results, galleryChapterJSON)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func GetIDs(galleries []*models.Gallery) []int {
|
||||
var results []int
|
||||
for _, gallery := range galleries {
|
||||
|
||||
Reference in New Issue
Block a user