-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from fga-eps-mds/i11_Visualizar_informacoes_so…
…bre_a_planta I11 visualizar informacoes sobre a planta
- Loading branch information
Showing
12 changed files
with
1,673 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/node_modules | ||
.env | ||
package-lock.json | ||
yarn.lock | ||
yarn.lock |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
app : { | ||
port: process.env.PORT || 3000, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const CommentSchema = new mongoose.Schema({ | ||
username: { | ||
type: String, | ||
require : true | ||
}, | ||
message: { | ||
type: String, | ||
require: true | ||
}, | ||
vote_count:{ | ||
type: Number, | ||
require:true | ||
} | ||
|
||
}); | ||
|
||
|
||
const Comment = mongoose.model('comment',CommentSchema); | ||
|
||
module.exports = Comment; | ||
//Exemplo de teste insominia | ||
//{ | ||
// "scientificName":"scientificName", | ||
// "family_name":"family_name", | ||
// "gender_name":"gender_name", | ||
// "specie_name":"specie_name", | ||
// "usage":"usage", | ||
// "first_User":"first_User", | ||
// "collection_count":"17", | ||
// "extinction":"1", | ||
// "profile_picture":"7", | ||
// "gbifID":"17", | ||
// "stateProvince":"brasilia" | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const PlantSchema = new mongoose.Schema({ | ||
scientificName: { | ||
type: String, | ||
require: true, | ||
unique: true | ||
}, | ||
family_name: { | ||
type: String, | ||
require: true | ||
}, | ||
gender_name: { | ||
type: String, | ||
require: true | ||
}, | ||
specie_name: { | ||
type: String, | ||
require: true | ||
}, | ||
common_name: { | ||
type: String, | ||
require: true | ||
}, | ||
usage: { | ||
type: String, | ||
require: true | ||
}, | ||
first_User: { | ||
type: String, | ||
require: true | ||
}, | ||
collection_count: { | ||
type: Number, | ||
require: true | ||
}, | ||
extinction: { | ||
type: Boolean, | ||
require: true | ||
}, | ||
profile_picture: { | ||
type: String, | ||
require : true | ||
}, | ||
gbifID: { | ||
type: Number, | ||
require: true, | ||
}, | ||
stateProvince: { | ||
type: String, | ||
require : true | ||
}, | ||
topicos: [{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'topic', | ||
|
||
}], | ||
}); | ||
|
||
|
||
const Plant = mongoose.model('plant',PlantSchema); | ||
|
||
module.exports = Plant; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const TopicoSchema = new mongoose.Schema({ | ||
plant:{ | ||
type:mongoose.Schema.Types.ObjectId, | ||
ref:'plant', | ||
require:true | ||
|
||
}, | ||
description: { | ||
type: String, | ||
require: true | ||
} | ||
|
||
}); | ||
|
||
|
||
|
||
const Topico = mongoose.model('topic',TopicoSchema); | ||
|
||
module.exports = Topico; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const express = require('express'); | ||
const Plant = require('../models/Plant'); | ||
const Topico = require('../models/Topico'); | ||
const Comment = require('../models/Comment'); | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/register', async (req , res) => { | ||
try{ | ||
const comment = await Comment.create(req.body); | ||
|
||
return res.send({ comment }); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'Registration failed'}); | ||
} | ||
}); | ||
|
||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const express = require('express'); | ||
|
||
const Plant = require('../models/Plant'); | ||
const Topico = require('../models/Topico'); | ||
|
||
const router = express.Router(); | ||
|
||
//registro de uma nova planta | ||
router.post('/register', async (req , res) => { | ||
try{ | ||
const { scientificName,family_name,gender_name,specie_name,common_name,usage,first_User,collection_count,extinction,profile_picture, gbifID,stateProvince,topicos} = req.body; | ||
|
||
const plant = await Plant.create({scientificName,family_name,gender_name,specie_name,common_name,usage,first_User,collection_count,extinction,profile_picture, gbifID,stateProvince}); | ||
|
||
// await Promise.all(topicos.map(async topico =>{ | ||
// const plantTopic = new Topico({...topico,plant : plant._id}); | ||
|
||
// await plantTopic.save(); | ||
|
||
// plant.topicos.push(plantTopic); | ||
// })); | ||
|
||
await plant.save(); | ||
|
||
return res.send({ plant }); | ||
}catch (err){ | ||
return res.send(err); | ||
} | ||
}); | ||
//Listagem de Todas as plantas | ||
router.get('/', async (req , res) => { | ||
try{ | ||
const plants = await Plant.find().populate('topicos'); | ||
|
||
return res.send({ plants }); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'Loading plants failed'}); | ||
} | ||
}); | ||
//Procurando planta por id | ||
router.get('/:plantId', async (req , res) => { | ||
try{ | ||
const plant = await Plant.findById(req.params.plantId).populate('topicos'); | ||
|
||
return res.send({ plant }); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'error when searching for this plant '}); | ||
} | ||
}); | ||
//Deletando planta por id | ||
router.delete('/:plantId', async (req , res) => { | ||
try{ | ||
const deleted = await Plant.findByIdAndRemove(req.params.plantId); | ||
|
||
return res.send(deleted); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'Error when Delete this plant'}); | ||
} | ||
}); | ||
//Dando upgrade planta por id | ||
router.put('/:plantId', async (req , res) => { | ||
|
||
try{ | ||
const { scientificName,family_name,gender_name,specie_name,common_name,usage,first_User,collection_count,extinction,profile_picture, gbifID,stateProvince,topicos} = req.body; | ||
|
||
const plant = await Plant.findByIdAndUpdate(req.params.plantId, | ||
{scientificName,family_name,gender_name,specie_name,common_name,usage,first_User,collection_count,extinction,profile_picture, gbifID,stateProvince},{ new: true}); | ||
|
||
plant.topicos = []; | ||
await Topico.remove({plant: plant._id}); | ||
|
||
await Promise.all(topicos.map(async topico =>{ | ||
const plantTopic = new Topico({...topico,plant : plant._id}); | ||
|
||
await plantTopic.save(); | ||
|
||
plant.topicos.push(plantTopic); | ||
})); | ||
|
||
await plant.save(); | ||
|
||
|
||
return res.send({ plant }); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'Registration failed'}); | ||
} | ||
|
||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const express = require('express'); | ||
const Plant = require('../models/Plant'); | ||
const Topico = require('../models/Topico'); | ||
|
||
const router = express.Router(); | ||
//Criar um novo topico pelo id da planta | ||
router.put('/:plantId', async (req , res) => { | ||
try{ | ||
const {topicos} = req.body; | ||
const plant = await Plant.findByIdAndUpdate(req.params.plantId, | ||
{},{ new: true}).populate('topicos'); | ||
await Promise.all(topicos.map(async topico =>{ | ||
const plantTopic = new Topico({...topico,plant : plant._id}); | ||
|
||
await plantTopic.save(); | ||
|
||
plant.topicos.push(plantTopic); | ||
})); | ||
await plant.save(); | ||
return res.send({ plant }); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'Registration failed'}); | ||
} | ||
}); | ||
//Listando todos os topics | ||
router.get('/', async (req , res) => { | ||
try{ | ||
const topics = await Topico.find(); | ||
return res.send({ topics }); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'Loading plants failed'}); | ||
} | ||
}); | ||
//Procurando topic por id | ||
router.get('/:topicId', async (req , res) => { | ||
try{ | ||
const topico = await Topico.findById(req.params.topicId); | ||
return res.send({ topico }); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'error when searching for this topic '}); | ||
} | ||
}); | ||
//Deletando topic por id | ||
router.delete('/:topicId', async (req , res) => { | ||
try{ | ||
await Topico.findByIdAndRemove(req.params.topicId); | ||
return res.send(); | ||
}catch (err){ | ||
return res.status(400).send({ error: 'Error when Delete this topic'}); | ||
} | ||
}); | ||
//Dando upgrade topic por id | ||
router.put('/:topicId', async (req , res) => { | ||
try{ | ||
await Topico.findByIdAndUpdate(req.params.topicId,{description: 'marcos felipe'},{new : true}); | ||
return res.send(); | ||
}catch (err){ | ||
console.log(err); | ||
return res.status(400).send({ error: 'Error when Delete this plant'}); | ||
} | ||
}); | ||
|
||
module.exports = router; |
Oops, something went wrong.