2023-08-25 15:05:28 +03:00
|
|
|
package prepare
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"git.ymnuktech.ru/ymnuk/yt-gen-app/lib/templ"
|
|
|
|
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
|
|
|
|
uuid "github.com/satori/go.uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
func prepareInterfaces(project *structs.Project) *structs.Project {
|
|
|
|
if len(project.Interfaces) == 0 {
|
|
|
|
return project
|
|
|
|
}
|
|
|
|
for i := range project.Interfaces {
|
|
|
|
project.Interfaces[i].Name = strings.Trim(project.Interfaces[i].Name, " ")
|
|
|
|
if project.Interfaces[i].Name == "" {
|
|
|
|
log.Fatal("Name interface is empty")
|
|
|
|
}
|
|
|
|
project.Interfaces[i].Name = templ.FieldNamePrepare(project.Interfaces[i].Name)
|
|
|
|
if project.Interfaces[i].ID == uuid.Nil {
|
|
|
|
project.Interfaces[i].ID = uuid.NewV4()
|
|
|
|
}
|
|
|
|
if len(project.Interfaces[i].Fields) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for j := range project.Interfaces[i].Fields {
|
2023-08-31 09:37:37 +03:00
|
|
|
if project.Interfaces[i].Fields[j].ID == uuid.Nil {
|
|
|
|
project.Interfaces[i].Fields[j].ID = uuid.NewV4()
|
|
|
|
}
|
2023-08-25 15:05:28 +03:00
|
|
|
project.Interfaces[i].Fields[j].Name = strings.Trim(project.Interfaces[i].Fields[j].Name, " ")
|
|
|
|
if project.Interfaces[i].Fields[j].Name == "" {
|
|
|
|
log.Fatalf("Field in interface %s should be set", project.Interfaces[i].Name)
|
|
|
|
}
|
|
|
|
project.Interfaces[i].Fields[j].Name = templ.FieldNamePrepare(project.Interfaces[i].Fields[j].Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return project
|
|
|
|
}
|