Skip to content

Commit

Permalink
Merge pull request #36 from Edward-J-Xu/edward/final
Browse files Browse the repository at this point in the history
Add Game Pages
  • Loading branch information
Edward-J-Xu authored Mar 27, 2023
2 parents 6744d92 + 7d4776c commit 2edb637
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 22 deletions.
16 changes: 8 additions & 8 deletions SQL/createtables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ create table if not exists post
gid int not null,
title varchar(512) not null,
postText varchar(512) not null,
foreign key(username) references userA(username),
foreign key(gid) references game(game_id)
foreign key(username) references userA(username) on delete cascade,
foreign key(gid) references game(game_id) on delete cascade
);

create table if not exists comment
Expand All @@ -44,24 +44,24 @@ create table if not exists comment
comment_body varchar(512) not null,
post_id int not null,
username varchar(15) not null,
foreign key(username) references userA(username),
foreign key(post_id) references post(id)
foreign key(username) references userA(username) on delete cascade,
foreign key(post_id) references post(id) on delete cascade
);

create table if not exists likes
(
post_id int not null,
user_id int not null,
primary key(post_id, user_id),
foreign key(post_id) references post(id),
foreign key(user_id) references userA(id)
foreign key(post_id) references post(id) on delete cascade,
foreign key(user_id) references userA(id) on delete cascade
);

create table if not exists own
(
username varchar(15) not null,
gid int not null,
primary key(username, gid),
foreign key(username) references userA(username),
foreign key(gid) references game(game_id)
foreign key(username) references userA(username) on delete cascade,
foreign key(gid) references game(game_id) on delete cascade
);
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
4 changes: 0 additions & 4 deletions client/src/pages/posts/Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ function Post() {
<div key={key} className="comment">
{comment.comment_body}
<label> Username: {comment.username}</label>
{/* <AuthContext.Provider value={{ authState, setAuthState }}> */}
{/* {console.log("Auth User: ", authState.username)} */}
{/* <h1> Logged in: {authState.username} </h1> */}
{authState.username === comment.username && (
<button
onClick={() => {
Expand All @@ -166,7 +163,6 @@ function Post() {
X
</button>
)}
{/* </AuthContext.Provider> */}
</div>
);
})}
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/posts/createPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function CreatePost() {
postText: Yup.string().required(),
gameId: Yup.number()
.required()
.max(199, "Game ID must be less than 200"),
.max(153, "Game ID must be less than 154"),
});

const onSubmit = (data) => {
Expand Down Expand Up @@ -89,7 +89,7 @@ function CreatePost() {
autoComplete="off"
id="inputCreatePost"
name="gameId"
placeholder="(Between 1 and 199)"
placeholder="(Between 1 and 153)"
/>

<button type="submit"> Create Post</button>
Expand Down
1 change: 0 additions & 1 deletion client/src/pages/posts/postApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const PostApp = () => {
: "likeBttn"
}
/>
{/* {console.log("Liked[0]: ", value.Likes[0].id)} */}
<label>{value.Likes.length}</label>
</div>
</div>
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
2 changes: 1 addition & 1 deletion server/routes/Posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ router.post("/", validateToken, async (req, res) => {
router.delete("/:postId", validateToken, async (req, res) => {
const postId = req.params.postId;
try {
await db.pool.query("delete from posts where id = (?)", [postId]);
await db.pool.query("delete from post where id = (?)", [postId]);
res.json("DELETED SUCCESSFULLY");
} catch (e) {
console.log(e);
Expand Down

0 comments on commit 2edb637

Please sign in to comment.