feat: add api
docker-publish / publish (push) Failing after 14m14s

This commit is contained in:
Nuxgrid
2026-07-27 16:06:19 +02:00
parent 8397a4470f
commit 6b4274d12b
46 changed files with 3922 additions and 0 deletions
@@ -0,0 +1,57 @@
package leads
import (
"errors"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// GormStore : Store adossé à PostgreSQL via GORM.
type GormStore struct {
db *gorm.DB
}
func NewGormStore(db *gorm.DB) *GormStore {
return &GormStore{db: db}
}
func (s *GormStore) Create(l Lead) (Lead, error) {
l.ID = uuid.NewString()
l.Status = StatusNew
l.CreatedAt = time.Now().UTC()
if err := s.db.Create(&l).Error; err != nil {
return Lead{}, err
}
return l, nil
}
func (s *GormStore) List() ([]Lead, error) {
var out []Lead
if err := s.db.Order("created_at DESC").Find(&out).Error; err != nil {
return nil, err
}
return out, nil
}
func (s *GormStore) Get(id string) (Lead, bool) {
var l Lead
err := s.db.Where("id = ?", id).First(&l).Error
if errors.Is(err, gorm.ErrRecordNotFound) || err != nil {
return Lead{}, false
}
return l, true
}
func (s *GormStore) SetStatus(id string, status Status) (Lead, bool) {
var l Lead
if err := s.db.Where("id = ?", id).First(&l).Error; err != nil {
return Lead{}, false
}
l.Status = status
if err := s.db.Save(&l).Error; err != nil {
return Lead{}, false
}
return l, true
}