This commit is contained in:
2026-05-12 01:13:01 +02:00
commit bf304e17c9
46 changed files with 4358 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
package customer
import (
"context"
"fmt"
"gorm.io/gorm"
)
type Profile struct {
ID int64
FirstName string
LastName string
Email string
}
type Service struct {
db *gorm.DB
prefix string
}
func NewService(db *gorm.DB, prefix string) *Service {
return &Service{db: db, prefix: prefix}
}
func (s *Service) GetByID(ctx context.Context, id int64) (*Profile, error) {
var profile Profile
query := fmt.Sprintf("SELECT id_customer AS id, firstname AS first_name, lastname AS last_name, email FROM %scustomer WHERE id_customer = ? LIMIT 1", s.prefix)
result := s.db.WithContext(ctx).Raw(query, id).Scan(&profile)
if result.Error != nil {
return nil, result.Error
}
if result.RowsAffected == 0 {
return nil, gorm.ErrRecordNotFound
}
return &profile, nil
}