-
Notifications
You must be signed in to change notification settings - Fork 140
Myrthe Dullaart #138
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
MyrtheDullaart
wants to merge
21
commits into
boolean-uk:main
Choose a base branch
from
MyrtheDullaart: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
Myrthe Dullaart #138
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
58f934e
set up project
MyrtheDullaart 324db19
add functions to update customer
MyrtheDullaart 86547fa
add functions to get all movies
MyrtheDullaart 859a52a
add functions to create movie
MyrtheDullaart 7cc7076
add functions to get movie by id
MyrtheDullaart 71e0f30
add functions to update movie
MyrtheDullaart b36e3b9
add functions to create new screen
MyrtheDullaart a20e031
add functions to get movies by query parameters and create tests
MyrtheDullaart 454cc62
add functions to create screenings and create test
MyrtheDullaart 264c6a0
add get movie by title and clean up code
MyrtheDullaart c7e504d
create test to get movie by title
MyrtheDullaart 3ddfb6b
add functions to update screenings when updating movie and create tests
MyrtheDullaart a2bf500
add functions to create screenings when creating a screen and create …
MyrtheDullaart 464d6a7
add functions to create ticket and create tests
MyrtheDullaart 383a5ee
add error handling for missing fields
MyrtheDullaart c9c48fa
add not found error handling and tests
MyrtheDullaart b219bca
add not unique error handling and tests
MyrtheDullaart 43badf3
clean up code
MyrtheDullaart 0a1bc87
add function to only get future screentime movies
MyrtheDullaart fa98791
create review model and seed
MyrtheDullaart ec73e45
create test for creating a review
MyrtheDullaart 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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20240702135814_make_unique/migration.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "Review" ( | ||
| "id" SERIAL NOT NULL, | ||
| "content" TEXT NOT NULL, | ||
| "customerId" INTEGER NOT NULL, | ||
| "movieId" INTEGER NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
|
||
| CONSTRAINT "Review_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Review" ADD CONSTRAINT "Review_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "Customer"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Review" ADD CONSTRAINT "Review_movieId_fkey" FOREIGN KEY ("movieId") REFERENCES "Movie"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
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
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,87 @@ | ||
| const { PrismaClientKnownRequestError } = require("@prisma/client/runtime/library") | ||
| const { getAllMoviesDb, createMovieDb, getMovieByIdDb, updateMovieDb } = require("../domains/movie") | ||
| const MissingFieldsError = require("../errors/missingFieldsError") | ||
| const NotFoundError = require("../errors/notFoundError") | ||
| const NotUniqueError = require("../errors/notUniqueError") | ||
|
|
||
| async function getAllMovies(req, res) { | ||
| const runtimeLt = Number(req.query.runtimeLt) | ||
| const runtimeGt = Number(req.query.runtimeGt) | ||
|
|
||
| const movies = await getAllMoviesDb(runtimeLt, runtimeGt) | ||
|
|
||
| res.json({ | ||
| movies | ||
| }) | ||
| } | ||
|
|
||
| async function createMovie(req, res) { | ||
| const { title, runtimeMins, screenings } = req.body | ||
|
|
||
| if (!title || !runtimeMins) { | ||
| throw new MissingFieldsError('Missing fields in request body') | ||
| } | ||
|
|
||
| try { | ||
| const createdMovie = await createMovieDb(title, runtimeMins, screenings) | ||
|
|
||
| res.status(201).json({ | ||
| movie: createdMovie | ||
| }) | ||
| } catch (e) { | ||
| if (e instanceof PrismaClientKnownRequestError) { | ||
| if (e.code === "P2002") { | ||
| throw new NotUniqueError('A movie with the provided title already exists') | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function getMovieByIdOrTitle(req, res) { | ||
| const movieId = req.params.id | ||
|
|
||
| try { | ||
| const movie = await getMovieByIdDb(movieId) | ||
|
|
||
| res.json({ | ||
| movie | ||
| }) | ||
| } catch (e) { | ||
| if (e instanceof PrismaClientKnownRequestError) { | ||
| if (e.code === "P2025") { | ||
| throw new NotFoundError('Movie with that id or title does not exist') | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| async function updateMovie(req, res) { | ||
| const movieId = Number(req.params.id) | ||
| const { title, runtimeMins, screenings } = req.body | ||
|
|
||
| if (!title || !runtimeMins) { | ||
| throw new MissingFieldsError('Missing fields in request body') | ||
| } | ||
|
|
||
| try { | ||
| const updatedMovie = await updateMovieDb(movieId, title, runtimeMins, screenings) | ||
|
|
||
| res.status(201).json({ | ||
| movie: updatedMovie | ||
| }) | ||
| } catch (e) { | ||
| if (e instanceof PrismaClientKnownRequestError) { | ||
| if (e.code === "P2025") { | ||
| throw new NotFoundError('Movie with that id or title does not exist') | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| getAllMovies, | ||
| createMovie, | ||
| getMovieByIdOrTitle, | ||
| updateMovie | ||
| } |
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.
O(n^2)