From d29eb5d844cde5f27e7466e9355dd889edac633f Mon Sep 17 00:00:00 2001 From: Krispire Admin Date: Sat, 11 Jul 2026 00:44:08 +0530 Subject: [PATCH] feat: daily vani --- internal/repository/vani_repo.go | 16 ++++++++++++++++ internal/service/vani_service.go | 15 ++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/internal/repository/vani_repo.go b/internal/repository/vani_repo.go index 0dc9795..5315c99 100644 --- a/internal/repository/vani_repo.go +++ b/internal/repository/vani_repo.go @@ -87,6 +87,22 @@ func (r *VaniRepo) Insert(ctx context.Context, pick *model.VaniPick) error { return nil } +// BookTitle resolves a book code to its display title (from book_meta.data.title), +// or "" if unknown. Used to label a prose pick with its book name. +func (r *VaniRepo) BookTitle(ctx context.Context, book string) string { + var raw bson.M + if err := r.mongo.Collection("book_meta"). + FindOne(ctx, bson.D{{Key: "book", Value: book}}).Decode(&raw); err != nil { + return "" + } + if data, ok := raw["data"].(bson.M); ok { + if t, ok := data["title"].(string); ok { + return t + } + } + return "" +} + // --- Mongo: random candidate sampling --- // excludeIDs turns hex _id strings into a $nin ObjectID array. diff --git a/internal/service/vani_service.go b/internal/service/vani_service.go index 8d7519d..bd44242 100644 --- a/internal/service/vani_service.go +++ b/internal/service/vani_service.go @@ -87,7 +87,7 @@ func (s *VaniService) choose(ctx context.Context, exclude map[string][]string, d } case "prose": if p, err := s.repo.SampleProse(ctx, exclude["prose"]); err == nil && p != nil { - return prosePick(p, day) + return prosePick(p, s.repo.BookTitle(ctx, p.Book), day) } case "transcript": if t, err := s.repo.SampleTranscript(ctx, exclude["transcript"]); err == nil && t != nil { @@ -120,7 +120,7 @@ func versePick(v *repository.VerseDoc, day time.Time) *model.VaniPick { } } -func prosePick(p *repository.ProseChapterDoc, day time.Time) *model.VaniPick { +func prosePick(p *repository.ProseChapterDoc, bookTitle string, day time.Time) *model.VaniPick { first := "" if len(p.Paragraphs) > 0 { first = p.Paragraphs[0] @@ -130,11 +130,12 @@ func prosePick(p *repository.ProseChapterDoc, day time.Time) *model.VaniPick { Kind: "prose", RefID: "prose:" + p.ID.Hex(), Payload: model.VaniPayload{ - Kind: "prose", - Label: "Chapter", - Title: p.Title, - Subtitle: excerpt(first, 140), - Href: proseURL(p.Book, p.Volume, p.Type, p.Slug), + Kind: "prose", + Label: "Chapter", + Title: p.Title, + Subtitle: excerpt(first, 140), + Href: proseURL(p.Book, p.Volume, p.Type, p.Slug), + BookTitle: bookTitle, }, } }