Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,11 @@ The flow of the application you build looks like this:
Take a little bit of time to familiarise yourself with the project structure - this exercise has both a front-end React
app (`src/client/`) *and* a back-end express API (`src/server/`) in it.

1. Fork this repository and clone the fork.
1. If you want to use the more challenging `freedom` branch, remember to UNCHECK the checkbox for "Copy the
`main` branch only"

<img src="./assets/forking_screenshot.png" alt="forking screenshot" width=600></img>
2. Then, once you have cloned your fork of the repo, you can run `git checkout freedom` in your terminal.
3. If you do not uncheck this box, then you will only be able to access the `main` branch.
2. Rename `.env.example` to `.env`
3. Edit the `DATABASE_URL` variable in `.env`, swapping `YOUR_DATABASE_URL` for the URL of your database
4. Run `npm ci` to install the project dependencies.
5. If you're using the main branch, we have already created the Prisma schema and migrations for you. Run `npx prisma migrate reset` to execute the
database migrations. Press `y` when it asks if you're sure.
**Note:** Since you are using the freedom branch, all we've done is add the require dependencies and place (almost) empty index files into the src/ sub-directories. Everything else is up to you.

1. Rename `.env.example` to `.env`
2. Edit the `DATABASE_URL` variable in `.env`, swapping `YOUR_DATABASE_URL` for the URL of your database
3. Run `npm ci` to install the project dependencies.

## Instructions

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
<title>Auth Challenge</title>
</head>
<body>
<div id="root"></div>
Expand Down
28 changes: 0 additions & 28 deletions prisma/migrations/20220211144514_init/migration.sql

This file was deleted.

3 changes: 0 additions & 3 deletions prisma/migrations/migration_lock.toml

This file was deleted.

29 changes: 0 additions & 29 deletions prisma/schema.prisma

This file was deleted.

67 changes: 1 addition & 66 deletions src/client/App.jsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,10 @@
import { useEffect, useState } from 'react';
import './App.css';
import MovieForm from './components/MovieForm';
import UserForm from './components/UserForm';

const port = import.meta.env.VITE_PORT;
const apiUrl = `http://localhost:${port}`;

function App() {
const [movies, setMovies] = useState([]);

useEffect(() => {
fetch(`${apiUrl}/movie`)
.then(res => res.json())
.then(res => setMovies(res.data));
}, []);

/**
* HINTS!
* 1. This handle___ functions below use async/await to handle promises, but the
* useEffect above is using .then to handle them. Both are valid approaches, but
* we should ideally use one or the other. Pick whichever you prefer.
*
* 2. The default method for the `fetch` API is to make a GET request. To make other
* types of requests, we must provide an object as the second argument of `fetch`.
* The values that you must provide are:
* - method
* - headers
* - body (if needed)
* For the "headers" property, you must state the content type of the body, i.e.:
* headers: {
* 'Content-Type': 'application/json'
* }
* */

const handleRegister = async ({ username, password }) => {

};

const handleLogin = async ({ username, password }) => {

};

const handleCreateMovie = async ({ title, description, runtimeMins }) => {

}

return (
<div className="App">
<h1>Register</h1>
<UserForm handleSubmit={handleRegister} />

<h1>Login</h1>
<UserForm handleSubmit={handleLogin} />

<h1>Create a movie</h1>
<MovieForm handleSubmit={handleCreateMovie} />

<h1>Movie list</h1>
<ul>
{movies.map(movie => {
return (
<li key={movie.id}>
<h3>{movie.title}</h3>
<p>Description: {movie.description}</p>
<p>Runtime: {movie.runtimeMins}</p>
</li>
);
})}
</ul>
</div>
);
return <></>;
}

export default App;
28 changes: 0 additions & 28 deletions src/client/components/MovieForm.jsx

This file was deleted.

27 changes: 0 additions & 27 deletions src/client/components/UserForm.jsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/server/controllers/movie.js

This file was deleted.

39 changes: 0 additions & 39 deletions src/server/controllers/user.js

This file was deleted.

29 changes: 0 additions & 29 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,7 @@
import { config } from 'dotenv';
config();

// Import express and cors
import express from 'express';
import cors from 'cors';

// Set up express
const app = express();
app.disable('x-powered-by');
app.use(cors());
// Tell express to use a JSON parser middleware
app.use(express.json());
// Tell express to use a URL Encoding middleware
app.use(express.urlencoded({ extended: true }));




import userRouter from './routers/user.js';
app.use('/user', userRouter);

import movieRouter from './routers/movie.js';
app.use('/movie', movieRouter);




// Set up a default "catch all" route to use when someone visits a route
// that we haven't built
app.get('*', (req, res) => {
res.json({ ok: true });
});

// Start our API server
const port = process.env.VITE_PORT;
Expand Down
9 changes: 0 additions & 9 deletions src/server/routers/movie.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/server/routers/user.js

This file was deleted.