switched to gorm..

This commit is contained in:
$(pass /github/name)
2024-07-10 14:22:56 +02:00
parent 87e9f71ceb
commit 6ac5491053
27 changed files with 368 additions and 283 deletions

View File

@@ -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
}