-
Notifications
You must be signed in to change notification settings - Fork 140
Zainab's PR #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zainabch123
wants to merge
12
commits into
boolean-uk:main
Choose a base branch
from
zainabch123:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Zainab's PR #149
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
37e5703
Added get movies, create movie, get movie by id, update movies functions
zainabch123 08cdddf
Added update customer function
zainabch123 756f933
Added create screen function
zainabch123 401e841
Added function to filter movies greater than runtimeGt and less than …
zainabch123 6308f8d
Added extra function to movies, customers. screens. tickets
zainabch123 abb8c90
Started errors
zainabch123 6a78a36
Added all errors
zainabch123 0cb0485
Added tests for extension functions
zainabch123 9be2b9a
Added tests for extension errors
zainabch123 14563df
Added function to get movies with future screening times
zainabch123 05e8a59
Tweaked code
zainabch123 5f5b935
Tweaked code again
zainabch123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,12 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - A unique constraint covering the columns `[title]` on the table `Movie` will be added. If there are existing duplicate values, this will fail. | ||
| - A unique constraint covering the columns `[number]` on the table `Screen` will be added. If there are existing duplicate values, this will fail. | ||
|
|
||
| */ | ||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "Movie_title_key" ON "Movie"("title"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "Screen_number_key" ON "Screen"("number"); |
This file contains hidden or 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 hidden or 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 hidden or 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,116 @@ | ||
| const { PrismaClientKnownRequestError } = require("@prisma/client"); | ||
| const prisma = require("../utils/prisma"); | ||
|
|
||
|
|
||
| const { | ||
| getAllMoviesdb, | ||
| createdMoviedb, | ||
| getMoviedb, | ||
| updatedMoviedb, | ||
| } = require("../domains/movies"); | ||
|
|
||
| const getAllMovies = async (req, res) => { | ||
| try { | ||
| const runtimeLt = Number(req.query.runtimeLt); | ||
| const runtimeGt = Number(req.query.runtimeGt); | ||
|
|
||
| const allMovies = await getAllMoviesdb(runtimeLt, runtimeGt); | ||
|
|
||
| res.status(200).json({ movies: allMovies }); | ||
| } catch (err) { | ||
| console.log("Error:", err); | ||
| } | ||
| }; | ||
|
|
||
| const createMovie = async (req, res) => { | ||
| const { title, runtimeMins, screenings } = req.body; | ||
|
|
||
| if (!title || !runtimeMins) { | ||
| return res.status(400).json({ | ||
| error: "Missing fields in request body", | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| const createdMovie = await createdMoviedb(title, runtimeMins, screenings); | ||
|
|
||
| res.status(201).json({ movie: createdMovie }); | ||
| } catch (err) { | ||
| if (err instanceof PrismaClientKnownRequestError) { | ||
| if (err.code === "P2002") { | ||
| return res.status(409).json({ | ||
| error: "A movie with the provided title already exists", | ||
| }); | ||
| } | ||
| } | ||
| res.status(500).json({ error: err.message }); | ||
| } | ||
| }; | ||
|
|
||
| const getMovieByID = async (req, res) => { | ||
| try { | ||
| const id = req.params.id; | ||
|
|
||
| const movie = await getMoviedb(id); | ||
| res.status(200).json({ movie: movie }); | ||
| } catch (err) { | ||
| if (err instanceof PrismaClientKnownRequestError) { | ||
| if (err.code === "P2025") { | ||
| return res.status(404).json({ | ||
| error: "A movie with that id does not exist", | ||
| }); | ||
| } | ||
| } | ||
| res.status(500).json({ error: err.message }); | ||
| } | ||
| }; | ||
|
|
||
| const updateMovie = async (req, res) => { | ||
| const id = Number(req.params.id); | ||
| const { title, runtimeMins, screenings } = req.body; | ||
|
|
||
| if (!title || !runtimeMins) { | ||
| return res.status(400).json({ | ||
| error: "Missing fields in request body", | ||
| }); | ||
| } | ||
|
|
||
| const existingTitle = await prisma.movie.findUnique({ | ||
| where: { | ||
| title: title, | ||
| }, | ||
| }); | ||
|
|
||
| if(existingTitle) { | ||
| return res.status(409).json({ | ||
| error: "Title already exists", | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| const updatedMovie = await updatedMoviedb( | ||
| id, | ||
| title, | ||
| runtimeMins, | ||
| screenings | ||
| ); | ||
|
|
||
| res.status(201).json({ movie: updatedMovie }); | ||
| } catch (err) { | ||
| if (err instanceof PrismaClientKnownRequestError) { | ||
| if (err.code === "P2025") { | ||
| return res.status(404).json({ | ||
| error: "A movie with that id does not exist", | ||
| }); | ||
| } | ||
| } | ||
| res.status(500).json({ error: err.message }); | ||
| } | ||
| }; | ||
|
|
||
| module.exports = { | ||
| getAllMovies, | ||
| createMovie, | ||
| getMovieByID, | ||
| updateMovie, | ||
| }; | ||
This file contains hidden or 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,31 @@ | ||
| const { PrismaClientKnownRequestError } = require("@prisma/client"); | ||
| const { createdScreendb } = require("../domains/screens"); | ||
|
|
||
| const createScreen = async (req, res) => { | ||
| const { number, screenings } = req.body; | ||
|
|
||
| if (!number) { | ||
| return res.status(400).json({ | ||
| error: "Missing fields in request body", | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| const createdScreen = await createdScreendb(number, screenings); | ||
|
|
||
| res.status(201).json({ screen: createdScreen }); | ||
| } catch (err) { | ||
| if (err instanceof PrismaClientKnownRequestError) { | ||
| if (err.code === "P2002") { | ||
| return res.status(409).json({ | ||
| error: "A screen with the provided number already exists", | ||
| }); | ||
| } | ||
| } | ||
| res.status(500).json({ error: err.message }); | ||
| } | ||
| }; | ||
|
|
||
| module.exports = { | ||
| createScreen, | ||
| }; |
This file contains hidden or 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,31 @@ | ||
| const { PrismaClientKnownRequestError } = require("@prisma/client"); | ||
| const { createdTicketdb } = require("../domains/tickets"); | ||
|
|
||
| const createTicket = async (req, res) => { | ||
| const { screeningId, customerId } = req.body; | ||
| if (!screeningId || !customerId) { | ||
| return res.status(400).json({ | ||
| error: "Missing fields in request body", | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| const createdTicket = await createdTicketdb(screeningId, customerId); | ||
|
|
||
| res.status(201).json({ ticket: createdTicket }); | ||
| } catch (err) { | ||
| if (err instanceof PrismaClientKnownRequestError) { | ||
| if (err.code === "P2003") { | ||
| return res.status(404).json({ | ||
| error: "A customer or screening does not exist with the provided id", | ||
| }); | ||
| } | ||
| } | ||
| res.status(500).json({ error: err.message }); | ||
|
|
||
| } | ||
| }; | ||
|
|
||
| module.exports = { | ||
| createTicket, | ||
| }; |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we'd typically send back just a 400 - bad request? but 500 is ok