Update MongoDB Driver and Configuration for Company Entities

- Updated the MongoDB driver from v1.17.4 to v2.3.0, ensuring compatibility with the latest features and improvements.
- Refactored company-related entity and repository files to utilize the new driver, replacing `primitive.ObjectID` with `bson.ObjectID` for ID handling.
- Adjusted the configuration in `.drone.yml` to include the `main` branch in the trigger settings, enhancing CI/CD pipeline flexibility.
This commit is contained in:
n.nakhostin
2025-09-09 18:53:39 +03:30
parent 57c29dc58f
commit 5d721705b7
24 changed files with 64 additions and 130 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ package company
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// CompanyStatus represents company account status
@@ -66,7 +66,7 @@ type Company struct {
// SetID sets the company ID (implements IDSetter interface)
func (c *Company) SetID(id string) {
c.ID, _ = primitive.ObjectIDFromHex(id)
c.ID, _ = bson.ObjectIDFromHex(id)
}
// GetID returns the company ID (implements IDGetter interface)
+1 -1
View File
@@ -8,7 +8,7 @@ import (
orm "tm/pkg/mongo"
"tm/pkg/response"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)
// Repository defines the interface for company data operations
+2 -2
View File
@@ -3,7 +3,7 @@ package company_category
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
type Category struct {
@@ -17,7 +17,7 @@ type Category struct {
// SetID sets the category ID (implements IDSetter interface)
func (c *Category) SetID(id string) {
c.ID, _ = primitive.ObjectIDFromHex(id)
c.ID, _ = bson.ObjectIDFromHex(id)
}
// GetID returns the category ID (implements IDGetter interface)
+3 -4
View File
@@ -8,8 +8,7 @@ import (
orm "tm/pkg/mongo"
"tm/pkg/response"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// Repository defines the interface for category data operations
@@ -99,9 +98,9 @@ func (r *categoryRepository) GetByID(ctx context.Context, id string) (*Category,
// GetByIDs retrieves categories by IDs
func (r *categoryRepository) GetByIDs(ctx context.Context, ids []string) ([]Category, error) {
objectIDs := make([]primitive.ObjectID, len(ids))
objectIDs := make([]bson.ObjectID, len(ids))
for i, id := range ids {
objectID, err := primitive.ObjectIDFromHex(id)
objectID, err := bson.ObjectIDFromHex(id)
if err != nil {
return nil, err
}
+2 -2
View File
@@ -3,7 +3,7 @@ package customer
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// CustomerStatus represents customer account status
@@ -43,7 +43,7 @@ type Customer struct {
// SetID sets the customer ID (implements IDSetter interface)
func (c *Customer) SetID(id string) {
c.ID, _ = primitive.ObjectIDFromHex(id)
c.ID, _ = bson.ObjectIDFromHex(id)
}
// GetID returns the customer ID (implements IDGetter interface)
+1 -1
View File
@@ -8,7 +8,7 @@ import (
orm "tm/pkg/mongo"
"tm/pkg/response"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)
// Repository defines the interface for customer data operations
+2 -2
View File
@@ -11,7 +11,7 @@ import (
"tm/pkg/authorization"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"golang.org/x/crypto/bcrypt"
)
@@ -562,7 +562,7 @@ func (s *customerService) RefreshToken(ctx context.Context, refreshToken string)
}
// Get customer information
customerID, err := primitive.ObjectIDFromHex(validationResult.Claims.UserID)
customerID, err := bson.ObjectIDFromHex(validationResult.Claims.UserID)
if err != nil {
s.logger.Error("Failed to parse customer ID from token", map[string]interface{}{
"error": err.Error(),
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"tm/pkg/logger"
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/bson"
driver "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
driver "go.mongodb.org/mongo-driver/v2/mongo"
)
// FeedbackRepository interface defines feedback data access methods
+2 -2
View File
@@ -4,7 +4,7 @@ import (
"time"
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// Inquiry status constants
@@ -35,7 +35,7 @@ type Inquiry struct {
}
func (i *Inquiry) SetID(id string) {
i.ID, _ = primitive.ObjectIDFromHex(id)
i.ID, _ = bson.ObjectIDFromHex(id)
}
func (i *Inquiry) GetID() string {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
orm "tm/pkg/mongo"
"tm/pkg/response"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)
// Repository defines methods for inquiry data access
+2 -2
View File
@@ -7,8 +7,8 @@ import (
orm "tm/pkg/mongo"
"tm/pkg/response"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
)
// TenderRepository interface defines tender data access methods
+2 -3
View File
@@ -7,8 +7,7 @@ import (
"tm/pkg/logger"
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// Repository defines the interface for tender approval data operations
@@ -214,7 +213,7 @@ func (r *tenderApprovalRepository) GetByIDs(ctx context.Context, ids []string) (
// Convert string IDs to ObjectIDs for MongoDB query
objectIDs := make([]interface{}, len(ids))
for i, id := range ids {
objectID, err := primitive.ObjectIDFromHex(id)
objectID, err := bson.ObjectIDFromHex(id)
if err != nil {
r.logger.Warn("Invalid tender approval ID format", map[string]interface{}{
"id": id,
+2 -2
View File
@@ -3,7 +3,7 @@ package user
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// UserRole represents user roles in the system
@@ -44,7 +44,7 @@ type User struct {
// SetID sets the user ID (implements IDSetter interface)
func (u *User) SetID(id string) {
u.ID, _ = primitive.ObjectIDFromHex(id)
u.ID, _ = bson.ObjectIDFromHex(id)
}
// GetID returns the user ID (implements IDGetter interface)
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"tm/pkg/response"
"github.com/labstack/echo/v4"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// AuthMiddleware validates JWT access tokens and extracts user information
@@ -44,7 +44,7 @@ func (h *Handler) AuthMiddleware() echo.MiddlewareFunc {
}
// Extract user information from token
userID, err := primitive.ObjectIDFromHex(validationResult.Claims.UserID)
userID, err := bson.ObjectIDFromHex(validationResult.Claims.UserID)
if err != nil {
h.logger.Error("Failed to parse user ID from token", map[string]interface{}{
"error": err.Error(),
+1 -1
View File
@@ -8,7 +8,7 @@ import (
orm "tm/pkg/mongo"
"tm/pkg/response"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)
// Repository defines methods for user data access
+2 -2
View File
@@ -9,7 +9,7 @@ import (
"tm/pkg/logger"
"tm/pkg/response"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"golang.org/x/crypto/bcrypt"
)
@@ -368,7 +368,7 @@ func (s *userService) RefreshToken(ctx context.Context, refreshToken string) (*A
}
// Get user information
userID, err := primitive.ObjectIDFromHex(validationResult.Claims.UserID)
userID, err := bson.ObjectIDFromHex(validationResult.Claims.UserID)
if err != nil {
s.logger.Error("Failed to parse user ID from token", map[string]interface{}{
"error": err.Error(),