From 47b3a6d96ef638d9d875870371a8bec063ee039f Mon Sep 17 00:00:00 2001 From: Krispire Admin Date: Sat, 11 Jul 2026 01:13:34 +0530 Subject: [PATCH] fix: daily vani --- internal/repository/vani_repo.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/repository/vani_repo.go b/internal/repository/vani_repo.go index 5315c99..8fce91e 100644 --- a/internal/repository/vani_repo.go +++ b/internal/repository/vani_repo.go @@ -88,19 +88,20 @@ func (r *VaniRepo) Insert(ctx context.Context, pick *model.VaniPick) error { } // 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. +// or "" if unknown. Used to label a prose pick with its book name. Decoding into +// a typed struct avoids the bson.M-nested-doc pitfall (nested documents decode +// as bson.D, so a `raw["data"].(bson.M)` assertion would silently fail). func (r *VaniRepo) BookTitle(ctx context.Context, book string) string { - var raw bson.M + var doc struct { + Data struct { + Title string `bson:"title"` + } `bson:"data"` + } if err := r.mongo.Collection("book_meta"). - FindOne(ctx, bson.D{{Key: "book", Value: book}}).Decode(&raw); err != nil { + FindOne(ctx, bson.D{{Key: "book", Value: book}}).Decode(&doc); err != nil { return "" } - if data, ok := raw["data"].(bson.M); ok { - if t, ok := data["title"].(string); ok { - return t - } - } - return "" + return doc.Data.Title } // --- Mongo: random candidate sampling ---