Skip to content

Commit

Permalink
feat: Implement Jav Service Data Model and MongoDB Integration
Browse files Browse the repository at this point in the history
Here is a high-level summary of the commit in imperative bullet points:

- Fix critical issues with the Jav service's data model infrastructure by introducing a new `model` package and rebalancing the database connection setup.
- Enhance the Jav service's robustness with reconnect logic for the Mongo database.
- Add a custom `Actress` struct and a new `Movie` data structure to the Jav service's data model.
- Improve the overall scalability and reliability of the Jav service.
  • Loading branch information
Laisky committed Aug 8, 2024
1 parent 0478708 commit 1ac6f58
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/web/jav/model/actress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package model

import "go.mongodb.org/mongo-driver/bson/primitive"

type Actress struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"mongo_id"`
Name string `bson:"name" json:"name"`
NameEnglish string `bson:"name_english" json:"name_english"`
URL string `bson:"url" json:"url"`
}
20 changes: 20 additions & 0 deletions internal/web/jav/model/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package model is a package for defining the data model for the jav service.
package model

import (
"context"

"github.com/Laisky/errors/v2"

"github.com/Laisky/laisky-blog-graphql/library/db/mongo"
)

// NewJavDB create new db
func NewJavDB(ctx context.Context, info mongo.DialInfo) (db mongo.DB, err error) {
db, err = mongo.NewDB(ctx, info)
if err != nil {
return nil, errors.Wrap(err, "dial jav db")
}

return db, nil
}
12 changes: 12 additions & 0 deletions internal/web/jav/model/movies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package model

import "go.mongodb.org/mongo-driver/bson/primitive"

type Movice struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"mongo_id"`
ActressID primitive.ObjectID `bson:"actress_id" json:"actress_id"`
Description string `bson:"description" json:"description"`
ImgUrl string `bson:"img_url" json:"img_url"`
Name string `bson:"name" json:"name"`
Tags []string `bson:"tags" json:"tags"`
}
1 change: 1 addition & 0 deletions library/db/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (d *db) runReconnectCheck(ctx context.Context) {
time.Sleep(3 * time.Second)
continue
}

log.Logger.Info("success reconnect to db", zap.String("db", d.diaInfo.Addr))
}
}
Expand Down

0 comments on commit 1ac6f58

Please sign in to comment.