✨ add mongodb/jwt
This commit is contained in:
13
app/core/api/repository/mongodb/collection/collection.go
Normal file
13
app/core/api/repository/mongodb/collection/collection.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package collection
|
||||
|
||||
import (
|
||||
"github.com/chenmingyong0423/go-mongox/v2"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
|
||||
// MustNewCollection creates a new Collection instance with the given name.
|
||||
func MustNewCollection[T any](svcCtx *svc.ServiceContext, collectionName string) *mongox.Collection[T] {
|
||||
collection := svcCtx.MongoClient.Collection(collectionName)
|
||||
return mongox.NewCollection[T](collection)
|
||||
}
|
28
app/core/api/repository/mongodb/init.go
Normal file
28
app/core/api/repository/mongodb/init.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package mongodb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
|
||||
)
|
||||
|
||||
// NewMongoDB initializes the MongoDB connection and returns the database object
|
||||
func NewMongoDB(uri string, username string, password string, authSource string, database string) *mongo.Database {
|
||||
client, err := mongo.Connect(options.Client().ApplyURI(uri).SetAuth(options.Credential{
|
||||
Username: username,
|
||||
Password: password,
|
||||
AuthSource: authSource,
|
||||
}))
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
err = client.Ping(context.Background(), readpref.Primary())
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
db := client.Database(database)
|
||||
return db
|
||||
}
|
11
app/core/api/repository/mongodb/model/comment_image.go
Normal file
11
app/core/api/repository/mongodb/model/comment_image.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "github.com/chenmingyong0423/go-mongox/v2"
|
||||
|
||||
type CommentImage struct {
|
||||
mongox.Model `bson:",inline"`
|
||||
TopicID string `bson:"topic_id"`
|
||||
CommentID string `bson:"comment_id"`
|
||||
UserID string `bson:"user_id"`
|
||||
Images []string `bson:"images"`
|
||||
}
|
Reference in New Issue
Block a user