-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
creating API to search the amount of doujins in database #2
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por favor, efetue as alterações indicadas na pull request.
@Boulkien
|
||
// return the data from document (in this case, the amount of doujins in database) | ||
if (!doujins.exists) { | ||
return res.send("There's nothing here") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faltou a definição de status code de retorno em cada condicional.
- Se doujin não existir: retornar 404
- Se doujin existir: retornar 200
return res.send("There's nothing here") | ||
} else { | ||
return res.json({ | ||
"amount of doujins": doujins.data() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chave muito change e não semântica, retorne chaves simples, pois o frontend precisará acessar. nunca use espaços em branco
incorreto: amount of doujins
resultado.amount of doujins // erro
correto: amountOfDoujins
resultado.amountOfDoujins // ok
backend/metadata/src/routes/index.js
Outdated
|
||
const routes = (app) => { | ||
app.route("/").get((req, res) => { | ||
res.status(200).send({ título: "O Alexandre está me fazendo de escravo"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rota de healthcheck precisa ser
/healthcheck
backend/metadata/src/routes/index.js
Outdated
res.status(200).send({ título: "O Alexandre está me fazendo de escravo"}) | ||
}) | ||
|
||
app.use( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
o correto no arquivo de rotas é importar do express Router
const { Router } = require("express");
const router = Router()
router.get(...)
module.exports = router;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exclua todos os app.use dessa rota, eles devem estar definidos no arquivo do servidor.
backend/metadata/src/app.js
Outdated
|
||
app.use(express.json()); | ||
|
||
routes(app); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O uso correto da instauração das rotas no aplicativo seria:
const routes = require("./routes");
app.use(express.json({
types: ["application/json"]
}));
app.use(routes);
backend/metadata/firebase/db.js
Outdated
const serviceAccount = require("../../eroneko-c890a77e5039.json") | ||
|
||
initializeApp({ | ||
credential: cert(serviceAccount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isso só funcionará localmente, uma vez que não subiremos as credenciais quando implantarmos o código no GCP.
faça a verificação da existência do arquivo baseado no caminho provido, caso o arquivo não exista, utilize as credenciais padrões do sistema.
ApplicationDefault()
backend/metadata/src/app.js
Outdated
@@ -1,10 +1,12 @@ | |||
const express = require("express"); | |||
const routes = require("./routes/index.js") | |||
const routes = require("./routes/Routes.js") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nome do arquivo em maiúsculo, alterar para routes.js.
importante seguir um padrão.
backend/metadata/firebase/db.js
Outdated
initializeApp({ | ||
credential: cert(serviceAccount) | ||
}) | ||
applicationDefault() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Não era para excluir a forma anterior, estava correta para o ambiente de desenvolvimento.
É necessária a criação de uma lógica para a utilização condicional de uma das duas dependendo do ambiente em que a aplicação está rodando.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fiz alguns comentários com poucas alterações. Uma vez que estiverem completas, podemos passar para a implantação e testar. Good Job 🤠
No description provided.