44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// WhatsAppCallRepo provides data access for WhatsAppCall.
|
|
type WhatsAppCallRepo struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewWhatsAppCallRepo(db *gorm.DB) *WhatsAppCallRepo {
|
|
return &WhatsAppCallRepo{db: db}
|
|
}
|
|
|
|
func (r *WhatsAppCallRepo) Create(ctx context.Context, call *model.WhatsAppCall) error {
|
|
return r.db.WithContext(ctx).Create(call).Error
|
|
}
|
|
|
|
func (r *WhatsAppCallRepo) FindByCallID(ctx context.Context, callID string) (*model.WhatsAppCall, error) {
|
|
var call model.WhatsAppCall
|
|
err := r.db.WithContext(ctx).Where("call_id = ?", callID).First(&call).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &call, nil
|
|
}
|
|
|
|
func (r *WhatsAppCallRepo) FindByConversationID(ctx context.Context, conversationID uint) ([]model.WhatsAppCall, error) {
|
|
var calls []model.WhatsAppCall
|
|
err := r.db.WithContext(ctx).Where("conversation_id = ?", conversationID).Find(&calls).Error
|
|
return calls, err
|
|
}
|
|
|
|
func (r *WhatsAppCallRepo) Update(ctx context.Context, call *model.WhatsAppCall) error {
|
|
return r.db.WithContext(ctx).Save(call).Error
|
|
}
|
|
|
|
func (r *WhatsAppCallRepo) Delete(ctx context.Context, id uint) error {
|
|
return r.db.WithContext(ctx).Delete(&model.WhatsAppCall{}, id).Error
|
|
} |