mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-06-05 11:57:30 +02:00
сделал objects
This commit is contained in:
parent
d93684f67e
commit
6227b34b19
@ -1,5 +1,6 @@
|
|||||||
//заполним FieldNameForeign
|
//заполним FieldNameForeign
|
||||||
FieldNameForeign := TableNameForeign.FieldNameForeign{}
|
FieldNameForeign := TableNameForeign.FieldNameForeign{}
|
||||||
|
FieldNameForeign.PrimaryKeyNameF = m.FieldNameForeign
|
||||||
err = crud_TableNameForeign.Read_ctx(ctx, db, &FieldNameForeign)
|
err = crud_TableNameForeign.Read_ctx(ctx, db, &FieldNameForeign)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf(FieldNameForeign.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithComma, err)
|
err = fmt.Errorf(FieldNameForeign.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithComma, err)
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ManyakRus/starter/config_main"
|
||||||
|
"github.com/ManyakRus/starter/postgres_gorm"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/constants"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud_objects/crud_object_lawsuit_status_types"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/objects/object_lawsuit_status_types"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReadObject(t *testing.T) {
|
||||||
|
config_main.LoadEnv()
|
||||||
|
|
||||||
|
postgres_gorm.Connect_WithApplicationName(constants.SERVICE_NAME + "_test")
|
||||||
|
defer postgres_gorm.CloseConnection()
|
||||||
|
crud_starter.InitCrudTransport_DB()
|
||||||
|
|
||||||
|
crud := crud_object_lawsuit_status_types.Crud_DB{}
|
||||||
|
Otvet := object_lawsuit_status_types.ObjectLawsuitStatusType{}
|
||||||
|
err := crud.ReadObject(&Otvet)
|
||||||
|
if err != nil && crud_func.IsRecordNotFound(err) == false {
|
||||||
|
t.Error("TestReadObject() error: ", err)
|
||||||
|
}
|
||||||
|
}
|
@ -218,6 +218,7 @@ type SettingsINI struct {
|
|||||||
TEXT_READALL string
|
TEXT_READALL string
|
||||||
|
|
||||||
NEED_USE_DB_VIEWS bool
|
NEED_USE_DB_VIEWS bool
|
||||||
|
TESTS_FOLDERNAME string
|
||||||
|
|
||||||
//Objects
|
//Objects
|
||||||
NEED_CREATE_OBJECTS bool
|
NEED_CREATE_OBJECTS bool
|
||||||
@ -1281,6 +1282,11 @@ func FillSettings() {
|
|||||||
s = Getenv(Name, true)
|
s = Getenv(Name, true)
|
||||||
Settings.PREFIX_CRUD_OBJECT = s
|
Settings.PREFIX_CRUD_OBJECT = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TESTS_FOLDERNAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TESTS_FOLDERNAME = s
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentDirectory - возвращает текущую директорию ОС
|
// CurrentDirectory - возвращает текущую директорию ОС
|
||||||
|
@ -724,6 +724,15 @@ func Find_ObjectTableURL(TableName string) string {
|
|||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find_CrudObjectTableURL - возвращает URL репозитория crud_object для таблицы TableName
|
||||||
|
func Find_CrudObjectTableURL(TableName string) string {
|
||||||
|
Otvet := ""
|
||||||
|
|
||||||
|
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATES_CRUD_OBJECTS_FOLDERNAME + "/" + TableName
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
// Find_CrudFuncURL - возвращает URL репозитория crud_func
|
// Find_CrudFuncURL - возвращает URL репозитория crud_func
|
||||||
func Find_CrudFuncURL(string) string {
|
func Find_CrudFuncURL(string) string {
|
||||||
Otvet := ""
|
Otvet := ""
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package crud_object_tables
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/create_files"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/types"
|
||||||
|
"github.com/ManyakRus/starter/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateAllFiles - создаёт все файлы в папке objects
|
||||||
|
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
for _, Table1 := range MapAll {
|
||||||
|
//проверка что таблица нормальная
|
||||||
|
err1 := create_files.IsGood_Table(Table1)
|
||||||
|
if err1 != nil {
|
||||||
|
log.Warn(err1)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
//файлы crud objects
|
||||||
|
err = CreateFiles_ReadObject(MapAll, Table1)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("CreateFiles_ReadObject() table: ", Table1.Name, " error: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//файлы crud objects test
|
||||||
|
err = CreateFiles_ReadObject_Test(MapAll, Table1)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("CreateFiles_ReadObject() table: ", Table1.Name, " error: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package crud_object
|
package crud_object_tables
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ManyakRus/crud_generator/internal/config"
|
"github.com/ManyakRus/crud_generator/internal/config"
|
||||||
@ -133,6 +133,11 @@ func CreateFiles_ReadObject_Table1(MapAll map[string]*types.Table, Table1 *types
|
|||||||
Otvet := TextTemplateFunction
|
Otvet := TextTemplateFunction
|
||||||
|
|
||||||
TableF, ColumnF := create_files.Find_TableF_ColumnF(MapAll, Column1)
|
TableF, ColumnF := create_files.Find_TableF_ColumnF(MapAll, Column1)
|
||||||
|
ColumnPKF := create_files.Find_PrimaryKeyColumn(TableF)
|
||||||
|
|
||||||
|
//PrimaryKeyNameF
|
||||||
|
PrimaryKeyNameF := ColumnPKF.NameGo
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "PrimaryKeyNameF", PrimaryKeyNameF)
|
||||||
|
|
||||||
//FieldNameForeign
|
//FieldNameForeign
|
||||||
FieldNameForeign := ColumnF.Name
|
FieldNameForeign := ColumnF.Name
|
||||||
@ -166,7 +171,7 @@ func CreateFiles_ReadObject_Test(MapAll map[string]*types.Table, Table1 *types.T
|
|||||||
|
|
||||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_READALL_TEST_FILENAME
|
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_READALL_TEST_FILENAME
|
||||||
TableName := strings.ToLower(Table1.Name)
|
TableName := strings.ToLower(Table1.Name)
|
||||||
DirReadyTable := DirReadyCrud + config.Settings.PREFIX_CRUD_OBJECT + TableName
|
DirReadyTable := DirReadyCrud + config.Settings.PREFIX_CRUD_OBJECT + TableName + micro.SeparatorFile() + config.Settings.TESTS_FOLDERNAME
|
||||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD_OBJECT + TableName
|
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD_OBJECT + TableName
|
||||||
|
|
||||||
//создадим каталог
|
//создадим каталог
|
||||||
@ -179,13 +184,13 @@ func CreateFiles_ReadObject_Test(MapAll map[string]*types.Table, Table1 *types.T
|
|||||||
}
|
}
|
||||||
TextCrud := string(bytes)
|
TextCrud := string(bytes)
|
||||||
|
|
||||||
//загрузим шаблон файла функции
|
////загрузим шаблон файла функции
|
||||||
FilenameTemplateCrudFunction := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_READALL_FUNCTION_TEST_FILENAME
|
//FilenameTemplateCrudFunction := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_READALL_FUNCTION_TEST_FILENAME
|
||||||
bytes, err = os.ReadFile(FilenameTemplateCrudFunction)
|
//bytes, err = os.ReadFile(FilenameTemplateCrudFunction)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
log.Panic("ReadFile() ", FilenameTemplateCrudFunction, " error: ", err)
|
// log.Panic("ReadFile() ", FilenameTemplateCrudFunction, " error: ", err)
|
||||||
}
|
//}
|
||||||
TextTemplatedFunction := string(bytes)
|
//TextTemplatedFunction := string(bytes)
|
||||||
|
|
||||||
//заменим имя пакета на новое
|
//заменим имя пакета на новое
|
||||||
TextCrud = create_files.Replace_PackageName(TextCrud, DirReadyTable)
|
TextCrud = create_files.Replace_PackageName(TextCrud, DirReadyTable)
|
||||||
@ -195,20 +200,34 @@ func CreateFiles_ReadObject_Test(MapAll map[string]*types.Table, Table1 *types.T
|
|||||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||||
TextCrud = create_files.Delete_TemplateRepositoryImports(TextCrud)
|
TextCrud = create_files.Delete_TemplateRepositoryImports(TextCrud)
|
||||||
|
|
||||||
//ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
//
|
||||||
//TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||||
|
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||||
|
|
||||||
CrudFuncURL := create_files.Find_CrudFuncURL(TableName)
|
//
|
||||||
TextCrud = create_files.AddImport(TextCrud, CrudFuncURL)
|
ObjectTableURL := create_files.Find_ObjectTableURL(TableName)
|
||||||
|
TextCrud = create_files.AddImport(TextCrud, ObjectTableURL)
|
||||||
|
|
||||||
|
//
|
||||||
|
CrudObjectTableURL := create_files.Find_CrudObjectTableURL(TableName)
|
||||||
|
TextCrud = create_files.AddImport(TextCrud, CrudObjectTableURL)
|
||||||
|
|
||||||
|
//
|
||||||
|
ConstantsURL := create_files.Find_ConstantsURL()
|
||||||
|
TextCrud = create_files.AddImport(TextCrud, ConstantsURL)
|
||||||
|
|
||||||
|
//
|
||||||
|
CrudStarterURL := create_files.Find_CrudStarterURL()
|
||||||
|
TextCrud = create_files.AddImport(TextCrud, CrudStarterURL)
|
||||||
|
|
||||||
|
////
|
||||||
|
//CrudFuncURL := create_files.Find_CrudFuncURL(TableName)
|
||||||
|
//TextCrud = create_files.AddImport(TextCrud, CrudFuncURL)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//создание функций
|
//создание функций
|
||||||
TextCrudFunc := CreateFiles_ReadObject_TestTable(Table1, TextTemplatedFunction)
|
TextCrud = CreateFiles_ReadObject_TableTest(MapAll, Table1, TextCrud)
|
||||||
if TextCrudFunc == "" {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
TextCrud = TextCrud + TextCrudFunc
|
|
||||||
|
|
||||||
//создание текста
|
//создание текста
|
||||||
TextCrud = create_files.Replace_TemplateModel_to_Model(TextCrud, Table1.NameGo)
|
TextCrud = create_files.Replace_TemplateModel_to_Model(TextCrud, Table1.NameGo)
|
||||||
@ -240,34 +259,9 @@ func CreateFiles_ReadObject_Test(MapAll map[string]*types.Table, Table1 *types.T
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateFiles_ReadObject_TestTable - создаёт текст всех функций
|
// CreateFiles_ReadObject_TableTest - создаёт текст функции
|
||||||
func CreateFiles_ReadObject_TestTable(MapAll map[string]*types.Table, Table1 *types.Table, TextTemplateFunction string) string {
|
func CreateFiles_ReadObject_TableTest(MapAll map[string]*types.Table, Table1 *types.Table, TextGo string) string {
|
||||||
Otvet := ""
|
Otvet := TextGo
|
||||||
|
|
||||||
for TableReadObject1, _ := range types.MapReadObject {
|
|
||||||
if TableReadObject1.Name != Table1.Name {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
Otvet1 := CreateFiles_ReadObject_Test_Table1(Table1, TextTemplateFunction)
|
|
||||||
Otvet = Otvet + Otvet1
|
|
||||||
}
|
|
||||||
|
|
||||||
return Otvet
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateFiles_ReadObject_Test_Table1 - создаёт текст всех функций
|
|
||||||
func CreateFiles_ReadObject_Test_Table1(Table1 *types.Table, TextTemplateFunction string) string {
|
|
||||||
Otvet := TextTemplateFunction
|
|
||||||
|
|
||||||
//
|
|
||||||
TextFieldsDefaultValue := create_files.Find_PrimaryKeysDefaultValues(Table1)
|
|
||||||
|
|
||||||
//
|
|
||||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesDefaultValues", TextFieldsDefaultValue)
|
|
||||||
|
|
||||||
//
|
|
||||||
PrimaryKeyNamesWithComma := create_files.Find_PrimaryKeyNamesWithComma(Table1)
|
|
||||||
Otvet = strings.ReplaceAll(Otvet, "PrimaryKeyNamesWithComma", PrimaryKeyNamesWithComma)
|
|
||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
@ -429,11 +429,6 @@ func ReplacePrimaryKeyM_ID(Text string, Table1 *types.Table) string {
|
|||||||
TextOR = " || "
|
TextOR = " || "
|
||||||
}
|
}
|
||||||
|
|
||||||
//Otvet = strings.ReplaceAll(Otvet, "\t"+VariableName+".ID = AliasFromInt(ID)", TextOtvetIDAliasID)
|
|
||||||
//Otvet = strings.ReplaceAll(Otvet, "\t"+VariableName+".ID = ProtoFromInt(m.ID)", TextRequestIDmID)
|
|
||||||
//Otvet = strings.ReplaceAll(Otvet, "\t"+VariableName+".ID = int64(ID)", TextRequestIDInt64ID)
|
|
||||||
//Otvet = strings.ReplaceAll(Otvet, "\tOtvet.ID = "+VariableName+".ID\n", TextOtvetIDmID)
|
|
||||||
//Otvet = strings.ReplaceAll(Otvet, " IntFromAlias("+VariableName+".ID) == 0", TextMID0)
|
|
||||||
Otvet = strings.ReplaceAll(Otvet, "\tm2.ID = int64(m.ID)", TextM2ID)
|
Otvet = strings.ReplaceAll(Otvet, "\tm2.ID = int64(m.ID)", TextM2ID)
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", TextIfMId)
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) == 0", TextIfMId)
|
||||||
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", TextIfMIdNot0)
|
Otvet = strings.ReplaceAll(Otvet, "int64(m.ID) != 0", TextIfMIdNot0)
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/ManyakRus/crud_generator/internal/create_files/alias"
|
"github.com/ManyakRus/crud_generator/internal/create_files/alias"
|
||||||
"github.com/ManyakRus/crud_generator/internal/create_files/constants_file"
|
"github.com/ManyakRus/crud_generator/internal/create_files/constants_file"
|
||||||
"github.com/ManyakRus/crud_generator/internal/create_files/crud"
|
"github.com/ManyakRus/crud_generator/internal/create_files/crud"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/create_files/crud_object_tables"
|
||||||
"github.com/ManyakRus/crud_generator/internal/create_files/crud_starter"
|
"github.com/ManyakRus/crud_generator/internal/create_files/crud_starter"
|
||||||
"github.com/ManyakRus/crud_generator/internal/create_files/crud_starter_tables"
|
"github.com/ManyakRus/crud_generator/internal/create_files/crud_starter_tables"
|
||||||
"github.com/ManyakRus/crud_generator/internal/create_files/crud_tables"
|
"github.com/ManyakRus/crud_generator/internal/create_files/crud_tables"
|
||||||
@ -239,6 +240,13 @@ func StartFillAll() error {
|
|||||||
//log.Error("env_file.CreateAllFiles() error: ", err)
|
//log.Error("env_file.CreateAllFiles() error: ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = crud_object_tables.CreateAllFiles(MapAll)
|
||||||
|
if err != nil {
|
||||||
|
//log.Error("env_file.CreateAllFiles() error: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user