feat(captain): align scenario and tool payloads
This commit is contained in:
@@ -28,6 +28,14 @@ func (r *CaptainCustomToolRepo) GetByID(ctx context.Context, id uint) (*model.Ca
|
||||
return &tool, nil
|
||||
}
|
||||
|
||||
func (r *CaptainCustomToolRepo) GetByAccountAndID(ctx context.Context, accountID, id uint) (*model.CaptainCustomTool, error) {
|
||||
var tool model.CaptainCustomTool
|
||||
if err := r.db.WithContext(ctx).Where("account_id = ? AND id = ?", accountID, id).First(&tool).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &tool, nil
|
||||
}
|
||||
|
||||
func (r *CaptainCustomToolRepo) GetBySlug(ctx context.Context, accountID uint, slug string) (*model.CaptainCustomTool, error) {
|
||||
var tool model.CaptainCustomTool
|
||||
if err := r.db.WithContext(ctx).Where("account_id = ? AND slug = ?", accountID, slug).First(&tool).Error; err != nil {
|
||||
@@ -44,6 +52,10 @@ func (r *CaptainCustomToolRepo) Delete(ctx context.Context, id uint) error {
|
||||
return r.db.WithContext(ctx).Delete(&model.CaptainCustomTool{}, id).Error
|
||||
}
|
||||
|
||||
func (r *CaptainCustomToolRepo) DeleteByAccount(ctx context.Context, accountID, id uint) error {
|
||||
return r.db.WithContext(ctx).Where("account_id = ? AND id = ?", accountID, id).Delete(&model.CaptainCustomTool{}).Error
|
||||
}
|
||||
|
||||
func (r *CaptainCustomToolRepo) ListByAccount(ctx context.Context, accountID uint, offset, limit int) ([]model.CaptainCustomTool, int64, error) {
|
||||
var tools []model.CaptainCustomTool
|
||||
var count int64
|
||||
@@ -61,4 +73,4 @@ func (r *CaptainCustomToolRepo) CountByAccount(ctx context.Context, accountID ui
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,18 @@ func (r *CaptainScenarioRepo) Create(ctx context.Context, scenario *model.Captai
|
||||
|
||||
func (r *CaptainScenarioRepo) GetByID(ctx context.Context, id uint) (*model.CaptainScenario, error) {
|
||||
var scenario model.CaptainScenario
|
||||
if err := r.db.WithContext(ctx).First(&scenario, id).Error; err != nil {
|
||||
if err := r.db.WithContext(ctx).Preload("Assistant").First(&scenario, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &scenario, nil
|
||||
}
|
||||
|
||||
func (r *CaptainScenarioRepo) GetByAccountAssistantAndID(ctx context.Context, accountID, assistantID, id uint) (*model.CaptainScenario, error) {
|
||||
var scenario model.CaptainScenario
|
||||
if err := r.db.WithContext(ctx).
|
||||
Preload("Assistant").
|
||||
Where("account_id = ? AND assistant_id = ? AND id = ?", accountID, assistantID, id).
|
||||
First(&scenario).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &scenario, nil
|
||||
@@ -36,12 +47,30 @@ func (r *CaptainScenarioRepo) Delete(ctx context.Context, id uint) error {
|
||||
return r.db.WithContext(ctx).Delete(&model.CaptainScenario{}, id).Error
|
||||
}
|
||||
|
||||
func (r *CaptainScenarioRepo) DeleteByAccountAssistant(ctx context.Context, accountID, assistantID, id uint) error {
|
||||
return r.db.WithContext(ctx).
|
||||
Where("account_id = ? AND assistant_id = ? AND id = ?", accountID, assistantID, id).
|
||||
Delete(&model.CaptainScenario{}).Error
|
||||
}
|
||||
|
||||
func (r *CaptainScenarioRepo) ListByAssistant(ctx context.Context, assistantID uint, offset, limit int) ([]model.CaptainScenario, int64, error) {
|
||||
var scenarios []model.CaptainScenario
|
||||
var count int64
|
||||
db := r.db.WithContext(ctx).Model(&model.CaptainScenario{}).Where("assistant_id = ?", assistantID)
|
||||
db.Count(&count)
|
||||
if err := db.Offset(offset).Limit(limit).Find(&scenarios).Error; err != nil {
|
||||
if err := db.Preload("Assistant").Offset(offset).Limit(limit).Find(&scenarios).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return scenarios, count, nil
|
||||
}
|
||||
|
||||
func (r *CaptainScenarioRepo) ListEnabledByAccountAssistant(ctx context.Context, accountID, assistantID uint) ([]model.CaptainScenario, int64, error) {
|
||||
var scenarios []model.CaptainScenario
|
||||
var count int64
|
||||
db := r.db.WithContext(ctx).Model(&model.CaptainScenario{}).
|
||||
Where("account_id = ? AND assistant_id = ? AND enabled = ?", accountID, assistantID, true)
|
||||
db.Count(&count)
|
||||
if err := db.Preload("Assistant").Order("created_at ASC").Find(&scenarios).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return scenarios, count, nil
|
||||
@@ -56,4 +85,4 @@ func (r *CaptainScenarioRepo) FindEnabled(ctx context.Context, assistantID uint)
|
||||
return nil, err
|
||||
}
|
||||
return scenarios, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user