forked from b00tc4mp/isdi-bootcamp-202405
-
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.
implement register game in api; implement register game logic and rea…
…ct in app b00tc4mp#84
- Loading branch information
Showing
22 changed files
with
197 additions
and
42 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import authenticateUserHandler from './authenticateUserHandler.js' | ||
import registerUserHandler from './registerUserHandler.js' | ||
import getUserUsernameHandler from './getUserUsernameHandler.js' | ||
import registerGameHandler from './registerGameHandler.js' | ||
|
||
const handle = { | ||
authenticateUser: authenticateUserHandler, | ||
registerUser: registerUserHandler, | ||
getUserUsername: getUserUsernameHandler | ||
getUserUsername: getUserUsernameHandler, | ||
registerGame: registerGameHandler | ||
} | ||
|
||
export default handle |
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,15 @@ | ||
import { logic } from 'core' | ||
|
||
export default (req, res, next) => { | ||
const { userId } = req | ||
|
||
const { name, image, description, link } = req.body | ||
|
||
try { | ||
logic.registerGame(userId, name, image, description, link) | ||
.then(() => res.status(201).send()) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
curl -v http://localhost:8080/games -X POST -d '{"userId":"66b9e687cfa7ce5e041652b3","name":"candy crush","image":"https://store-images.s-microsoft.com/image/apps.54354.13510798882606697.7a42c472-75d7-487e-9538-ebb5ce1657e6.372723d8-dd1a-450a-9fed-d420e7705e4e?mode=scale&q=90&h=300&w=200","description":"candy crush broh","link":"https://www.microsoft.com/en-us/p/candy-crush-saga/9nblggh18846?activetab=pivot:overviewtab"}' -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmI5NDExMTA5Mzg3ODY5NTVlY2YzYjUiLCJpYXQiOjE3MjM0NDk5MDN9.sE0z2XpU_e6AQlVnebsA9k7gtW8TITWrfEpP73zj3Dw" -H "Content-Type: application/json" |
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 |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import loginUser from './loginUser'; | ||
import logoutUser from './logoutUser'; | ||
import registerUser from './registerUser'; | ||
import isUserLoggedIn from './isUserLoggedIn'; | ||
import getUserUsername from './getUserUsername'; | ||
import loginUser from './loginUser.js' | ||
import logoutUser from './logoutUser.js' | ||
import registerUser from './registerUser.js' | ||
import isUserLoggedIn from './isUserLoggedIn.js' | ||
import getUserUsername from './getUserUsername.js' | ||
import registerGame from './registerGame.js' | ||
|
||
const logic = { | ||
loginUser, | ||
logoutUser, | ||
registerUser, | ||
isUserLoggedIn, | ||
getUserUsername | ||
getUserUsername, | ||
registerGame | ||
} | ||
|
||
export default logic |
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,36 @@ | ||
import { validate, errors } from 'com' | ||
|
||
const { SystemError } = errors | ||
|
||
export default (name, image, description, link) => { | ||
validate.string(name, 'name') | ||
validate.string(image, 'image') | ||
validate.string(description, 'description') | ||
validate.string(link, 'link') | ||
|
||
return fetch(`${import.meta.env.VITE_API_URL}/games`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${sessionStorage.token}`, | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ name, image, description, link }) | ||
}) | ||
.catch(error => { throw new SystemError(error.message) }) | ||
.then(response => { | ||
const { status } = response | ||
|
||
if (status === 201) return | ||
|
||
return response.json() | ||
.then(body => { | ||
const { error, message } = body | ||
|
||
const constructor = errors[error] | ||
|
||
throw new constructor(message) | ||
}) | ||
}) | ||
|
||
|
||
} |
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 |
---|---|---|
@@ -1,16 +1,11 @@ | ||
import logic from '../../logic' | ||
|
||
export default function Footer() { | ||
const handleAddGame = () => { | ||
|
||
} | ||
|
||
const handleRegisterGame = () => { | ||
|
||
} | ||
|
||
return <footer className='fixed w-screen p-2 bottom-0 left-0 flex flex-row justify-around items-center border border-solid border-t-black'> | ||
<button className='border border-solid border-black' onClick={handleAddGame}>Add Game</button> | ||
<button className='border border-solid border-black' onClick={handleRegisterGame}>Register Game</button> | ||
export default function Footer({ path, onSearchGame, onRegisterGame, onHome }) { | ||
return <footer className='fixed w-screen h-10 bottom-0 left-0 flex flex-row justify-around items-center border-t border-solid border-t-black z-10 bg-slate-700'> | ||
{path === '/' && <> | ||
<button className='border border-solid border-slate-500 bg-white px-2 rounded' onClick={onSearchGame}>Search Game</button> | ||
<button className='border border-solid border-slate-500 bg-white px-2 rounded' onClick={onRegisterGame}>Register Game</button> | ||
</>} | ||
{path === '/games/register' && <button className='border border-solid border-slate-500 bg-white px-2 rounded' onClick={onHome}>HOME</button>} | ||
</footer> | ||
} |
50 changes: 50 additions & 0 deletions
50
staff/marti-herms/project/V-HUB/app/src/home/GameRegister.jsx
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,50 @@ | ||
import Logo from '../library/Logo' | ||
import Container from '../library/Container' | ||
import Form from '../library/Form' | ||
import Input from '../library/Input' | ||
import Button from '../library/Button' | ||
|
||
import useContext from '../context' | ||
import logic from '../../logic' | ||
|
||
export default function GameRegister({ onGameRegister }) { | ||
const { alert } = useContext() | ||
|
||
const handleRegisterSubmit = (event) => { | ||
event.preventDefault() | ||
|
||
const form = event.target | ||
|
||
const nameInput = form['name-input'] | ||
const imageInput = form['image-input'] | ||
const descriptionInput = form['description-input'] | ||
const linkInput = form['link-input'] | ||
|
||
const name = nameInput.value | ||
const image = imageInput.value | ||
const description = descriptionInput.value | ||
const link = linkInput.value | ||
|
||
try { | ||
logic.registerGame(name, image, description, link) | ||
.then(gameId => onGameRegister(gameId)) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
} | ||
|
||
return <> | ||
<Container className='flex flex-col items-center w-full h-full dark:bg-[#1e1e1e]'> | ||
<Logo /> | ||
<Form className='gap-2' onSubmit={handleRegisterSubmit}> | ||
<Input id='name-input' type='text' placeholder='Name' /> | ||
<Input id='image-input' type='text' placeholder='Image' /> | ||
<Input id='description-input' type='text' placeholder='Description' /> | ||
<Input id='link-input' type='text' placeholder='Link' /> | ||
<Button type='submit' className='bg-rose-500 hover:bg-rose-800'>Register</Button> | ||
</Form> | ||
</Container> | ||
</> | ||
} |
Empty file.
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 |
---|---|---|
@@ -1,24 +1,48 @@ | ||
import { useState, useEffect } from 'react' | ||
|
||
import useContext from '../context' | ||
|
||
import logic from '../../logic' | ||
import { Route, Routes, useNavigate } from 'react-router-dom' | ||
|
||
import Header from './Header' | ||
import Library from './Library' | ||
import Footer from './Footer' | ||
import GameRegister from './GameRegister' | ||
|
||
export default function Home({ onLogout }) { | ||
const [path, setPath] = useState('/') | ||
|
||
const navigate = useNavigate() | ||
|
||
useEffect(() => { | ||
navigate(path) | ||
}, [path]) | ||
|
||
}) | ||
const handleHomeClick = () => { | ||
setPath('/') | ||
} | ||
|
||
return <main> | ||
<Header onLogoutClick={onLogout} ></Header> | ||
const handleRegisterGameClick = () => { | ||
setPath('/games/register') | ||
} | ||
|
||
const handleSearchGameClick = () => { | ||
setPath('/games/search') | ||
} | ||
|
||
const handleRegisterGame = (gameId) => { | ||
setPath(`/games/${gameId}`) | ||
} | ||
|
||
return <> | ||
<Header onLogoutClick={onLogout} ></Header> | ||
|
||
<Footer></Footer> | ||
</main> | ||
<main className='py-10 w-screen h-full dark:bg-[#1e1e1e]'> | ||
<Routes> | ||
<Route path='/' element={<p className='text-white'>Hello World</p>} /> | ||
<Route path='/games/register' element={<GameRegister onGameRegister={handleRegisterGame} />} /> | ||
<Route path='/games/search' /> | ||
<Route path='/games/:gameId' /> | ||
</Routes> | ||
</main> | ||
|
||
<Footer path={path} onSearchGame={handleSearchGameClick} onRegisterGame={handleRegisterGameClick} onHome={handleHomeClick} ></Footer> | ||
</> | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function Button({ className = '', children, ...nextProps }) { | ||
return <button className={className + 'w-8/12 h-16 text-4xl text-black rounded-md border border-solid border-black shadow-md shadow-black '} {...nextProps}>{children}</button> | ||
return <button className={className + ' w-8/12 h-16 text-4xl text-black rounded-md border border-solid border-black shadow-md shadow-black '} {...nextProps}>{children}</button> | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function Form({ className = '', children, onSubmit }) { | ||
return <form className={'flex flex-col m-auto w-full h-full justify-center items-center rounded-md shadow-md shadow-black ' + className} onSubmit={onSubmit}>{children}</form> | ||
return <form className={'flex flex-col w-full h-full justify-between items-center ' + className} onSubmit={onSubmit}>{children}</form> | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export default function Logo() { | ||
return <div className='bg-transparent box-content'> | ||
<img className='bg-transparent w-3/12 h-3/12' src='../images/logo.svg' alt='logo' /> | ||
<p className='relative text-white z-10 top-0'>V-HUB</p> | ||
<img className='relative top-0 bg-transparent w-3/12 h-3/12' src='../images/logo.svg' alt='logo' /> | ||
<p className='relative top-0 text-white z-10'>V-HUB</p> | ||
</div> | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function Paragraph({ children, className = '' }) { | ||
return <p className={`m-2 ${className}`}>{children}</p> | ||
return <p className={`m-2 dark:text-white ${className}`}>{children}</p> | ||
} |
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
Oops, something went wrong.