mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-12-22 00:36:41 +02:00
сделал ./crud_functions_rename.json
This commit is contained in:
parent
5c6452cd6d
commit
67b9f1cb39
@ -5,7 +5,8 @@ FILEMAIN=./cmd/$(SERVICENAME)/main.go
|
||||
FILEAPP=./bin/$(SERVICENAME)
|
||||
|
||||
NEW_REPO=$(SERVICENAME)
|
||||
GENERATION_PROTO=cd ./api && ./generation_code.sh
|
||||
CD_GENERATION_PROTO=cd ./api
|
||||
GENERATION_PROTO=generation_code.sh
|
||||
|
||||
|
||||
run:
|
||||
@ -53,6 +54,7 @@ conn:
|
||||
init:
|
||||
clear
|
||||
go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service
|
||||
$(CD_GENERATION_PROTO)
|
||||
$(GENERATION_PROTO)
|
||||
go mod tidy
|
||||
go mod vendor
|
@ -1,3 +1,14 @@
|
||||
{
|
||||
"lawsuit_payments.id": "alias.PaymentId",
|
||||
"lawsuit_payments.invoice_id": "alias.InvoiceId",
|
||||
"lawsuit_payments.lawsuit_id": "alias.LawsuitId",
|
||||
"lawsuit_payments.id": "alias.PaymentId",
|
||||
"invoice_debt_type_stats.invoice_id": "alias.InvoiceId",
|
||||
"invoice_debt_type_stats.lawsuit_id": "alias.LawsuitId",
|
||||
"contract_black_items.contract_number": "alias.ContractNumber",
|
||||
"contract_white_items.contract_number": "alias.ContractNumber",
|
||||
"lawsuits.number_claim": "alias.ClaimNumber",
|
||||
"lawsuits.number": "alias.LawsuitNumber",
|
||||
"contracts.number": "alias.ContractNumber"
|
||||
}
|
||||
|
||||
|
@ -1,2 +1,8 @@
|
||||
{
|
||||
"lawsuits": [
|
||||
{
|
||||
"old": "create_update_ctx",
|
||||
"new": "create_update_ctx_original"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
{
|
||||
"lawsuits": "NewLawsuit,AsLawsuit,create_update_ctx"
|
||||
}
|
||||
|
@ -1,2 +1,19 @@
|
||||
{
|
||||
"inn": "INN",
|
||||
"kpp": "KPP",
|
||||
"okpo": "OKPO",
|
||||
"ogrn": "OGRN",
|
||||
"okato": "OKATO",
|
||||
"nsi_flat": "NSIFlat",
|
||||
"nsi_flat_id": "NSIFlatID",
|
||||
"nsi_id": "NSIID",
|
||||
"www": "WWW",
|
||||
"bik": "BIK",
|
||||
"city_name": "City",
|
||||
"edms_link": "EDMSLink",
|
||||
"code_nsi": "CodeNSI",
|
||||
"json_updated_at": "JSONUpdatedAt",
|
||||
"pdf_updated_at": "PDFUpdatedAt",
|
||||
"pdf_file_id": "PDFFileID",
|
||||
"json_file_id": "JSONFileID"
|
||||
}
|
@ -1,2 +1,4 @@
|
||||
{
|
||||
"ext_id": true,
|
||||
"created_at": false
|
||||
}
|
||||
|
@ -21,15 +21,15 @@ DB_PASSWORD=
|
||||
INCLUDE_TABLES=""
|
||||
|
||||
#INCLUDE_TABLES - table name ignore filter. Regular expression
|
||||
EXCLUDE_TABLES=
|
||||
EXCLUDE_TABLES="ext_"
|
||||
|
||||
#---------------------Template settings---------------------
|
||||
|
||||
#SERVICE_REPOSITORY_URL - URL of your new service repository (Github, gitlab, etc.)
|
||||
SERVICE_REPOSITORY_URL="gitlab.aescorp.ru/dsp_dev/claim/crud_service"
|
||||
SERVICE_REPOSITORY_URL="gitlab.aescorp.ru/dsp_dev/claim/sync_service"
|
||||
|
||||
#SERVICE_NAME - service name for your new service
|
||||
SERVICE_NAME=crud_service
|
||||
SERVICE_NAME=sync_service
|
||||
|
||||
#TEMPLATE_SERVICE_NAME - service name in your template files
|
||||
TEMPLATE_SERVICE_NAME=sync_service
|
||||
@ -96,7 +96,7 @@ TEXT_TEMPLATE_TABLENAME="lawsuit_status_types"
|
||||
USE_DEFAULT_TEMPLATE=true
|
||||
|
||||
#HAS_IS_DELETED - fill "true" if you have "is_deleted" column, and want Delete() Restore() functions.
|
||||
HAS_IS_DELETED=false
|
||||
HAS_IS_DELETED=true
|
||||
|
||||
#---------------------Create files settings---------------------
|
||||
|
||||
|
@ -7,7 +7,6 @@ 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 таблицы для тестирования
|
||||
@ -38,7 +37,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
Request := grpc_proto.RequestId{}
|
||||
Request.Id = math.MinInt64
|
||||
Request.Id = LawsuitStatusType_ID_Test
|
||||
Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
|
||||
|
||||
server1 := &ServerGRPC{}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package crud_starter_lawsuit_status_types
|
||||
|
||||
import (
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||
)
|
||||
|
||||
// SetCrudInterface - заполняет интерфейс crud: DB, GRPC, NRPC
|
||||
func SetCrudInterface(crud lawsuit_status_types.ICrud_LawsuitStatusType) {
|
||||
lawsuit_status_types.Crud_LawsuitStatusType = crud
|
||||
|
||||
return
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package starter_crud_starter_lawsuit_status_types
|
||||
|
||||
import (
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud/crud_lawsuit_status_types"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSetCrudInterface(t *testing.T) {
|
||||
crud := crud_lawsuit_status_types.Crud_DB{}
|
||||
|
||||
SetCrudInterface(crud)
|
||||
}
|
@ -4,7 +4,6 @@ import (
|
||||
config "github.com/ManyakRus/starter/config_main"
|
||||
"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"
|
||||
)
|
||||
|
||||
@ -111,11 +110,44 @@ func TestDelete(t *testing.T) {
|
||||
|
||||
crud := Crud_GRPC{}
|
||||
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||
Otvet.ID = math.MinInt64
|
||||
|
||||
err := crud.Delete(&Otvet)
|
||||
Otvet.ID = Postgres_ID_Test
|
||||
err := crud.Read(&Otvet)
|
||||
if err != nil {
|
||||
t.Error("TestDelete() error: ", err)
|
||||
t.Error("TestRead() 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ 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 таблицы для тестирования
|
||||
@ -111,10 +110,44 @@ func TestDelete(t *testing.T) {
|
||||
|
||||
crud := Crud_NRPC{}
|
||||
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||
Otvet.ID = math.MinInt64
|
||||
err := crud.Delete(&Otvet)
|
||||
Otvet.ID = Postgres_ID_Test
|
||||
err := crud.Read(&Otvet)
|
||||
if err != nil {
|
||||
t.Error("TestDelete() error: ", err)
|
||||
t.Error("TestRead() 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
// versionLawsuitStatusType - версия структуры модели, с учётом имен и типов полей
|
||||
var versionLawsuitStatusType uint32
|
||||
|
||||
// crud_LawsuitStatusType - объект контроллер crud операций
|
||||
var crud_LawsuitStatusType ICrud_LawsuitStatusType
|
||||
// Crud_LawsuitStatusType - объект контроллер crud операций
|
||||
var Crud_LawsuitStatusType ICrud_LawsuitStatusType
|
||||
|
||||
// интерфейс стандартных CRUD операций, для использования в DB или GRPC или NRPC
|
||||
type ICrud_LawsuitStatusType interface {
|
||||
@ -92,84 +92,84 @@ func (m LawsuitStatusType) GetJSON() (string, error) {
|
||||
|
||||
// Read - находит запись в БД по ID, и заполняет в объект
|
||||
func (m *LawsuitStatusType) Read() error {
|
||||
if crud_LawsuitStatusType == nil {
|
||||
if Crud_LawsuitStatusType == nil {
|
||||
return constants.ErrorCrudIsNotInit
|
||||
}
|
||||
|
||||
err := crud_LawsuitStatusType.Read(m)
|
||||
err := Crud_LawsuitStatusType.Read(m)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Save - записывает объект в БД по ID
|
||||
func (m *LawsuitStatusType) Save() error {
|
||||
if crud_LawsuitStatusType == nil {
|
||||
if Crud_LawsuitStatusType == nil {
|
||||
return constants.ErrorCrudIsNotInit
|
||||
}
|
||||
|
||||
err := crud_LawsuitStatusType.Save(m)
|
||||
err := Crud_LawsuitStatusType.Save(m)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Update - обновляет объект в БД по ID
|
||||
func (m *LawsuitStatusType) Update() error {
|
||||
if crud_LawsuitStatusType == nil {
|
||||
if Crud_LawsuitStatusType == nil {
|
||||
return constants.ErrorCrudIsNotInit
|
||||
}
|
||||
|
||||
err := crud_LawsuitStatusType.Update(m)
|
||||
err := Crud_LawsuitStatusType.Update(m)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create - создаёт объект в БД с новым ID
|
||||
func (m *LawsuitStatusType) Create() error {
|
||||
if crud_LawsuitStatusType == nil {
|
||||
if Crud_LawsuitStatusType == nil {
|
||||
return constants.ErrorCrudIsNotInit
|
||||
}
|
||||
|
||||
err := crud_LawsuitStatusType.Create(m)
|
||||
err := Crud_LawsuitStatusType.Create(m)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete - устанавливает признак пометки удаления в БД
|
||||
func (m *LawsuitStatusType) Delete() error {
|
||||
if crud_LawsuitStatusType == nil {
|
||||
if Crud_LawsuitStatusType == nil {
|
||||
return constants.ErrorCrudIsNotInit
|
||||
}
|
||||
|
||||
err := crud_LawsuitStatusType.Delete(m)
|
||||
err := Crud_LawsuitStatusType.Delete(m)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Restore - снимает признак пометки удаления в БД
|
||||
func (m *LawsuitStatusType) Restore() error {
|
||||
if crud_LawsuitStatusType == nil {
|
||||
if Crud_LawsuitStatusType == nil {
|
||||
return constants.ErrorCrudIsNotInit
|
||||
}
|
||||
|
||||
err := crud_LawsuitStatusType.Restore(m)
|
||||
err := Crud_LawsuitStatusType.Restore(m)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Find_ByExtID - находит объект по ExtID
|
||||
func (m *LawsuitStatusType) Find_ByExtID() error {
|
||||
if crud_LawsuitStatusType == nil {
|
||||
if Crud_LawsuitStatusType == nil {
|
||||
return constants.ErrorCrudIsNotInit
|
||||
}
|
||||
|
||||
err := crud_LawsuitStatusType.Find_ByExtID(m)
|
||||
err := Crud_LawsuitStatusType.Find_ByExtID(m)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// SetCrudInterface - заполняет интерфейс crud: DB, GRPC, NRPC
|
||||
func (m LawsuitStatusType) SetCrudInterface(crud ICrud_LawsuitStatusType) {
|
||||
crud_LawsuitStatusType = crud
|
||||
Crud_LawsuitStatusType = crud
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -35,3 +35,7 @@ const SERVER_GRPC_FUNC_FILENAME = "server_grpc_func.go"
|
||||
|
||||
const MAKEFILE_FILENAME = "Makefile"
|
||||
const ENV_FILENAME = ".env"
|
||||
|
||||
const STARTER_TABLES_FILENAME = "starter_tables.go_"
|
||||
const STARTER_TABLES_FILENAME_TEST = "starter_tables_test.go_"
|
||||
const STARTER_TABLES_PREFIX = "crud_starter_"
|
||||
|
@ -98,6 +98,7 @@ import (
|
||||
sort.Strings(keys)
|
||||
|
||||
//все таблицы
|
||||
TextStarter := ""
|
||||
TextModel := ""
|
||||
TextDB := ""
|
||||
TextGRPC := ""
|
||||
@ -115,19 +116,29 @@ import (
|
||||
continue
|
||||
}
|
||||
|
||||
TextModel = TextModel + FindTextImportModel1(Table1)
|
||||
TextStarter = TextStarter + FindTextImportStarter1(Table1)
|
||||
//TextModel = TextModel + FindTextImportModel1(Table1)
|
||||
TextDB = TextDB + FindTextImportDB1(Table1)
|
||||
TextGRPC = TextGRPC + FindTextImportGRPC1(Table1)
|
||||
TextNRPC = TextNRPC + FindTextImportNRPC1(Table1)
|
||||
}
|
||||
|
||||
Otvet = Otvet + TextModel + "\n" + TextDB + "\n" + TextGRPC + "\n" + TextNRPC
|
||||
Otvet = Otvet + TextStarter + "\n" + TextModel + "\n" + TextDB + "\n" + TextGRPC + "\n" + TextNRPC
|
||||
|
||||
Otvet = Otvet + "\n)"
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextImportStarter1 - возвращает текст импорта crud_starter_ для 1 таблицы
|
||||
func FindTextImportStarter1(Table1 *types.Table) string {
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DB_URL := config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + "/" + constants.STARTER_TABLES_PREFIX + TableName
|
||||
Otvet := "\n\t\"" + DB_URL + `"`
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextImportModel1 - возвращает текст импорта Model для 1 таблицы
|
||||
func FindTextImportModel1(Table1 *types.Table) string {
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
@ -206,8 +217,7 @@ func InitCrudTransport_DB() {`
|
||||
// FindTextNRPC1 - возвращает текст всех функций .proto для таблицы
|
||||
func FindTextDB1(Table1 *types.Table) string {
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
ModelName := Table1.NameGo
|
||||
Otvet := "\n\t" + TableName + "." + ModelName + "{}.SetCrudInterface(" + config.Settings.PREFIX_CRUD + TableName + ".Crud_DB{})"
|
||||
Otvet := "\n\t" + constants.STARTER_TABLES_PREFIX + TableName + ".SetCrudInterface(" + config.Settings.PREFIX_CRUD + TableName + ".Crud_DB{})"
|
||||
|
||||
return Otvet
|
||||
}
|
||||
@ -255,8 +265,7 @@ func InitCrudTransport_GRPC() {`
|
||||
// FindTextNRPC1 - возвращает текст всех функций .proto для таблицы
|
||||
func FindTextGRPC1(Table1 *types.Table) string {
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
ModelName := Table1.NameGo
|
||||
Otvet := "\n\t" + TableName + "." + ModelName + "{}.SetCrudInterface(grpc_" + TableName + ".Crud_GRPC{})"
|
||||
Otvet := "\n\t" + constants.STARTER_TABLES_PREFIX + TableName + ".SetCrudInterface(grpc_" + TableName + ".Crud_GRPC{})"
|
||||
|
||||
return Otvet
|
||||
}
|
||||
@ -303,8 +312,7 @@ func InitCrudTransport_NRPC() {`
|
||||
// FindTextNRPC1 - возвращает текст всех функций .proto для таблицы
|
||||
func FindTextNRPC1(Table1 *types.Table) string {
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
ModelName := Table1.NameGo
|
||||
Otvet := "\n\t" + TableName + "." + ModelName + "{}.SetCrudInterface(nrpc_" + TableName + ".Crud_NRPC{})"
|
||||
Otvet := "\n\t" + constants.STARTER_TABLES_PREFIX + TableName + ".SetCrudInterface(nrpc_" + TableName + ".Crud_NRPC{})"
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
163
internal/create_files/crud_starter_tables/crud_starter_tables.go
Normal file
163
internal/create_files/crud_starter_tables/crud_starter_tables.go
Normal file
@ -0,0 +1,163 @@
|
||||
package crud_starter_tables
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/crud_generator/internal/config"
|
||||
"github.com/ManyakRus/crud_generator/internal/constants"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files"
|
||||
"github.com/ManyakRus/crud_generator/internal/folders"
|
||||
"github.com/ManyakRus/crud_generator/internal/types"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CreateAllFiles - создаёт все файлы в папке db
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.CheckGoodTable(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn(err1)
|
||||
continue
|
||||
}
|
||||
|
||||
//файлы starter
|
||||
if config.Settings.NEED_CREATE_DB == true {
|
||||
err = CreateFiles(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
//тестовые файлы starter
|
||||
if config.Settings.NEED_CREATE_DB_TEST == true {
|
||||
err = CreateTestFiles(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFiles - создаёт 1 файл в папке db
|
||||
func CreateFiles(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesDB := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile() + "starter_tables" + micro.SeparatorFile()
|
||||
DirReadyDB := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateDB := DirTemplatesDB + constants.STARTER_TABLES_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyDB + constants.STARTER_TABLES_PREFIX + TableName
|
||||
FilenameReadyDB := DirReadyTable + micro.SeparatorFile() + constants.STARTER_TABLES_PREFIX + TableName + ".go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateDB)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateDB, " error: ", err)
|
||||
}
|
||||
TextDB := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextDB = create_files.ReplacePackageName(TextDB, DirReadyTable)
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextDB = create_files.DeleteTemplateRepositoryImports(TextDB)
|
||||
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextDB = create_files.AddImport(TextDB, ModelTableURL)
|
||||
|
||||
}
|
||||
|
||||
//создание текста
|
||||
ModelName := Table1.NameGo
|
||||
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextDB = create_files.ReplaceServiceURLImports(TextDB)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextDB = create_files.DeleteEmptyImport(TextDB)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateTestFiles - создаёт 1 файл в папке db
|
||||
func CreateTestFiles(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesDB := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile() + "starter_tables" + micro.SeparatorFile()
|
||||
DirReadyDB := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateDB := DirTemplatesDB + constants.STARTER_TABLES_FILENAME_TEST
|
||||
DirReadyTable := DirReadyDB + constants.STARTER_TABLES_PREFIX + TableName
|
||||
FilenameReadyDB := DirReadyTable + micro.SeparatorFile() + constants.STARTER_TABLES_PREFIX + TableName + "_test.go"
|
||||
|
||||
//создадим папку готовых файлов
|
||||
folders.CreateFolder(DirReadyTable)
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateDB)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateDB, " error: ", err)
|
||||
}
|
||||
TextDB := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextDB = create_files.ReplacePackageName(TextDB, DirReadyTable)
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextDB = create_files.DeleteTemplateRepositoryImports(TextDB)
|
||||
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextDB = create_files.AddImport(TextDB, ModelTableURL)
|
||||
|
||||
}
|
||||
|
||||
//создание текста
|
||||
ModelName := Table1.NameGo
|
||||
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextDB = create_files.ReplaceServiceURLImports(TextDB)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextDB = create_files.DeleteEmptyImport(TextDB)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
@ -0,0 +1 @@
|
||||
package crud_starter_tables
|
@ -3,6 +3,7 @@ package logic
|
||||
import (
|
||||
"github.com/ManyakRus/crud_generator/internal/config"
|
||||
"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/db_crud_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/db_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/env_file"
|
||||
@ -162,6 +163,13 @@ func StartFillAll() error {
|
||||
return err
|
||||
}
|
||||
|
||||
//tables
|
||||
err = crud_starter_tables.CreateAllFiles(MapAll)
|
||||
if err != nil {
|
||||
//log.Error("db_tables.CreateAllFiles() error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//env
|
||||
err = env_file.CreateAllFiles()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user