149 lines
3.5 KiB
Go
149 lines
3.5 KiB
Go
package templ
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
|
|
)
|
|
|
|
func MethodSummary(value string) string {
|
|
// TODO
|
|
//log.Fatal("not released")
|
|
return value
|
|
}
|
|
|
|
func MethodComment(value string) string {
|
|
// TODO
|
|
//log.Fatal("not released")
|
|
return value
|
|
}
|
|
|
|
func GetModelName(project *structs.Project, value structs.VisField) string {
|
|
if value.Name == "binary" {
|
|
return "[]byte"
|
|
}
|
|
if project == nil {
|
|
log.Fatal("project is null")
|
|
}
|
|
for _, tbl := range project.DB.Tables {
|
|
if tbl.ID == value.ID {
|
|
return fmt.Sprintf("model.%s", FieldNamePrepare(tbl.Name))
|
|
}
|
|
}
|
|
for _, interf := range project.Interfaces {
|
|
if interf.ID == value.ID {
|
|
return fmt.Sprintf("structs.%s", FieldNamePrepare(interf.Name))
|
|
}
|
|
}
|
|
log.Fatal("model not found")
|
|
return ""
|
|
}
|
|
|
|
func GetModelNameAngular(project *structs.Project, value structs.VisField) string {
|
|
if project == nil {
|
|
log.Fatal("project is null")
|
|
}
|
|
if value.Name == "binary" {
|
|
return "any"
|
|
}
|
|
if value.Name == "user" {
|
|
return "ModelUser"
|
|
}
|
|
for _, tbl := range project.DB.Tables {
|
|
if tbl.ID == value.ID {
|
|
return fmt.Sprintf("Model%s", FieldNamePrepare(tbl.Name))
|
|
}
|
|
}
|
|
for _, interf := range project.Interfaces {
|
|
if interf.ID == value.ID {
|
|
return fmt.Sprintf("Structs%s", FieldNamePrepare(interf.Name))
|
|
}
|
|
}
|
|
log.Fatal("model not found")
|
|
return ""
|
|
}
|
|
|
|
func FieldInTableByName(name string, table *structs.Table) *structs.Field {
|
|
/*if table != nil && table.Name == "ratio_gender_age" {
|
|
fmt.Println(table)
|
|
}*/
|
|
for i := range table.Fields {
|
|
if table.Fields[i].Name == FieldNamePrepare(name) {
|
|
return &table.Fields[i]
|
|
}
|
|
}
|
|
for i := range table.FkFields {
|
|
//fmt.Println(FieldNamePrepare(name))
|
|
if table.FkFields[i].Name == FieldNamePrepare(name) ||
|
|
table.FkFields[i].Name+"ID" == FieldNamePrepare(name) ||
|
|
table.FkFields[i].Name+"Id" == FieldNamePrepare(name) {
|
|
|
|
return &structs.Field{
|
|
Name: table.FkFields[i].Name,
|
|
Type: table.FkFields[i].TypeParentTable,
|
|
}
|
|
}
|
|
}
|
|
log.Fatalf(`Field "%s" not found in "%s"`, name, table.Name)
|
|
return nil
|
|
}
|
|
|
|
func FieldStringToType(value interface{}, field *structs.Field) string {
|
|
//value = strings.ReplaceAll(value, "\"", "\\\"")
|
|
switch field.Type {
|
|
case "text":
|
|
return fmt.Sprintf("&[]string{`%s`}[0]", value)
|
|
case "string":
|
|
return fmt.Sprintf("&[]string{`%s`}[0]", value)
|
|
case "int":
|
|
return fmt.Sprintf("&[]int{%d}[0]", value)
|
|
case "bigint":
|
|
return fmt.Sprintf("&[]int64{%d}[0]", value)
|
|
case "double":
|
|
return fmt.Sprintf("&[]float64{%f}[0]", value)
|
|
case "float":
|
|
return fmt.Sprintf("&[]float32{%f}[0]", value)
|
|
case "uuid":
|
|
return fmt.Sprintf("&[]uuid.UUID{uuid.FromStringOrNil(`%s`)}[0]", value)
|
|
case "date":
|
|
return fmt.Sprintf("&[]time.Time{time.Parse(\"2006-01-02\",`%s`)}[0]", value)
|
|
case "time":
|
|
return fmt.Sprintf("&[]time.Time{time.Parse(\"2006-01-02 15:04:05\",`%s`)}[0]", value)
|
|
case "bool":
|
|
return fmt.Sprintf("&[]bool{%t}[0]", value)
|
|
case "any":
|
|
return fmt.Sprintf("&[]byte{%s}", value)
|
|
default:
|
|
fkTmp := &structs.Field{
|
|
Name: field.Type,
|
|
}
|
|
return fmt.Sprintf("&[]%s{%s}", FieldName(fkTmp), value)
|
|
//log.Fatalf("Unknow format %s", field.Type)
|
|
}
|
|
}
|
|
|
|
func DisplayMethodNamePost(value string) string {
|
|
// TODO
|
|
//log.Fatal("not released")
|
|
return value
|
|
}
|
|
|
|
func MethodNamePost(value string) string {
|
|
// TODO
|
|
//log.Fatal("not released")
|
|
return value
|
|
}
|
|
|
|
func DisplayMethodNameGet(value string) string {
|
|
// TODO
|
|
//log.Fatal("not released")
|
|
return value
|
|
}
|
|
|
|
func MethodNameGet(value string) string {
|
|
// TODO
|
|
//log.Fatal("not released")
|
|
return value
|
|
}
|