diff --git a/protoc-gen-go-crud/deliveries/template.go b/protoc-gen-go-crud/deliveries/template.go index 7906998..e61b3df 100644 --- a/protoc-gen-go-crud/deliveries/template.go +++ b/protoc-gen-go-crud/deliveries/template.go @@ -18,6 +18,16 @@ type {{.ServiceType}}Service struct { {{$firstLetter}}c usecase.I{{.ServiceType}}UseCase } +func New{{.ServiceType}}Service({{$firstLetter}}c usecase.I{{$svrType}}UseCase) {{$packageName}}.{{.ServiceType}}HTTPServer{ + return &{{.ServiceType}}Service{ + {{$firstLetter}}c: {{$firstLetter}}c, + } +} + +func (s *{{.ServiceType}}Service) log(ctx context.Context) *zap.SugaredLogger { + return global.Logger(ctx).Named("{{.ServiceType}}Service") +} + {{- range .MethodSets}} {{$request := .Request}} {{$reply := .Reply}} @@ -29,24 +39,12 @@ type {{.ServiceType}}Service struct { {{$reply = printf "%s.%s" .PackageName .Reply}} {{- end}} -func ({{$firstLetter}} {{$svrType}}Service){{.OriginalName}}(c *gin.Context, in *{{$request}})(*{{$reply}},error) { - panic("todo") +func (s *{{$svrType}}Service){{.OriginalName}}(c *gin.Context, in *{{$request}})(*{{$reply}},error) { + //TODO implement me + panic("implement me") } {{- end}} -func ({{$firstLetter}} {{.ServiceType}}Service) Log(c *gin.Context) *zap.SugaredLogger { - return global.Logger(c).Named("{{.ServiceType}}Repo") -} - -func New{{.ServiceType}}Service({{$firstLetter}}c usecase.I{{$svrType}}UseCase) {{$packageName}}.{{.ServiceType}}HTTPServer{ - return &{{.ServiceType}}Service{ - {{$firstLetter}}c: {{$firstLetter}}c, - } -} - - - - ` type serviceDesc struct { diff --git a/protoc-gen-go-crud/repositories/template.go b/protoc-gen-go-crud/repositories/template.go index efdbaa1..a0403f7 100644 --- a/protoc-gen-go-crud/repositories/template.go +++ b/protoc-gen-go-crud/repositories/template.go @@ -9,12 +9,12 @@ import ( var crudTemplate = ` type I{{.ServiceType}}Repo interface { + log(ctx context.Context) *zap.SugaredLogger Create{{.ServiceType}}(ctx context.Context, {{.ServiceType}} *entities.{{.ServiceType}}) error Update{{.ServiceType}}(ctx context.Context, updateFields []string,{{.ServiceType}} *entities.{{.ServiceType}}) error Get{{.ServiceType}}(ctx context.Context, id entity.ID) (*entities.{{.ServiceType}}, error) Get{{.ServiceType}}s(ctx context.Context, filter *database.Filter) (res []*entities.{{.ServiceType}}, count int64, err error) Delete{{.ServiceType}}(ctx context.Context, id entity.ID) error - Log(ctx context.Context) *zap.SugaredLogger } @@ -22,40 +22,45 @@ type I{{.ServiceType}}Repo interface { {{$entityName := (GetEntityName .ServiceType)}} -type {{.ServiceType}}Repo struct { -} +type {{.ServiceType}}Repo struct {} -func ({{$firstLetter}} *{{.ServiceType}}Repo) DB(ctx context.Context) *gorm.DB { - return global.DBFromContext(ctx).Model(&entities.{{.ServiceType}}{}) +func New{{.ServiceType}}Repo() I{{.ServiceType}}Repo{ + return &{{.ServiceType}}Repo{} } -func ({{$firstLetter}} {{.ServiceType}}Repo) Create{{.ServiceType}}(ctx context.Context, {{$entityName}} *entities.{{.ServiceType}}) error { - panic("todo") +func ({{$firstLetter}} *{{.ServiceType}}Repo) log(ctx context.Context) *zap.SugaredLogger { + return global.Logger(ctx).Named("{{.ServiceType}}Repo") } -func ({{$firstLetter}} {{.ServiceType}}Repo) Update{{.ServiceType}}(ctx context.Context, updateFields []string, {{$entityName}} *entities.{{.ServiceType}}) error { - panic("todo") +func ({{$firstLetter}} *{{.ServiceType}}Repo) DB(ctx context.Context) *gorm.DB { + return global.DBFromContext(ctx).Model(&entities.{{.ServiceType}}{}) } -func ({{$firstLetter}} {{.ServiceType}}Repo) Get{{.ServiceType}}(ctx context.Context, id entity.ID) (*entities.{{.ServiceType}}, error) { - panic("todo") +func (r *{{.ServiceType}}Repo) Create{{.ServiceType}}(ctx context.Context, {{$entityName}} *entities.{{.ServiceType}}) error { + //TODO implement me + panic("implement me") } -func ({{$firstLetter}} {{.ServiceType}}Repo) Delete{{.ServiceType}}(ctx context.Context, id entity.ID) error { - panic("todo") +func (r *{{.ServiceType}}Repo) Update{{.ServiceType}}(ctx context.Context, updateFields []string, {{$entityName}} *entities.{{.ServiceType}}) error { + //TODO implement me + panic("implement me") } -func ({{$firstLetter}} {{.ServiceType}}Repo) Get{{.ServiceType}}s(ctx context.Context, filter *database.Filter) (res []*entities.{{.ServiceType}}, count int64, err error) { - panic("todo") +func (r *{{.ServiceType}}Repo) Get{{.ServiceType}}(ctx context.Context, id entity.ID) (*entities.{{.ServiceType}}, error) { + //TODO implement me + panic("implement me") } -func ({{$firstLetter}} {{.ServiceType}}Repo) Log(ctx context.Context) *zap.SugaredLogger { - return global.Logger(ctx).Named("{{.ServiceType}}Repo") +func (r *{{.ServiceType}}Repo) Delete{{.ServiceType}}(ctx context.Context, id entity.ID) error { + //TODO implement me + panic("implement me") } -func New{{.ServiceType}}Repo() I{{.ServiceType}}Repo{ - return &{{.ServiceType}}Repo{} +func (r *{{.ServiceType}}Repo) Get{{.ServiceType}}s(ctx context.Context, filter *database.Filter) (res []*entities.{{.ServiceType}}, count int64, err error) { + //TODO implement me + panic("implement me") } + ` type serviceDesc struct { diff --git a/protoc-gen-go-crud/usecase/template.go b/protoc-gen-go-crud/usecase/template.go index ccd558e..c277860 100644 --- a/protoc-gen-go-crud/usecase/template.go +++ b/protoc-gen-go-crud/usecase/template.go @@ -12,45 +12,51 @@ var crudTemplate = ` type I{{.ServiceType}}UseCase interface { + log(ctx context.Context) *zap.SugaredLogger Create{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Create{{.ServiceType}}Request) error Update{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Update{{.ServiceType}}Request) error Delete{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Delete{{.ServiceType}}Request) error Get{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Get{{.ServiceType}}Request) (*entities.{{.ServiceType}},error) List{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.List{{.ServiceType}}Request) ([]*entities.{{.ServiceType}},int64,error) - Log(ctx context.Context) *zap.SugaredLogger } -type {{.ServiceType}}UseCase struct { -} +type {{.ServiceType}}UseCase struct {} func New{{.ServiceType}}UseCase() I{{.ServiceType}}UseCase { return &{{.ServiceType}}UseCase{} } -func ({{$firstLetter}} *{{.ServiceType}}UseCase) Create{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Create{{.ServiceType}}Request) error { - panic("todo") +func (uc *{{.ServiceType}}UseCase) log(ctx context.Context) *zap.SugaredLogger { + return global.Logger(ctx).Named("{{.ServiceType}}UseCase") } -func ({{$firstLetter}} *{{.ServiceType}}UseCase) Update{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Update{{.ServiceType}}Request) error { - panic("todo") +func (uc *{{.ServiceType}}UseCase) Create{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Create{{.ServiceType}}Request) error { + //TODO implement me + panic("implement me") } -func ({{$firstLetter}} *{{.ServiceType}}UseCase) Delete{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Delete{{.ServiceType}}Request) error{ - panic("todo") +func (uc *{{.ServiceType}}UseCase) Update{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Update{{.ServiceType}}Request) error { + //TODO implement me + panic("implement me") } -func ({{$firstLetter}} *{{.ServiceType}}UseCase) Get{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Get{{.ServiceType}}Request) (*entities.{{.ServiceType}},error){ - panic("todo") +func (uc *{{.ServiceType}}UseCase) Delete{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Delete{{.ServiceType}}Request) error{ + //TODO implement me + panic("implement me") } -func ({{$firstLetter}} *{{.ServiceType}}UseCase) List{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.List{{.ServiceType}}Request) ([]*entities.{{.ServiceType}},int64,error){ - panic("todo") +func (uc *{{.ServiceType}}UseCase) Get{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.Get{{.ServiceType}}Request) (*entities.{{.ServiceType}},error){ + //TODO implement me + panic("implement me") } -func ({{$firstLetter}} {{.ServiceType}}UseCase) Log(ctx context.Context) *zap.SugaredLogger { - return global.Logger(ctx).Named("{{.ServiceType}}Repo") +func (uc *{{.ServiceType}}UseCase) List{{.ServiceType}}(ctx context.Context,in *{{.PackageName}}.List{{.ServiceType}}Request) ([]*entities.{{.ServiceType}},int64,error){ + //TODO implement me + panic("implement me") } + + ` type serviceDesc struct {