1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-22 00:36:41 +02:00

сделал Delete() везде

This commit is contained in:
Nikitin Aleksandr 2023-12-01 16:48:06 +03:00
parent b5e3b2cf85
commit 4450202313
5 changed files with 19 additions and 147 deletions

View File

@ -7,6 +7,7 @@ import (
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing" "testing"
"math"
) )
// LawsuitStatusType_ID_Test - ID таблицы для тестирования // LawsuitStatusType_ID_Test - ID таблицы для тестирования
@ -37,7 +38,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
ctx := context.Background() ctx := context.Background()
Request := grpc_proto.RequestId{} Request := grpc_proto.RequestId{}
Request.Id = LawsuitStatusType_ID_Test Request.Id = math.MinInt64
Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
server1 := &ServerGRPC{} server1 := &ServerGRPC{}

View File

@ -209,7 +209,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
@ -218,53 +218,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
} }

View File

@ -5,6 +5,7 @@ import (
"github.com/ManyakRus/starter/postgres_gorm" "github.com/ManyakRus/starter/postgres_gorm"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing" "testing"
"math"
) )
const Postgres_ID_Test = 1 const Postgres_ID_Test = 1
@ -64,35 +65,12 @@ func TestDelete(t *testing.T) {
crud := Crud_DB{} crud := Crud_DB{}
Otvet := lawsuit_status_types.LawsuitStatusType{} Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Postgres_ID_Test Otvet.ID = math.MinInt64
err := crud.Read(&Otvet) err := crud.Delete(&Otvet)
if err != nil { if err != nil {
t.Error("TestDelete() error: ", err) t.Error("TestDelete() error: ", err)
} }
if Otvet.IsDeleted == false {
err = crud.Delete(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
err = crud.Restore(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
} else {
err = crud.Restore(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
err = crud.Delete(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
}
} }

View File

@ -4,6 +4,7 @@ import (
config "github.com/ManyakRus/starter/config" config "github.com/ManyakRus/starter/config"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"math"
"testing" "testing"
) )
@ -110,44 +111,11 @@ func TestDelete(t *testing.T) {
crud := Crud_GRPC{} crud := Crud_GRPC{}
Otvet := lawsuit_status_types.LawsuitStatusType{} Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Postgres_ID_Test Otvet.ID = math.MinInt64
err := crud.Read(&Otvet)
err := crud.Delete(&Otvet)
if err != nil { if err != nil {
t.Error("TestRead() error: ", err) t.Error("TestDelete() error: ", err)
}
if Otvet.IsDeleted == false {
err = crud.Delete(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestDelete() error: ID =0")
}
err = crud.Restore(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestDelete() error: ID =0")
}
} else {
err = crud.Restore(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestDelete() error: ID =0")
}
err = crud.Delete(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestDelete() error: ID =0")
}
} }
} }

View File

@ -5,6 +5,7 @@ import (
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing" "testing"
"math"
) )
// Postgres_ID_Test - ID таблицы для тестирования // Postgres_ID_Test - ID таблицы для тестирования
@ -110,44 +111,10 @@ func TestDelete(t *testing.T) {
crud := Crud_NRPC{} crud := Crud_NRPC{}
Otvet := lawsuit_status_types.LawsuitStatusType{} Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Postgres_ID_Test Otvet.ID = math.MinInt64
err := crud.Read(&Otvet) err := crud.Delete(&Otvet)
if err != nil { if err != nil {
t.Error("TestRead() error: ", err) t.Error("TestDelete() error: ", err)
}
if Otvet.IsDeleted == false {
err = crud.Delete(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestDelete() error: ID =0")
}
err = crud.Restore(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestDelete() error: ID =0")
}
} else {
err = crud.Restore(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestDelete() error: ID =0")
}
err = crud.Delete(&Otvet)
if err != nil {
t.Error("TestDelete() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestDelete() error: ID =0")
}
} }
} }