switched to gorm..
This commit is contained in:
@@ -2,8 +2,7 @@ package repositories
|
||||
|
||||
import (
|
||||
"GoMembership/internal/models"
|
||||
// "GoMembership/pkg/errors"
|
||||
"database/sql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConsentRepository interface {
|
||||
@@ -11,25 +10,18 @@ type ConsentRepository interface {
|
||||
}
|
||||
|
||||
type consentRepository struct {
|
||||
db *sql.DB
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewConsentRepository(db *sql.DB) ConsentRepository {
|
||||
func NewConsentRepository(db *gorm.DB) ConsentRepository {
|
||||
return &consentRepository{db}
|
||||
}
|
||||
|
||||
func (repo *consentRepository) CreateConsent(consent *models.Consent) (int64, error) {
|
||||
result := repo.db.Create(consent)
|
||||
|
||||
query := "INSERT INTO consents (user_id, first_name, last_name, email, created_at, updated_at, consent_type) VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||
result, err := repo.db.Exec(query, consent.UserID, consent.FirstName, consent.LastName, consent.Email, consent.CreatedAt, consent.UpdatedAt, consent.ConsentType)
|
||||
if err != nil {
|
||||
|
||||
return -1, err
|
||||
if result.Error != nil {
|
||||
return 0, result.Error
|
||||
}
|
||||
lastInsertID, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
return lastInsertID, err
|
||||
return consent.ID, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user