feat: 修改代码补全采纳逻辑

This commit is contained in:
yokowu
2025-07-04 17:24:31 +08:00
parent 01245897fe
commit 810e5f2437
3 changed files with 22 additions and 5 deletions

View File

@@ -28,6 +28,7 @@ type ProxyUsecase interface {
type ProxyRepo interface {
Record(ctx context.Context, record *RecordParam) error
UpdateByTaskID(ctx context.Context, taskID string, fn func(*db.TaskUpdateOne)) error
AcceptCompletion(ctx context.Context, req *AcceptCompletionReq) error
SelectModelWithLoadBalancing(modelName string, modelType consts.ModelType) (*db.Model, error)
ValidateApiKey(ctx context.Context, key string) (*db.ApiKey, error)
}

View File

@@ -133,3 +133,23 @@ func (r *ProxyRepo) UpdateByTaskID(ctx context.Context, taskID string, fn func(*
return up.Exec(ctx)
})
}
func (r *ProxyRepo) AcceptCompletion(ctx context.Context, req *domain.AcceptCompletionReq) error {
return entx.WithTx(ctx, r.db, func(tx *db.Tx) error {
rc, err := tx.Task.Query().Where(task.TaskID(req.ID)).Only(ctx)
if err != nil {
return err
}
if err := tx.Task.UpdateOneID(rc.ID).
SetIsAccept(true).
SetCompletion(req.Completion).
Exec(ctx); err != nil {
return err
}
return tx.TaskRecord.Update().
Where(taskrecord.TaskID(rc.ID)).
SetCompletion(req.Completion).Exec(ctx)
})
}

View File

@@ -6,7 +6,6 @@ import (
"github.com/chaitin/MonkeyCode/backend/pkg/cvt"
"github.com/chaitin/MonkeyCode/backend/consts"
"github.com/chaitin/MonkeyCode/backend/db"
"github.com/chaitin/MonkeyCode/backend/domain"
)
@@ -40,8 +39,5 @@ func (p *ProxyUsecase) ValidateApiKey(ctx context.Context, key string) (*domain.
}
func (p *ProxyUsecase) AcceptCompletion(ctx context.Context, req *domain.AcceptCompletionReq) error {
return p.repo.UpdateByTaskID(ctx, req.ID, func(ruo *db.TaskUpdateOne) {
ruo.SetIsAccept(true)
ruo.SetCompletion(req.Completion)
})
return p.repo.AcceptCompletion(ctx, req)
}