Feat(BE-36,37,38,39): finish master data management api

This commit is contained in:
Hafizh A. Y
2025-10-03 21:04:21 +07:00
parent e8905be856
commit 2d49ffe4cd
103 changed files with 6974 additions and 117 deletions
+8 -7
View File
@@ -29,6 +29,7 @@ func main() {
feat := os.Args[1]
parts := strings.Split(feat, "/")
entity := parts[len(parts)-1]
pluralEntityKebab := toPlural(toKebab(entity))
d := Data{
FeatName: feat,
@@ -52,43 +53,43 @@ func main() {
},
{
TplPath: "tools/templates/validation.tmpl",
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), toKebab(d.Entity)+"s", "validations"),
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), pluralEntityKebab, "validations"),
OutSuffix: ".validation.go",
TplName: "validation",
},
{
TplPath: "tools/templates/service.tmpl",
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), toKebab(d.Entity)+"s", "services"),
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), pluralEntityKebab, "services"),
OutSuffix: ".service.go",
TplName: "service",
},
{
TplPath: "tools/templates/controller.tmpl",
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), toKebab(d.Entity)+"s", "controllers"),
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), pluralEntityKebab, "controllers"),
OutSuffix: ".controller.go",
TplName: "controller",
},
{
TplPath: "tools/templates/repository.tmpl",
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), toKebab(d.Entity)+"s", "repositories"),
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), pluralEntityKebab, "repositories"),
OutSuffix: ".repository.go",
TplName: "repository",
},
{
TplPath: "tools/templates/dto.tmpl",
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), toKebab(d.Entity)+"s", "dto"),
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), pluralEntityKebab, "dto"),
OutSuffix: ".dto.go",
TplName: "dto",
},
{
TplPath: "tools/templates/route.tmpl",
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), toKebab(d.Entity)+"s"),
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), pluralEntityKebab),
OutSuffix: "",
TplName: "route",
},
{
TplPath: "tools/templates/module.tmpl",
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), toKebab(d.Entity)+"s"),
OutDir: filepath.Join("internal", "modules", toKebabPath(d.Parts[:len(d.Parts)-1]), pluralEntityKebab),
OutSuffix: "",
TplName: "module",
},
+6
View File
@@ -56,4 +56,10 @@ func To{{Pascal .Entity}}ListDTOs(e []entity.{{Pascal .Entity}}) []{{Pascal .Ent
}
return result
}
func To{{Pascal .Entity}}DetailDTO(e entity.{{Pascal .Entity}}) {{Pascal .Entity}}DetailDTO {
return {{Pascal .Entity}}DetailDTO{
{{Pascal .Entity}}ListDTO: To{{Pascal .Entity}}ListDTO(e),
}
}
{{end}}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
type {{Pascal .Entity}} struct {
Id uint `gorm:"primaryKey"`
Name string `gorm:"not null"`
Name string `gorm:"not null;uniqueIndex:idx_name,where:deleted_at IS NULL"`
CreatedBy uint `gorm:"not null"`
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
+1 -1
View File
@@ -88,7 +88,7 @@ func (s *{{Camel .Entity}}Service) CreateOne(c *fiber.Ctx, req *validation.Creat
return nil, err
}
return createBody, nil
return s.GetOne(c, createBody.Id)
}
func (s {{Camel .Entity}}Service) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint) (*entity.{{Pascal .Entity}}, error) {
+1 -1
View File
@@ -5,7 +5,7 @@ type Create struct {
}
type Update struct {
Name *string `json:"name,omitempty" validate:"omitempty,max=50"`
Name *string `json:"name,omitempty" validate:"omitempty"`
}
type Query struct {