Skip to content

Commit

Permalink
🐛 fixed bugs on inject new dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
booscaaa committed Jan 26, 2022
1 parent 287d554 commit 9e7986f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 44 deletions.
14 changes: 7 additions & 7 deletions cmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ func createData(screen, module, name string) {
}

tmpl := template.New("import-di.embed").Delims("[[", "]]")
tmpl, _ = tmpl.ParseFS(TemplateFs, "templates/single-command-repository/import-di.embed")
tmpl, _ = tmpl.ParseFS(util.TemplateFs, "templates/single-command-repository/import-di.embed")

var importDiText bytes.Buffer
tmpl.Execute(&importDiText, name)

importDiTextResult := importDiText.String()

tmpl = template.New("config-inject-di.embed").Delims("[[", "]]")
tmpl, _ = tmpl.ParseFS(TemplateFs, "templates/single-command-repository/config-inject-di.embed")
tmpl, _ = tmpl.ParseFS(util.TemplateFs, "templates/single-command-repository/config-inject-di.embed")

var configinjectDiText bytes.Buffer
tmpl.Execute(&configinjectDiText, name)
Expand All @@ -118,7 +118,7 @@ func createData(screen, module, name string) {
newDI.WriteString(importDiTextResult)
}

if strings.Contains(text, "const baseUrl") {
if strings.Contains(text, "const instance = axiosInstance") {
newDI.WriteString("\n")
newDI.WriteString(configinjectDiTextResult + "\n")
}
Expand Down Expand Up @@ -229,8 +229,8 @@ func init() {

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
repositoryCmd.Flags().StringP("screen", "p", "", "Nome do screen a ser criado")
repositoryCmd.Flags().StringP("module", "m", "", "Nome do module a ser criado")
repositoryCmd.Flags().StringP("name", "n", "", "Nome do repository a ser criado")
repositoryCmd.Flags().BoolP("delete", "d", false, "Deletar repository")
repositoryCmd.Flags().StringP("screen", "s", "", "The screen name to be created")
repositoryCmd.Flags().StringP("module", "m", "", "The module name to be created")
repositoryCmd.Flags().StringP("name", "n", "", "The repository name to be created")
repositoryCmd.Flags().BoolP("delete", "d", false, "Delete repository")
}
6 changes: 5 additions & 1 deletion cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ var templateCmd = &cobra.Command{
util.PopulateFiles(diPath+"/"+"di.js", "di.embed", "default", defaultTemplate)
}

if _, err := os.Stat(diPath + "/" + "axios.js"); os.IsNotExist(err) {
util.PopulateFiles(diPath+"/"+"axios.js", "axios.embed", "default", defaultTemplate)
}

if _, err := os.Stat(usecasePath); os.IsNotExist(err) {
os.MkdirAll(usecasePath, os.ModePerm)
}
Expand Down Expand Up @@ -150,7 +154,7 @@ func init() {

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
templateCmd.Flags().StringP("screen", "p", "", "The screen name to be created")
templateCmd.Flags().StringP("screen", "s", "", "The screen name to be created")
templateCmd.Flags().StringP("module", "m", "", "The module name to be created")
templateCmd.Flags().StringP("repositories", "r", "", "Name of repositories to be created separated by comma")
}
12 changes: 12 additions & 0 deletions templates/default/axios.embed
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from 'axios'

const axiosInstace = axios.create({
baseURL: process.env.VUE_APP_API_BASE_URL,
hearder: {
Accept: 'application/json',
'Content-Type': 'application/json',
Access: 'application/json',
},
})

export default axiosInstace
14 changes: 7 additions & 7 deletions templates/default/di.embed
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Handler from '../../../../core/util/Handler'
import axios from 'axios'
import axiosInstance from './axios'
[[ range .Repositories ]]
import [[ . ]]Repository from '../data/repository/[[ . ]]Repository'
import [[ . ]]UseCase from '../domain/usecase/[[ . ]]UseCase'
[[ end ]]
import [[ .Controller ]]Controller from '../controller/[[ .Programa ]]Controller'
import [[ .Controller ]]Controller from '../controller/[[ .Screen ]]Controller'

const instance = axiosInstance

const baseUrl = new Handler().getUrl()
[[ range .Repositories ]]
const [[ . ]]RepositoryImpl = [[ . ]]Repository(baseUrl, axios)
const [[ . ]]RepositoryImpl = [[ . ]]Repository(instance)
const [[ . ]]UseCaseImpl = [[ . ]]UseCase([[ . ]]RepositoryImpl)
[[ end ]]

const [[ .Programa ]]Controller = (context) =>
const [[ .Screen ]]Controller = (context) =>
new [[ .Controller ]]Controller(
context,[[ range .Repositories ]]
[[ . ]]UseCaseImpl,[[ end ]]
)

export { [[ .Programa ]]Controller }
export { [[ .Screen ]]Controller }
15 changes: 3 additions & 12 deletions templates/default/repository.embed
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import Handler from '../../../../../core/util/Handler'

const [[ . ]]Repository = (baseUrl, axios) => async (ablFilter) => {
const [[ . ]]Repository = (axios) => async () => {
try {
const response = await axios.get(`${baseUrl}/rest/TODO`, {
params: {
filter: {
ablFilter: ablFilter,
},
},
withCredentials: true,
})
const response = await axios.get('/rest/TODO')
return response //TODO
} catch (error) {
throw new Handler().trataErro(error)
throw error
}
}

Expand Down
4 changes: 2 additions & 2 deletions templates/default/usecase.embed
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const [[ . ]]UseCase = (repository) => async (query) => {
const [[ . ]]UseCase = (repository) => async () => {
try {
//TODO
return await repository(query)
return await repository()
} catch (error) {
throw error
}
Expand Down
4 changes: 2 additions & 2 deletions templates/default/vue.embed
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
</template>

<script>
import { [[ .Programa ]]Controller } from "../di/di";
import { [[ .Screen ]]Controller } from "../di/di";
export default {
data: (context) => ({
controller: [[ .Programa ]]Controller(context),
controller: [[ .Screen ]]Controller(context),
}),
mounted() {
this.controller.mounted();
Expand Down
2 changes: 1 addition & 1 deletion templates/single-command-repository/config-inject-di.embed
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const [[ . ]]RepositoryImpl = [[ . ]]Repository(baseUrl, axios)
const [[ . ]]RepositoryImpl = [[ . ]]Repository(instance)
const [[ . ]]UseCaseImpl = [[ . ]]UseCase([[ . ]]RepositoryImpl)
15 changes: 3 additions & 12 deletions templates/single-command-repository/repository.embed
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import Handler from '../../../../../core/util/Handler'

const [[ . ]]Repository = (baseUrl, axios) => async (ablFilter) => {
const [[ . ]]Repository = (axios) => async () => {
try {
const response = await axios.get(`${baseUrl}/rest/TODO`, {
params: {
filter: {
ablFilter: ablFilter,
},
},
withCredentials: true,
})
const response = await axios.get('/rest/TODO')
return response //TODO
} catch (error) {
throw new Handler().trataErro(error)
throw error
}
}

Expand Down

0 comments on commit 9e7986f

Please sign in to comment.