diff --git a/.gitignore b/.gitignore index 7f6e98f..08b230c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ main main.exe -frontend \ No newline at end of file +frontend +task.py \ No newline at end of file diff --git a/entities/field.go b/entities/field.go index bbef5bb..d4699b7 100644 --- a/entities/field.go +++ b/entities/field.go @@ -1,8 +1,7 @@ package entities type Field struct { - Name string - Type string + Name string + Type string Medatada []Medatada } - diff --git a/generation/gen.go b/generation/gen.go index 77565e9..6036360 100644 --- a/generation/gen.go +++ b/generation/gen.go @@ -9,7 +9,7 @@ import ( ) func Generate(structName string, fields []entities.Field) { - mkPath := strings.ToLower(fmt.Sprintf("%s/frontend/%s", utils.FindFrontendPath() , structName)) + mkPath := strings.ToLower(fmt.Sprintf("%s/frontend/src/%s", utils.FindFrontendPath() , structName)) if err := os.Mkdir(mkPath, 0755); err != nil { panic(err) } diff --git a/generation/service.go b/generation/service.go index 911f90f..5b40252 100644 --- a/generation/service.go +++ b/generation/service.go @@ -2,45 +2,64 @@ package generation import ( "fmt" - "nto_cli/utils" "os" "strings" ) func GetServiceBindPath(structName string) string { - path := utils.FindFrontendPath() - path += fmt.Sprintf("/bindings/app/internal/services/%sservice.ts", strings.ToLower(structName)) + path := fmt.Sprintf("../bindings/app/internal/services/%sservice.ts", strings.ToLower(structName)) + return path +} + +func GetServiceStructType(structName string) string { + path := "../bindings/app/internal/services/models.ts" + return path +} + +func GetServiceType() string { + path := "./types/service.type.ts" return path } func GenerateService(structName, mkPath string) { - serviceFile, err := os.Create(mkPath + "/" + strings.ToLower(structName) + ".service.ts") + serviceFile, err := os.Create(mkPath + "/" + strings.ToLower(structName) + ".service.ts") if err != nil { panic(err) } defer serviceFile.Close() - _, err = serviceFile.WriteString(fmt.Sprintf(`export class %sService { - async read() { - + _, err = serviceFile.WriteString( + fmt.Sprintf(`import { GetAll, Create, Delete, ExportToExcel, GetById, Update, Count } from "%s" +import type { %s } from "%s" +import type { Service } from "%s" + +export class %sService implements Service { + async read(id: number) { + return await GetById(id) } async readAll() { - + return await GetAll() } - async create() { - + async create(item: %s) { + return await Create(item) } - async delete() { - + async delete(item: %s) { + return await Delete(item) } - async update() { - + async update(item: %s) { + return await Update(item) + } + async count() { + return await Count() + } + async exportToExcel() { + return await ExportToExcel() } } -`, structName)) +`, GetServiceBindPath(structName), structName, GetServiceStructType(structName), GetServiceType(), structName, structName, structName, structName)) if err != nil { panic(err) } -} \ No newline at end of file +} diff --git a/utils/find_frontend_path.go b/utils/find_frontend_path.go index 512b423..fc4401e 100644 --- a/utils/find_frontend_path.go +++ b/utils/find_frontend_path.go @@ -3,7 +3,6 @@ package utils import ( "errors" "os" - "slices" "strings" ) @@ -13,8 +12,8 @@ func FindFrontendPath() string { panic(err) } dirs := strings.Split(currentPath, "\\") - if !slices.Contains(dirs, "frontend") { - panic(errors.New("Frontend dir doesn't exist")) + if dirs[len(dirs) - 2] + "/" + dirs[len(dirs) - 1] != "frontend/src" { + panic(errors.New("You're not in frontend/src")) } var path string for i, dir := range dirs {