Skip to content

Commit

Permalink
Add Game Attr
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward-J-Xu committed Mar 27, 2023
1 parent 8a3950a commit 7d4776c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
8 changes: 4 additions & 4 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ function App() {
<>
{/* Milestone 1 */}
<Link
to="/games/popular"
to="/games/all"
style={{ textDecoration: "none" }}
>
<span>Popular</span>
<span>All Games</span>
</Link>
<Link
to="/games/top_rated"
Expand All @@ -94,10 +94,10 @@ function App() {
<span>Top Rated</span>
</Link>
<Link
to="/games/upcoming"
to="/games/new"
style={{ textDecoration: "none" }}
>
<span>Upcoming</span>
<span>New</span>
</Link>
<Link
to="/games/posts"
Expand Down
25 changes: 24 additions & 1 deletion client/src/components/gameList/gameList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const GameList = () => {
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()
Expand All @@ -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)
})
}

}


Expand Down
16 changes: 15 additions & 1 deletion server/routes/Games.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@ 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"
)
console.log("call get game api: ", data[0])
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);
Expand Down

0 comments on commit 7d4776c

Please sign in to comment.