feat: implement mongo APIs

This commit is contained in:
Krispire Admin
2026-05-10 00:42:06 +05:30
parent b055b8ba0c
commit 3f09ea1fe5
4 changed files with 19 additions and 10 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ type EssaySummaryDoc struct {
func (r *EssayRepo) GetAll(ctx context.Context) ([]EssaySummaryDoc, error) {
opts := options.Find().
SetSort(bson.M{"group": 1, "order": 1}).
SetSort(bson.D{{Key: "group", Value: 1}, {Key: "order", Value: 1}}).
SetProjection(bson.M{"slug": 1, "title": 1, "year": 1, "group": 1})
cursor, err := r.col.Find(ctx, bson.M{}, opts)
if err != nil {
+6 -5
View File
@@ -34,17 +34,18 @@ type LetterDoc struct {
type LetterSummaryDoc struct {
ID bson.ObjectID `bson:"_id" json:"id"`
Slug string `bson:"slug" json:"slug"`
Recipients []string `bson:"recipients" json:"recipients"`
Recipients []string `bson:"recipients,omitempty" json:"recipients"`
RecipientDisplay string `bson:"recipientDisplay" json:"recipient_display"`
Date *string `bson:"date,omitempty" json:"date,omitempty"`
Year *int `bson:"year,omitempty" json:"year,omitempty"`
Month *int `bson:"month,omitempty" json:"month,omitempty"`
Day *int `bson:"day,omitempty" json:"day,omitempty"`
Location *string `bson:"location,omitempty" json:"location,omitempty"`
}
var letterSummaryProjection = bson.M{
"slug": 1, "recipients": 1, "recipientDisplay": 1,
"date": 1, "year": 1, "month": 1, "location": 1,
"date": 1, "year": 1, "month": 1, "day": 1, "location": 1,
}
func (r *LetterRepo) GetBySlug(ctx context.Context, slug string) (*LetterDoc, error) {
@@ -61,7 +62,7 @@ func (r *LetterRepo) GetBySlug(ctx context.Context, slug string) (*LetterDoc, er
func (r *LetterRepo) GetByYear(ctx context.Context, year int) ([]LetterSummaryDoc, error) {
opts := options.Find().
SetSort(bson.M{"month": 1, "day": 1}).
SetSort(bson.D{{Key: "month", Value: 1}, {Key: "day", Value: 1}}).
SetProjection(letterSummaryProjection)
cursor, err := r.col.Find(ctx, bson.M{"year": year}, opts)
if err != nil {
@@ -77,7 +78,7 @@ func (r *LetterRepo) GetByYear(ctx context.Context, year int) ([]LetterSummaryDo
func (r *LetterRepo) GetByRecipient(ctx context.Context, name string) ([]LetterSummaryDoc, error) {
opts := options.Find().
SetSort(bson.M{"year": 1, "month": 1, "day": 1}).
SetSort(bson.D{{Key: "year", Value: 1}, {Key: "month", Value: 1}, {Key: "day", Value: 1}}).
SetProjection(letterSummaryProjection)
cursor, err := r.col.Find(ctx, bson.M{"recipients": name}, opts)
if err != nil {
@@ -93,7 +94,7 @@ func (r *LetterRepo) GetByRecipient(ctx context.Context, name string) ([]LetterS
func (r *LetterRepo) GetByLocation(ctx context.Context, location string) ([]LetterSummaryDoc, error) {
opts := options.Find().
SetSort(bson.M{"year": 1, "month": 1, "day": 1}).
SetSort(bson.D{{Key: "year", Value: 1}, {Key: "month", Value: 1}, {Key: "day", Value: 1}}).
SetProjection(letterSummaryProjection)
cursor, err := r.col.Find(ctx, bson.M{"location": location}, opts)
if err != nil {
+4 -4
View File
@@ -96,7 +96,7 @@ func (r *TranscriptionRepo) GetBySlug(ctx context.Context, slug string) (*Transc
func (r *TranscriptionRepo) GetByYear(ctx context.Context, year int) ([]TranscriptionSummaryDoc, error) {
filter := bson.M{"year": year, "isPublished": true}
opts := options.Find().
SetSort(bson.M{"month": 1, "day": 1}).
SetSort(bson.D{{Key: "month", Value: 1}, {Key: "day", Value: 1}}).
SetProjection(transcriptionSummaryProjection)
cursor, err := r.col.Find(ctx, filter, opts)
if err != nil {
@@ -113,7 +113,7 @@ func (r *TranscriptionRepo) GetByYear(ctx context.Context, year int) ([]Transcri
func (r *TranscriptionRepo) GetByPlace(ctx context.Context, place string) ([]TranscriptionSummaryDoc, error) {
filter := bson.M{"place": place, "isPublished": true}
opts := options.Find().
SetSort(bson.M{"year": 1, "month": 1, "day": 1}).
SetSort(bson.D{{Key: "year", Value: 1}, {Key: "month", Value: 1}, {Key: "day", Value: 1}}).
SetProjection(transcriptionSummaryProjection)
cursor, err := r.col.Find(ctx, filter, opts)
if err != nil {
@@ -130,7 +130,7 @@ func (r *TranscriptionRepo) GetByPlace(ctx context.Context, place string) ([]Tra
func (r *TranscriptionRepo) GetByType(ctx context.Context, docType string) ([]TranscriptionSummaryDoc, error) {
filter := bson.M{"type": docType, "isPublished": true}
opts := options.Find().
SetSort(bson.M{"year": 1, "month": 1, "day": 1}).
SetSort(bson.D{{Key: "year", Value: 1}, {Key: "month", Value: 1}, {Key: "day", Value: 1}}).
SetProjection(transcriptionSummaryProjection)
cursor, err := r.col.Find(ctx, filter, opts)
if err != nil {
@@ -199,7 +199,7 @@ func (r *TranscriptionRepo) Count(ctx context.Context) (int64, error) {
func (r *TranscriptionRepo) GetAdjacent(ctx context.Context, slug string, year int) (*TranscriptionSummaryDoc, *TranscriptionSummaryDoc, error) {
filter := bson.M{"year": year, "isPublished": true}
opts := options.Find().
SetSort(bson.M{"month": 1, "day": 1}).
SetSort(bson.D{{Key: "month", Value: 1}, {Key: "day", Value: 1}}).
SetProjection(transcriptionSummaryProjection)
cursor, err := r.col.Find(ctx, filter, opts)
if err != nil {