1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-16 21:52:42 +02:00
crud_generator/internal/logic/logic.go

74 lines
1.5 KiB
Go
Raw Normal View History

2023-09-28 16:45:44 +02:00
package logic
import (
2023-09-28 17:08:00 +02:00
"github.com/ManyakRus/crud_generator/internal/constants"
2023-09-28 16:45:44 +02:00
"github.com/ManyakRus/crud_generator/internal/postgres"
"github.com/ManyakRus/crud_generator/internal/types"
"github.com/ManyakRus/starter/log"
2023-09-28 17:08:00 +02:00
"github.com/ManyakRus/starter/micro"
2023-09-28 16:45:44 +02:00
)
//var MassTable []types.Table
2023-09-28 17:08:00 +02:00
func StartFillAll() bool {
2023-09-28 16:45:44 +02:00
Otvet := false
//заполним MapAll
MapAll, err := postgres.FillMapTable()
if err != nil {
log.Error("FillMapTable() error: ", err)
return Otvet
}
if len(MapAll) > 0 {
Otvet = true
}
if Otvet == false {
println("warning: Empty file not saved !")
return Otvet
}
2023-09-28 17:08:00 +02:00
err = CreateModelFiles(MapAll)
2023-09-28 16:45:44 +02:00
return Otvet
}
2023-09-28 17:08:00 +02:00
//// MassFromMapColumns - возвращает Slice из Map
//func MassFromMapColumns(MapColumns map[string]types.Column) []types.Column {
// Otvet := make([]types.Column, 0)
//
// for _, v := range MapColumns {
// Otvet = append(Otvet, v)
// }
//
// sort.Slice(Otvet[:], func(i, j int) bool {
// return Otvet[i].OrderNumber < Otvet[j].OrderNumber
// })
//
// return Otvet
//}
func CreateModelFiles(MapAll map[string]*types.Table) error {
2023-09-28 16:45:44 +02:00
var err error
2023-09-28 17:08:00 +02:00
for _, table1 := range MapAll {
err = CreateModelFiles1(table1)
if err != nil {
return err
2023-09-28 16:45:44 +02:00
}
}
return err
}
2023-09-28 17:08:00 +02:00
func CreateModelFiles1(table1 *types.Table) error {
2023-09-28 16:45:44 +02:00
var err error
2023-09-28 17:08:00 +02:00
DirBin := micro.ProgramDir_bin()
DirTemplates := DirBin + constants.FolderTemplates + micro.SeparatorFile()
DirReady := DirBin + constants.FolderReady + micro.SeparatorFile()
2023-09-28 16:45:44 +02:00
return err
}