mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 16:20:34 +07:00
fix: gofmt && little fixes
This commit is contained in:
@@ -12,7 +12,7 @@ type Field struct {
|
|||||||
Medatada []Metadata
|
Medatada []Metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
var PRIMITIVE_TYPES = map[string]string{
|
var PrimitiveTypes = map[string]string{
|
||||||
"date": "date",
|
"date": "date",
|
||||||
"number": "number",
|
"number": "number",
|
||||||
"string": "string",
|
"string": "string",
|
||||||
@@ -38,15 +38,15 @@ var PRIMITIVE_TYPES = map[string]string{
|
|||||||
func (f *Field) GenerateType() string {
|
func (f *Field) GenerateType() string {
|
||||||
result := " type: {\n"
|
result := " type: {\n"
|
||||||
|
|
||||||
keys := make([]string, 0, len(PRIMITIVE_TYPES))
|
keys := make([]string, 0, len(PrimitiveTypes))
|
||||||
for k := range PRIMITIVE_TYPES {
|
for k := range PrimitiveTypes {
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(keys, strings.ToLower(f.Type)) {
|
if slices.Contains(keys, strings.ToLower(f.Type)) {
|
||||||
result += fmt.Sprintf(` primitive: "%s",`, PRIMITIVE_TYPES[strings.ToLower(f.Type)])
|
result += fmt.Sprintf(` primitive: "%s",`, PrimitiveTypes[strings.ToLower(f.Type)])
|
||||||
} else {
|
} else {
|
||||||
var field string = "[]"
|
var field = "[]"
|
||||||
for _, meta := range f.Medatada {
|
for _, meta := range f.Medatada {
|
||||||
if meta.Name == "field" {
|
if meta.Name == "field" {
|
||||||
if len(meta.Values) > 0 {
|
if len(meta.Values) > 0 {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package generation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"nto_cli/utils"
|
"nto_cli/utils"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -20,11 +21,11 @@ import type { IService } from "%s"
|
|||||||
|
|
||||||
export default class %sService implements IService<%s> {
|
export default class %sService implements IService<%s> {
|
||||||
async read(id: number) {
|
async read(id: number) {
|
||||||
return await GetById(id)
|
return await GetById(id) as %s
|
||||||
}
|
}
|
||||||
|
|
||||||
async readAll() {
|
async readAll() {
|
||||||
return await GetAll() as %s
|
return await GetAll() as %s[]
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(item: %s) {
|
async create(item: %s) {
|
||||||
@@ -33,16 +34,18 @@ export default class %sService implements IService<%s> {
|
|||||||
|
|
||||||
async delete(id: number) {
|
async delete(id: number) {
|
||||||
return await Delete(id)
|
return await Delete(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(item: %s) {
|
async update(item: %s) {
|
||||||
await Update(item)
|
await Update(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
async count() {
|
async count() {
|
||||||
return await Count()
|
return await Count()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, utils.GetServiceBindPath(structName), structName, utils.GetServiceStructType(structName), utils.GetServiceType(), structName, structName, structName, structName))
|
`, utils.GetServiceBindPath(structName), structName, utils.GetServiceStructType(structName), utils.GetServiceType(), structName, structName, structName, structName, structName, structName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalf("Failed to write to file: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
func FindFrontendPath() string {
|
func FindFrontendPath() string {
|
||||||
currentPath, err := os.Getwd()
|
currentPath, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalf("Failed to find path for frontend: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var dirs []string
|
var dirs []string
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func GetStructList(filePath string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.Err() != nil {
|
if s.Err() != nil {
|
||||||
log.Fatalf("")
|
log.Fatalf("Unexpected scanner error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return structNames
|
return structNames
|
||||||
|
|||||||
@@ -18,4 +18,4 @@ func GetServiceStructType(structName string) string {
|
|||||||
func GetServiceType() string {
|
func GetServiceType() string {
|
||||||
path := "../types/service.type.ts"
|
path := "../types/service.type.ts"
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package utils
|
|||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
func SplitBySingleSpace(input string) []string {
|
func SplitBySingleSpace(input string) []string {
|
||||||
parts := strings.Split(strings.TrimSpace(input), " ")
|
parts := strings.Split(strings.TrimSpace(input), " ")
|
||||||
var result []string
|
var result []string
|
||||||
for _, p := range parts {
|
for _, p := range parts {
|
||||||
if p != "" {
|
if p != "" {
|
||||||
result = append(result, p)
|
result = append(result, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user