36 lines
883 B
Go
36 lines
883 B
Go
package repositories
|
|
|
|
import (
|
|
"GoMembership/internal/models"
|
|
// "GoMembership/pkg/errors"
|
|
"database/sql"
|
|
)
|
|
|
|
type ConsentRepository interface {
|
|
CreateConsent(consent *models.Consent) (int64, error)
|
|
}
|
|
|
|
type consentRepository struct {
|
|
db *sql.DB
|
|
}
|
|
|
|
func NewConsentRepository(db *sql.DB) ConsentRepository {
|
|
return &consentRepository{db}
|
|
}
|
|
|
|
func (repo *consentRepository) CreateConsent(consent *models.Consent) (int64, error) {
|
|
|
|
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
|
|
}
|
|
lastInsertID, err := result.LastInsertId()
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
|
|
return lastInsertID, err
|
|
}
|