feat: vani of the day edit
This commit is contained in:
@@ -217,6 +217,63 @@ func (r *VaniRepo) oneByHex(ctx context.Context, coll, hex string, out interface
|
||||
return nil
|
||||
}
|
||||
|
||||
// TranscriptBySlug loads a lecture by its URL slug.
|
||||
//
|
||||
// Search cannot do this: the slug is not an indexed field, so querying
|
||||
// "720720sb-london" matches on tokens like "london" and returns whatever else
|
||||
// mentions it. Resolving the slug directly is the only reliable way to pin a
|
||||
// specific item someone already has the URL for.
|
||||
func (r *VaniRepo) TranscriptBySlug(ctx context.Context, slug string) (*TranscriptionDoc, error) {
|
||||
var t TranscriptionDoc
|
||||
err := r.mongo.Collection("transcriptions").
|
||||
FindOne(ctx, bson.D{{Key: "slug", Value: slug}}).Decode(&t)
|
||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||
return nil, ErrVaniRefNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("transcript by slug: %w", err)
|
||||
}
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
// ProseBySlug loads a prose chapter by book and slug.
|
||||
func (r *VaniRepo) ProseBySlug(ctx context.Context, book, slug string) (*ProseChapterDoc, error) {
|
||||
var p ProseChapterDoc
|
||||
err := r.mongo.Collection("prose_chapters").FindOne(ctx, bson.D{
|
||||
{Key: "book", Value: book},
|
||||
{Key: "slug", Value: slug},
|
||||
}).Decode(&p)
|
||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||
return nil, ErrVaniRefNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prose by slug: %w", err)
|
||||
}
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
// VerseByRef loads a verse by its book/division/chapter/verse coordinates,
|
||||
// which is what a verse URL carries.
|
||||
func (r *VaniRepo) VerseByRef(ctx context.Context, book string, division *string, chapter, verse int) (*VerseDoc, error) {
|
||||
filter := bson.D{
|
||||
{Key: "book", Value: book},
|
||||
{Key: "chapter", Value: chapter},
|
||||
{Key: "verse", Value: verse},
|
||||
}
|
||||
if division != nil && *division != "" {
|
||||
filter = append(filter, bson.E{Key: "division", Value: *division})
|
||||
}
|
||||
var v VerseDoc
|
||||
err := r.mongo.Collection("verses").FindOne(ctx, filter).Decode(&v)
|
||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||
return nil, ErrVaniRefNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("verse by ref: %w", err)
|
||||
}
|
||||
return &v, nil
|
||||
}
|
||||
|
||||
// VerseByHex / ProseByHex / TranscriptByHex load a specific item an admin has
|
||||
// chosen. The payload is then built by the same builders the random picker
|
||||
// uses, so a pinned pick renders identically to an automatic one.
|
||||
|
||||
Reference in New Issue
Block a user