mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-01-03 01:22:21 +02:00
сделал Text_created_at
This commit is contained in:
parent
c620d2ad2e
commit
48bf9dc634
@ -146,12 +146,14 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ
|
||||
if is_create == true {
|
||||
if int64(m.ID) != 0 {
|
||||
TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0")
|
||||
// log.Panic(sError)
|
||||
err = errors.New(TextError)
|
||||
return err
|
||||
}
|
||||
} else if int64(m.ID) == 0 {
|
||||
TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0")
|
||||
err = errors.New(TextError)
|
||||
// log.Panic(sError)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -208,7 +210,7 @@ func (crud Crud_DB) Delete(m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete_ctx - записывает is_deleted = true
|
||||
// Delete_ctx - удаляет запись в БД
|
||||
func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
var err error
|
||||
|
||||
@ -217,53 +219,11 @@ func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.Laws
|
||||
return err
|
||||
}
|
||||
|
||||
m2 := lawsuit_status_types.LawsuitStatusType{}
|
||||
m2.ID = m.ID
|
||||
err = crud.Read_ctx(ctx, &m2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
db := postgres_gorm.GetConnection()
|
||||
db.WithContext(ctx)
|
||||
|
||||
m2.IsDeleted = true
|
||||
m.IsDeleted = true
|
||||
|
||||
err = crud.Save_ctx(ctx, &m2)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Restore - записывает is_deleted = true
|
||||
func (crud Crud_DB) Restore(m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
var err error
|
||||
|
||||
ctxMain := contextmain.GetContext()
|
||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err = crud.Restore_ctx(ctx, m)
|
||||
return err
|
||||
}
|
||||
|
||||
// Restore_ctx - записывает is_deleted = true
|
||||
func (crud Crud_DB) Restore_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
var err error
|
||||
|
||||
if micro.ContextDone(ctx) == true {
|
||||
err = context.Canceled
|
||||
return err
|
||||
}
|
||||
|
||||
m2 := lawsuit_status_types.LawsuitStatusType{}
|
||||
m2.ID = m.ID
|
||||
err = crud.Read_ctx(ctx, &m2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m2.IsDeleted = false
|
||||
m.IsDeleted = false
|
||||
|
||||
err = crud.Save_ctx(ctx, &m2)
|
||||
tx := db.Delete(m)
|
||||
err = tx.Error
|
||||
|
||||
return err
|
||||
}
|
||||
@ -304,7 +264,7 @@ func (crud Crud_DB) Find_ByExtID_ctx(ctx context.Context, m *lawsuit_status_type
|
||||
db := postgres_gorm.GetConnection()
|
||||
db.WithContext(ctx)
|
||||
|
||||
tx := db.Where("ext_id = ?", m.ExtID).Where("connection_id = ?", m.ConnectionID).First(m)
|
||||
tx := db.Where("ext_id = ?", m.ExtID).Where("connection_id = ?", m.ConnectionID).Order("is_deleted").Order("id").First(m)
|
||||
err = tx.Error
|
||||
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user