fixed executors db freezing #21
|
|
@ -27,6 +27,60 @@ type ApprovalTopicExecutorDBI interface {
|
|||
UpdateApprovalTopicExecutorDB(ctx context.Context, tx pgx.Tx, paramsUpdate *typescore.ApprovalTopicExecutor, returnObj ...bool) (*typescore.ApprovalTopicExecutor, pgx.Tx, error)
|
||||
DeleteApprovalTopicExecutorDB(ctx context.Context, params *typescore.ApprovalTopicExecutor) error
|
||||
GetExecutorsByTopicIDDB(ctx context.Context, topicID uint64) ([]*typescore.ApprovalTopicExecutor, error)
|
||||
GetApprovalTopicExecutorListWithParamsDB(ctx context.Context, opts typescore.ListDbOptions) ([]*typescore.ApprovalTopicExecutor, uint64, error)
|
||||
}
|
||||
|
||||
func (d *ApprovalTopicExecutorDB) GetApprovalTopicExecutorListWithParamsDB(ctx context.Context, opts typescore.ListDbOptions) ([]*typescore.ApprovalTopicExecutor, uint64, error) {
|
||||
options, filter, err := dbutils.GetOptionsDB[typescore.ApprovalTopicExecutor](opts)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
query := squirrel.Select(
|
||||
"ate.*",
|
||||
"u.id", "u.full_name", "u.username",
|
||||
"t.id", "t.name",
|
||||
"COUNT(*) OVER() AS total_count",
|
||||
).
|
||||
From("approval_topic_executors ate").
|
||||
LeftJoin("users u ON ate.user_id = u.id").
|
||||
LeftJoin("approval_topics t ON ate.topic_id = t.id")
|
||||
|
||||
query = dbutils.SetterLimitAndOffsetQuery(query, options.Offset, options.Limit)
|
||||
query = dbutils.ApplyFilters(query, filter, options.LikeFields, dbcoretablenames.TableNameApprovalTopicExecutor.ToString())
|
||||
query = query.OrderBy("step_order ASC, id ASC")
|
||||
|
||||
sql, args, err := query.PlaceholderFormat(squirrel.Dollar).ToSql()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
rows, err := d.pool.Query(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var results []*typescore.ApprovalTopicExecutor
|
||||
var totalCount uint64
|
||||
|
||||
for rows.Next() {
|
||||
exec := &typescore.ApprovalTopicExecutor{}
|
||||
exec.User = &typescore.User{}
|
||||
exec.Topic = &typescore.ApprovalTopic{}
|
||||
|
||||
err := rows.Scan(
|
||||
&exec.ID, &exec.TopicID, &exec.UserID, &exec.StepOrder, &exec.RequireFile, &exec.IsActive, &exec.CreatedAt, &exec.UpdatedAt,
|
||||
&exec.User.ID, &exec.User.FullName, &exec.User.Username,
|
||||
&exec.Topic.ID, &exec.Topic.Name,
|
||||
&totalCount,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
results = append(results, exec)
|
||||
}
|
||||
|
||||
return results, totalCount, nil
|
||||
}
|
||||
|
||||
func (d *ApprovalTopicExecutorDB) GetApprovalTopicExecutorListDB(ctx context.Context, opts ...typescore.ListDbOptions) ([]*typescore.ApprovalTopicExecutor, uint64, error) {
|
||||
|
|
@ -161,7 +215,7 @@ func (d *ApprovalTopicExecutorDB) DeleteApprovalTopicExecutorDB(ctx context.Cont
|
|||
return err
|
||||
}
|
||||
|
||||
_, err = d.pool.Query(ctx, query, args...)
|
||||
_, err = d.pool.Exec(ctx, query, args...)
|
||||
return err
|
||||
}
|
||||
return errors.New("ApprovalTopicExecutor obj is nil")
|
||||
|
|
|
|||
|
|
@ -376,17 +376,6 @@ func (s *TopicExecutorsReg) DeleteTopicExecutorHandler(w http.ResponseWriter, r
|
|||
|
||||
ctx := r.Context()
|
||||
|
||||
// Проверяем, что запись существует
|
||||
existingExecutors, _, err := s.ipc.Database.ApprovalTopicExecutor.GetApprovalTopicExecutorListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalTopicExecutor{ID: req.ID},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(existingExecutors) == 0 {
|
||||
return nil, errors.New("topic executor not found")
|
||||
}
|
||||
|
||||
err = s.ipc.Database.ApprovalTopicExecutor.DeleteApprovalTopicExecutorDB(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in New Issue