Closed wesonweb closed 5 months ago
Next I need to look at the 'plant problems' section of the form as it needs to be dynamic ie there may be no problems so it can be ignored or several problems can be added dynamically. The schema has it as an array of strings. Also need to check for accessibility and see if there are any refactors I can make on the code.
Form to add plants to the database
Image storage
Front end
submitPlantData
function sends the image and the rest of the plant object to the backend endpoint/api/plants/new-plant
Back end
.env
fileimage
now becomes an object to save bothid
andurl
returned by CloudinarycreatePlant
controller inserver/controllers/plantController
so that once the endpoint receives the plant object it gets sent to Cloudinary and then returns the plant imageid
andurl
json
response to the front endScreenshots
Completed the form using a test plant and an image of a spider plant. The image was sent and stored in Cloudinary:
Console log of the![resJson-response](https://github.com/wesonweb/houseyourplants_app/assets/6653884/19e9d7fd-2fe4-4350-8e77-4c3f231bd607)
res.json(newPlant)
received in the front endtested on Postman to GET all plants from MongoDB - screenshot shows the spider plant
MongoDB screenshot confirming plant is there![mongoDB](https://github.com/wesonweb/houseyourplants_app/assets/6653884/5025717e-5e74-4824-af49-d5e5cdb40272)