-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using database instead of local file for fish
- Loading branch information
1 parent
3c9a272
commit 6c77905
Showing
10 changed files
with
274 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const Bugs = require('../models/bugs'); | ||
|
||
const { | ||
v4: uuidv4 | ||
} = require("uuid"); | ||
const S3 = require("aws-sdk/clients/s3"); | ||
const s3 = new S3(); // initialize the S3 constructor | ||
|
||
const BUCKET = process.env.BUCKET; | ||
|
||
module.exports = { | ||
index | ||
} | ||
|
||
|
||
|
||
|
||
async function index(req, res) { | ||
try { | ||
// this populates the user when you find the bugs | ||
// so you'll have access to the users information | ||
// when you fetch teh bugs | ||
const bugs = await Bugs.find({}).exec(); | ||
res.status(200).json({ | ||
bugs: bugs | ||
}); | ||
} catch (err) { | ||
res.status(400).json({ | ||
err | ||
}); | ||
} | ||
} |
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,35 @@ | ||
const Fish = require('../models/fish'); | ||
|
||
const { | ||
v4: uuidv4 | ||
} = require("uuid"); | ||
const S3 = require("aws-sdk/clients/s3"); | ||
const s3 = new S3(); // initialize the S3 constructor | ||
|
||
const BUCKET = process.env.BUCKET; | ||
|
||
module.exports = { | ||
index, | ||
|
||
} | ||
|
||
|
||
|
||
|
||
async function index(req, res) { | ||
try { | ||
// this populates the user when you find the fish | ||
// so you'll have access to the users information | ||
// when you fetch teh fish | ||
const fish = await Fish.find({}); | ||
// console.log(res.fish, 'fish') | ||
// console.log(res.json, 'json') | ||
res.status(200).json({ | ||
fish: fish | ||
}); | ||
} catch (err) { | ||
res.status(400).json({ | ||
err | ||
}); | ||
} | ||
} |
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,80 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const caughtSchema = mongoose.Schema({ | ||
|
||
username: String, | ||
userId: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User' | ||
} | ||
}); | ||
|
||
const bugsSchema = new mongoose.Schema({ | ||
id: Number, | ||
bug_name: String, | ||
price: Number, | ||
img: String, | ||
location: String, | ||
hemisphere: { | ||
north: { | ||
January: Boolean, | ||
February: Boolean, | ||
March: Boolean, | ||
April: Boolean, | ||
May: Boolean, | ||
June: Boolean, | ||
July: Boolean, | ||
August: Boolean, | ||
October: Boolean, | ||
September: Boolean, | ||
November: Boolean, | ||
December: Boolean, | ||
}, | ||
south: { | ||
January: Boolean, | ||
February: Boolean, | ||
March: Boolean, | ||
April: Boolean, | ||
May: Boolean, | ||
June: Boolean, | ||
July: Boolean, | ||
August: Boolean, | ||
October: Boolean, | ||
September: Boolean, | ||
November: Boolean, | ||
December: Boolean, | ||
} | ||
}, | ||
time: String, | ||
time_available: { | ||
h_0: Boolean, | ||
h_1: Boolean, | ||
h_2: Boolean, | ||
h_3: Boolean, | ||
h_4: Boolean, | ||
h_4: Boolean, | ||
h_5: Boolean, | ||
h_6: Boolean, | ||
h_7: Boolean, | ||
h_8: Boolean, | ||
h_9: Boolean, | ||
h_10: Boolean, | ||
h_11: Boolean, | ||
h_12: Boolean, | ||
h_13: Boolean, | ||
h_14: Boolean, | ||
h_15: Boolean, | ||
h_16: Boolean, | ||
h_17: Boolean, | ||
h_18: Boolean, | ||
h_19: Boolean, | ||
h_20: Boolean, | ||
h_21: Boolean, | ||
h_22: Boolean, | ||
h_23: Boolean | ||
}, | ||
caught: [caughtSchema] // < one post has many likes | ||
}); | ||
|
||
|
||
module.exports = mongoose.model('Bugs', bugsSchema); |
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,69 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const caughtSchema = mongoose.Schema({ | ||
|
||
username: String, | ||
userId: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User' | ||
} | ||
}); | ||
const months = mongoose.Schema({ | ||
January: Boolean, | ||
February: Boolean, | ||
March: Boolean, | ||
April: Boolean, | ||
May: Boolean, | ||
June: Boolean, | ||
July: Boolean, | ||
August: Boolean, | ||
October: Boolean, | ||
September: Boolean, | ||
November: Boolean, | ||
December: Boolean | ||
}) | ||
const hours = mongoose.Schema({ | ||
h_0: Boolean, | ||
h_1: Boolean, | ||
h_2: Boolean, | ||
h_3: Boolean, | ||
h_4: Boolean, | ||
h_4: Boolean, | ||
h_5: Boolean, | ||
h_6: Boolean, | ||
h_7: Boolean, | ||
h_8: Boolean, | ||
h_9: Boolean, | ||
h_10: Boolean, | ||
h_11: Boolean, | ||
h_12: Boolean, | ||
h_13: Boolean, | ||
h_14: Boolean, | ||
h_15: Boolean, | ||
h_16: Boolean, | ||
h_17: Boolean, | ||
h_18: Boolean, | ||
h_19: Boolean, | ||
h_20: Boolean, | ||
h_21: Boolean, | ||
h_22: Boolean, | ||
h_23: Boolean | ||
}) | ||
|
||
const fishSchema = new mongoose.Schema({ | ||
id: Number, | ||
bug_name: String, | ||
price: Number, | ||
img: String, | ||
shadow_size: String, | ||
hemisphere: [{ | ||
north: [months], | ||
south: [months] | ||
}], | ||
time: String, | ||
time_available: [hours], | ||
caught: [caughtSchema] // < one post has many likes | ||
}); | ||
|
||
|
||
module.exports = mongoose.model('Fish', fishSchema); |
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,13 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const fishCtrl = require('../../controllers/fish'); | ||
|
||
|
||
// /*---------- Public Routes ----------*/ | ||
|
||
router.get('/', fishCtrl.index) | ||
|
||
|
||
|
||
|
||
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
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 |
---|---|---|
|
@@ -446,6 +446,8 @@ const BugData = [{ | |
"h_23": true | ||
} | ||
}, | ||
|
||
//now | ||
{ | ||
"id": 26, | ||
"bug_name": "Brown Cicada", | ||
|
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
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,16 @@ | ||
import tokenService from "./tokenService" | ||
|
||
const BASE_URL = '/api/fish/' | ||
|
||
|
||
export function getAll() { | ||
return fetch(BASE_URL, { | ||
headers: { | ||
'Authorization': 'Bearer ' + tokenService.getToken() | ||
} | ||
}) | ||
.then(res => { | ||
if (res.ok) return res.json() | ||
throw new Error('Problem Fetching Gel All') | ||
}) | ||
} |