codeedu / fc2-arquitetura-hexagonal Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Tarde pessoal,
na aula Enable e Disable Handlers e considerações finais do modulo, após a criação handler de disable e enable product, eu percebi que ele duplicava o registro no banco para arrumar isso e preciso arrumar no seguinte local:
PATH: /adapters/db/product.go
func (p *ProductDb) Save(product application.ProductInterface) (application.ProductInterface, error) {
var rows int
p.db.QueryRow(`select id from products where id=?`, product.GetID()).Scan(&rows)
if rows == 0 {
_, err := p.create(product)
if err != nil {
return nil, err
}
} else {
_, err := p.update(product)
if err != nil {
return nil, err
}
}
return product, nil
}
Desta forma vocês estão retornando o ID e na verdade querem um count(*) um quantidade de registros existente com aquele determinado ID, como esse select não faz um retorno do tipo int e sim um []string ele não consegue jogar o retorno na variável rows e o valor por padrão de um objeto declarado do tipo int e 0. Para arrumar esse comportamento sugiro essa alteração abaixo.
func (p *ProductDb) Save(product application.ProductInterface) (application.ProductInterface, error) {
var rows int
p.db.QueryRow(`select count(*) from products where id=?`, product.GetID()).Scan(&rows)
if rows == 0 {
_, err := p.create(product)
if err != nil {
return nil, err
}
} else {
_, err := p.update(product)
if err != nil {
return nil, err
}
}
return product, nil
}
Obrigado e até mais.
Ao rodar
docker build .
Estou tendo o seguinte erro
[+] Building 12.0s (6/11)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 38B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/golang:1.16 1.6s
=> [1/8] FROM docker.io/library/golang:1.16@sha256:5f6a4662de3efc6d6bb812d02e9de3d8698eea16b8eb7281f03e6f3e8383018e 0.0s
=> CACHED [2/8] WORKDIR /go/src 0.0s
=> ERROR [3/8] RUN go get -u github.com/spf13/cobra@latest && go install github.com/golang/mock/[email protected] && go 10.4s
------
> [3/8] RUN go get -u github.com/spf13/cobra@latest && go install github.com/golang/mock/[email protected] && go install github.com/spf13/cobra-cli@latest:
#6 10.38 go get github.com/spf13/cobra@latest: module github.com/spf13/cobra: Get "https://proxy.golang.org/github.com/spf13/cobra/@v/list": dial tcp: lookup proxy.golang.org on 172.17.192.1:53: read udp 172.17.0.2:38208->172.17.192.1:53: i/o timeout
------
executor failed running [/bin/sh -c go get -u github.com/spf13/cobra@latest && go install github.com/golang/mock/[email protected] && go install github.com/spf13/cobra-cli@latest]: exit code: 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.