2023-08-02 16:04:17 +03:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"git.ymnuktech.ru/ymnuk/yt-gen-app/lib/templ"
|
|
|
|
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func generateBackendRest() {
|
|
|
|
|
2023-08-11 12:28:30 +03:00
|
|
|
/*type RestStruct struct {
|
2023-08-02 16:04:17 +03:00
|
|
|
Path string
|
|
|
|
Project *structs.Project
|
|
|
|
Rest *structs.Rest
|
2023-08-11 12:28:30 +03:00
|
|
|
}*/
|
2023-08-02 16:04:17 +03:00
|
|
|
|
|
|
|
if len(Project.Backend.Rest) > 0 {
|
|
|
|
for i := range Project.Backend.Rest {
|
2023-08-11 12:28:30 +03:00
|
|
|
restStruct := &structs.RestStruct{
|
2023-08-25 15:05:28 +03:00
|
|
|
Project: Project,
|
|
|
|
Path: templ.ParseRestPath(i),
|
|
|
|
PathPackageName: templ.ParseRestPathForName(i),
|
|
|
|
Rest: Project.Backend.Rest[i],
|
|
|
|
PathParams: templ.ParseRestPathParams(i),
|
2023-08-02 16:04:17 +03:00
|
|
|
}
|
2023-08-25 15:05:28 +03:00
|
|
|
destPath := filepath.Join(AppConfig.OutdirBackend, "route", "api", templ.BackendFsPath(i))
|
2023-08-02 16:04:17 +03:00
|
|
|
fmt.Println(destPath)
|
|
|
|
if err := templ.PrepareTmplFile("tmpl/backend/route/api/templ/index.tmpl", restStruct, filepath.Join(destPath, "index.go")); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-08-09 14:45:36 +03:00
|
|
|
|
|
|
|
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/list.tmpl", restStruct, filepath.Join(destPath, "list.go")); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/count.tmpl", restStruct, filepath.Join(destPath, "count.go")); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/get.tmpl", restStruct, filepath.Join(destPath, "get.go")); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/search.tmpl", restStruct, filepath.Join(destPath, "search.go")); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-08-17 23:21:09 +03:00
|
|
|
if Project.Backend.Rest[i].Editable {
|
|
|
|
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/post.tmpl", restStruct, filepath.Join(destPath, "post.go")); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/put.tmpl", restStruct, filepath.Join(destPath, "put.go")); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/delete.tmpl", restStruct, filepath.Join(destPath, "delete.go")); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2023-08-02 16:04:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|