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 getUserUsername logic and tests; implement first home react…
… iteration b00tc4mp#84
- Loading branch information
Showing
25 changed files
with
270 additions
and
54 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
staff/marti-herms/project/V-HUB/api/handlers/getUserUsernameHandler.js
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,9 +1,11 @@ | ||
import authenticateUserHandler from './authenticateUserHandler.js' | ||
import registerUserHandler from './registerUserHandler.js' | ||
import getUserUsernameHandler from './getUserUsernameHandler.js' | ||
|
||
const handle = { | ||
authenticateUser: authenticateUserHandler, | ||
registerUser: registerUserHandler | ||
registerUser: registerUserHandler, | ||
getUserUsername: getUserUsernameHandler | ||
} | ||
|
||
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
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 @@ | ||
curl -v http://localhost:8080/users/66b941110938786955ecf3b5/username -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmI5NDExMTA5Mzg3ODY5NTVlY2YzYjUiLCJpYXQiOjE3MjM0NDk5MDN9.sE0z2XpU_e6AQlVnebsA9k7gtW8TITWrfEpP73zj3Dw" |
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 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> | ||
</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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useState, useEffect } from 'react' | ||
|
||
import useContext from '../context' | ||
|
||
import logic from '../../logic' | ||
|
||
import Paragraph from '../library/Paragraph' | ||
|
||
export default function Header({ onLogoutClick }) { | ||
const [username, setUsername] = useState(null) | ||
|
||
useEffect(() => { | ||
try { | ||
logic.getUserUsername() | ||
.then(username => setUsername(username)) | ||
.catch(error => { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
}) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
}, []) | ||
|
||
return <header className='flex flex-row justify-end px-4 border border-solid border-b-black'> | ||
<Paragraph>{username}</Paragraph> | ||
<button onClick={onLogoutClick}>Logout</button> | ||
</header> | ||
} |
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,11 @@ | ||
import { useState, useEffect } from 'react' | ||
|
||
|
||
|
||
export default function Library() { | ||
const [games, setGames] = useState(null) | ||
|
||
return <div> | ||
{games.map()} | ||
</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,25 +1,24 @@ | ||
import { useState, useEffect } from "react" | ||
import { useState, useEffect } from 'react' | ||
|
||
import useContext from '../context' | ||
|
||
export default function Home() { | ||
const [username, setUsername] = useState(null) | ||
import logic from '../../logic' | ||
|
||
import Header from './Header' | ||
import Library from './Library' | ||
import Footer from './Footer' | ||
|
||
export default function Home({ onLogout }) { | ||
|
||
useEffect(() => { | ||
try { | ||
logic.getUserUsername() | ||
.then(username => setName(username)) | ||
.catch(error => { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
}) | ||
} catch (error) { | ||
console.error(error) | ||
|
||
alert(error.message) | ||
} | ||
|
||
}) | ||
|
||
return <p>Hello, {username}</p> | ||
return <main> | ||
<Header onLogoutClick={onLogout} ></Header> | ||
|
||
|
||
|
||
<Footer></Footer> | ||
</main> | ||
} |
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={'w-8/12 h-16 text-4xl text-black rounded-md border border-solid border-black shadow-md shadow-black ' + className} {...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,7 @@ | ||
export default function Checkbox({ className = '', ...nextProps }) { | ||
return <input type='checkbox' {...nextProps} /> | ||
export default function Checkbox({ className = '', id, ...nextProps }) { | ||
return <> | ||
<label htmlFor={id}> | ||
<input type='checkbox' id={id} {...nextProps} /> Game Dev | ||
</label> | ||
</> | ||
} |
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 bg-[#616161] w-[500px] h-5/6 justify-center items-center rounded-md shadow-md shadow-black ' + className} onSubmit={onSubmit}>{children}</form> | ||
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> | ||
} |
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,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> | ||
</div> | ||
} |
3 changes: 0 additions & 3 deletions
3
staff/marti-herms/project/V-HUB/app/src/library/VSeparator.jsx
This file was deleted.
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
2 changes: 1 addition & 1 deletion
2
staff/marti-herms/project/V-HUB/app/util/extractPayloadFromToken.js
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 |
---|---|---|
|
@@ -19,7 +19,6 @@ const user = new Schema({ | |
}, | ||
avatar: { | ||
type: String, | ||
required: true | ||
}, | ||
role: { | ||
type: String, | ||
|
24 changes: 24 additions & 0 deletions
24
staff/marti-herms/project/V-HUB/core/logic/getUserUsername.js
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,24 @@ | ||
import { User } from '../data/models.js' | ||
|
||
import { validate, errors } from 'com' | ||
|
||
const { NotFoundError, SystemError } = errors | ||
|
||
export default (userId, targetUserId) => { | ||
validate.string(userId, 'userId') | ||
validate.string(targetUserId, 'targetUserId') | ||
|
||
return User.findById(userId).lean() | ||
.catch(error => { throw new SystemError(error.message) }) | ||
.then(user => { | ||
if (!user) throw new NotFoundError('user not found') | ||
|
||
return User.findById(targetUserId).lean() | ||
.catch(error => { throw new SystemError(error.message) }) | ||
}) | ||
.then(user => { | ||
if (!user) throw new NotFoundError('targetUser not found') | ||
|
||
return user.username | ||
}) | ||
} |
Oops, something went wrong.