fix: daily vani
This commit is contained in:
@@ -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),
|
// 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 {
|
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").
|
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 ""
|
return ""
|
||||||
}
|
}
|
||||||
if data, ok := raw["data"].(bson.M); ok {
|
return doc.Data.Title
|
||||||
if t, ok := data["title"].(string); ok {
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Mongo: random candidate sampling ---
|
// --- Mongo: random candidate sampling ---
|
||||||
|
|||||||
Reference in New Issue
Block a user