diff --git a/client/src/App.js b/client/src/App.js
index bf6adbb..f871d8f 100644
--- a/client/src/App.js
+++ b/client/src/App.js
@@ -82,10 +82,10 @@ function App() {
<>
{/* Milestone 1 */}
- Popular
+ All Games
Top Rated
- Upcoming
+ New
{
const { type } = useParams();
const getData = () => {
- fetch(`http://localhost:3001/games`)
+ if (type == "all") {
+ fetch(`http://localhost:3001/games/all`)
.then(res => {
console.log(res)
return res.json()
@@ -17,6 +18,28 @@ const GameList = () => {
console.log("data: ", data)
setGameList(data)
})
+ } else if (type == "top_rated") {
+ fetch(`http://localhost:3001/games/top_rated`)
+ .then(res => {
+ console.log(res)
+ return res.json()
+ })
+ .then(data => {
+ console.log("data: ", data)
+ setGameList(data)
+ })
+ } else {
+ fetch(`http://localhost:3001/games/new`)
+ .then(res => {
+ console.log(res)
+ return res.json()
+ })
+ .then(data => {
+ console.log("data: ", data)
+ setGameList(data)
+ })
+ }
+
}
diff --git a/server/routes/Games.js b/server/routes/Games.js
index fd42f86..317a495 100644
--- a/server/routes/Games.js
+++ b/server/routes/Games.js
@@ -3,7 +3,7 @@ const router = express.Router();
const db = require("../models/index");
-router.get("/", async (req, res) => {
+router.get("/all", async (req, res) => {
const [data, metaData] = await db.pool.query(
"select * from game order by name"
)
@@ -11,6 +11,20 @@ router.get("/", async (req, res) => {
res.json(data)
})
+router.get("/top_rated", async (req, res) => {
+ const [data, metaData] = await db.pool.query(
+ "select * from game order by rating desc"
+ )
+ res.json(data)
+})
+
+router.get("/new", async (req, res) => {
+ const [data, metaData] = await db.pool.query(
+ "select * from game order by release_year desc, release_month desc, release_day desc"
+ )
+ res.json(data)
+})
+
router.get("/:id", async (req, res) => {
const id = req.params.id;
// const post = await Posts.findByPk(id);