1
0
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:
Nikitin Aleksandr 2023-12-26 09:32:38 +03:00
parent c620d2ad2e
commit 48bf9dc634

View File

@ -146,12 +146,14 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ
if is_create == true { if is_create == true {
if int64(m.ID) != 0 { if int64(m.ID) != 0 {
TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0") TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0")
// log.Panic(sError)
err = errors.New(TextError) err = errors.New(TextError)
return err return err
} }
} else if int64(m.ID) == 0 { } else if int64(m.ID) == 0 {
TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0") TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0")
err = errors.New(TextError) err = errors.New(TextError)
// log.Panic(sError)
return err return err
} }
@ -208,7 +210,7 @@ func (crud Crud_DB) Delete(m *lawsuit_status_types.LawsuitStatusType) error {
return err return err
} }
// Delete_ctx - записывает is_deleted = true // Delete_ctx - удаляет запись в БД
func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error { func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
var err error var err error
@ -217,53 +219,11 @@ func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.Laws
return err return err
} }
m2 := lawsuit_status_types.LawsuitStatusType{} db := postgres_gorm.GetConnection()
m2.ID = m.ID db.WithContext(ctx)
err = crud.Read_ctx(ctx, &m2)
if err != nil {
return err
}
m2.IsDeleted = true tx := db.Delete(m)
m.IsDeleted = true err = tx.Error
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)
return err 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 := postgres_gorm.GetConnection()
db.WithContext(ctx) 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 err = tx.Error
return err return err