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/object_model/entities/lawsuit_status_types"
"testing"
"math"
)
// LawsuitStatusType_ID_Test - ID таблицы для тестирования
@ -37,7 +38,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
ctx := context.Background()
Request := grpc_proto.RequestId{}
Request.Id = LawsuitStatusType_ID_Test
Request.Id = math.MinInt64
Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
server1 := &ServerGRPC{}

View File

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

View File

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

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/object_model/entities/lawsuit_status_types"
"testing"
"math"
)
// Postgres_ID_Test - ID таблицы для тестирования
@ -110,45 +111,11 @@ func TestDelete(t *testing.T) {
crud := Crud_NRPC{}
Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Postgres_ID_Test
err := crud.Read(&Otvet)
if err != nil {
t.Error("TestRead() error: ", err)
}
if Otvet.IsDeleted == false {
err = crud.Delete(&Otvet)
Otvet.ID = math.MinInt64
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")
}
}
}
func TestFindByExtID(t *testing.T) {