55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
)
|
|
|
|
// InboxLimitRepo implements GORM repository for InboxLimit.
|
|
// Reference: Chatwoot app/models/inbox_limit.rb + InboxLimitsController (create/update/destroy only)
|
|
type InboxLimitRepo struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewInboxLimitRepo creates a new InboxLimit repository.
|
|
func NewInboxLimitRepo(db *gorm.DB) *InboxLimitRepo {
|
|
return &InboxLimitRepo{db: db}
|
|
}
|
|
|
|
// Create inserts a new inbox limit.
|
|
func (r *InboxLimitRepo) Create(ctx context.Context, limit *model.InboxLimit) error {
|
|
return r.db.WithContext(ctx).Create(limit).Error
|
|
}
|
|
|
|
// FindByInbox retrieves all inbox limits for a specific inbox.
|
|
func (r *InboxLimitRepo) FindByInbox(ctx context.Context, inboxID uint) ([]model.InboxLimit, error) {
|
|
var limits []model.InboxLimit
|
|
err := r.db.WithContext(ctx).Where("inbox_id = ?", inboxID).Find(&limits).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return limits, nil
|
|
}
|
|
|
|
// FindByID retrieves an inbox limit by primary key.
|
|
func (r *InboxLimitRepo) FindByID(ctx context.Context, id uint) (*model.InboxLimit, error) {
|
|
var limit model.InboxLimit
|
|
err := r.db.WithContext(ctx).First(&limit, id).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &limit, nil
|
|
}
|
|
|
|
// Update saves changes to an existing inbox limit.
|
|
func (r *InboxLimitRepo) Update(ctx context.Context, limit *model.InboxLimit) error {
|
|
return r.db.WithContext(ctx).Save(limit).Error
|
|
}
|
|
|
|
// Delete removes an inbox limit by primary key.
|
|
func (r *InboxLimitRepo) Delete(ctx context.Context, id uint) error {
|
|
return r.db.WithContext(ctx).Delete(&model.InboxLimit{}, id).Error
|
|
} |