-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add type to room * Change room type default * Add type to room creation modal * Allow user to select movies
- Loading branch information
Showing
16 changed files
with
378 additions
and
47 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
58 changes: 58 additions & 0 deletions
58
prisma/migrations/20240303163024_add_type_to_room/migration.sql
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,58 @@ | ||
-- RedefineTables | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_Choice" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"albumId" TEXT NOT NULL, | ||
"albumImage" TEXT NOT NULL, | ||
"albumArtist" TEXT NOT NULL, | ||
"albumName" TEXT NOT NULL, | ||
"eliminated" BOOLEAN NOT NULL, | ||
"cssGradient" TEXT, | ||
"createdAt" INTEGER NOT NULL DEFAULT (strftime('%s', 'now')), | ||
"roomId" INTEGER NOT NULL, | ||
"userId" INTEGER NOT NULL, | ||
CONSTRAINT "Choice_roomId_fkey" FOREIGN KEY ("roomId") REFERENCES "Room" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT "Choice_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Choice" ("albumArtist", "albumId", "albumImage", "albumName", "createdAt", "cssGradient", "eliminated", "id", "roomId", "userId") SELECT "albumArtist", "albumId", "albumImage", "albumName", "createdAt", "cssGradient", "eliminated", "id", "roomId", "userId" FROM "Choice"; | ||
DROP TABLE "Choice"; | ||
ALTER TABLE "new_Choice" RENAME TO "Choice"; | ||
CREATE UNIQUE INDEX "Choice_roomId_userId_key" ON "Choice"("roomId", "userId"); | ||
CREATE TABLE "new_Room" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"linkId" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"step" TEXT NOT NULL DEFAULT 'selecting', | ||
"createdAt" INTEGER NOT NULL DEFAULT (strftime('%s', 'now')), | ||
"type" TEXT NOT NULL DEFAULT 'albums', | ||
"teamId" INTEGER NOT NULL, | ||
CONSTRAINT "Room_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Room" ("createdAt", "id", "linkId", "name", "step", "teamId") SELECT "createdAt", "id", "linkId", "name", "step", "teamId" FROM "Room"; | ||
DROP TABLE "Room"; | ||
ALTER TABLE "new_Room" RENAME TO "Room"; | ||
CREATE UNIQUE INDEX "Room_linkId_key" ON "Room"("linkId"); | ||
CREATE TABLE "new_User" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"email" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"image" TEXT, | ||
"provider" TEXT NOT NULL, | ||
"providerId" TEXT NOT NULL, | ||
"createdAt" INTEGER NOT NULL DEFAULT (strftime('%s', 'now')) | ||
); | ||
INSERT INTO "new_User" ("createdAt", "email", "id", "image", "name", "provider", "providerId") SELECT "createdAt", "email", "id", "image", "name", "provider", "providerId" FROM "User"; | ||
DROP TABLE "User"; | ||
ALTER TABLE "new_User" RENAME TO "User"; | ||
CREATE UNIQUE INDEX "User_provider_providerId_key" ON "User"("provider", "providerId"); | ||
CREATE TABLE "new_Team" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"name" TEXT NOT NULL, | ||
"createdAt" INTEGER NOT NULL DEFAULT (strftime('%s', 'now')), | ||
"invite" TEXT NOT NULL | ||
); | ||
INSERT INTO "new_Team" ("createdAt", "id", "invite", "name") SELECT "createdAt", "id", "invite", "name" FROM "Team"; | ||
DROP TABLE "Team"; | ||
ALTER TABLE "new_Team" RENAME TO "Team"; | ||
PRAGMA foreign_key_check; | ||
PRAGMA foreign_keys=ON; |
58 changes: 58 additions & 0 deletions
58
prisma/migrations/20240303163500_change_room_type_default_to_albums/migration.sql
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,58 @@ | ||
-- RedefineTables | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_Room" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"linkId" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"step" TEXT NOT NULL DEFAULT 'selecting', | ||
"createdAt" INTEGER NOT NULL DEFAULT (strftime('%s', 'now')), | ||
"type" TEXT NOT NULL DEFAULT 'albums', | ||
"teamId" INTEGER NOT NULL, | ||
CONSTRAINT "Room_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Room" ("createdAt", "id", "linkId", "name", "step", "teamId", "type") SELECT "createdAt", "id", "linkId", "name", "step", "teamId", "type" FROM "Room"; | ||
DROP TABLE "Room"; | ||
ALTER TABLE "new_Room" RENAME TO "Room"; | ||
CREATE UNIQUE INDEX "Room_linkId_key" ON "Room"("linkId"); | ||
CREATE TABLE "new_User" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"email" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"image" TEXT, | ||
"provider" TEXT NOT NULL, | ||
"providerId" TEXT NOT NULL, | ||
"createdAt" INTEGER NOT NULL DEFAULT (strftime('%s', 'now')) | ||
); | ||
INSERT INTO "new_User" ("createdAt", "email", "id", "image", "name", "provider", "providerId") SELECT "createdAt", "email", "id", "image", "name", "provider", "providerId" FROM "User"; | ||
DROP TABLE "User"; | ||
ALTER TABLE "new_User" RENAME TO "User"; | ||
CREATE UNIQUE INDEX "User_provider_providerId_key" ON "User"("provider", "providerId"); | ||
CREATE TABLE "new_Choice" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"albumId" TEXT NOT NULL, | ||
"albumImage" TEXT NOT NULL, | ||
"albumArtist" TEXT NOT NULL, | ||
"albumName" TEXT NOT NULL, | ||
"eliminated" BOOLEAN NOT NULL, | ||
"cssGradient" TEXT, | ||
"createdAt" INTEGER NOT NULL DEFAULT (strftime('%s', 'now')), | ||
"roomId" INTEGER NOT NULL, | ||
"userId" INTEGER NOT NULL, | ||
CONSTRAINT "Choice_roomId_fkey" FOREIGN KEY ("roomId") REFERENCES "Room" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT "Choice_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Choice" ("albumArtist", "albumId", "albumImage", "albumName", "createdAt", "cssGradient", "eliminated", "id", "roomId", "userId") SELECT "albumArtist", "albumId", "albumImage", "albumName", "createdAt", "cssGradient", "eliminated", "id", "roomId", "userId" FROM "Choice"; | ||
DROP TABLE "Choice"; | ||
ALTER TABLE "new_Choice" RENAME TO "Choice"; | ||
CREATE UNIQUE INDEX "Choice_roomId_userId_key" ON "Choice"("roomId", "userId"); | ||
CREATE TABLE "new_Team" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"name" TEXT NOT NULL, | ||
"createdAt" INTEGER NOT NULL DEFAULT (strftime('%s', 'now')), | ||
"invite" TEXT NOT NULL | ||
); | ||
INSERT INTO "new_Team" ("createdAt", "id", "invite", "name") SELECT "createdAt", "id", "invite", "name" FROM "Team"; | ||
DROP TABLE "Team"; | ||
ALTER TABLE "new_Team" RENAME TO "Team"; | ||
PRAGMA foreign_key_check; | ||
PRAGMA foreign_keys=ON; |
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,37 @@ | ||
import { env } from '$env/dynamic/private'; | ||
|
||
interface OmdbMovie { | ||
Title: string; | ||
Year: string; | ||
imdbID: string; | ||
Type: string; | ||
Poster: string; | ||
} | ||
|
||
interface OmdbSearchResponse { | ||
Search: OmdbMovie[]; | ||
totalResults: string; | ||
Response: string; | ||
} | ||
|
||
export const getToken = async () => { | ||
return env.OMDB_API_KEY; | ||
}; | ||
|
||
export const search = async (query: string, token: string): Promise<OmdbSearchResponse> => { | ||
const params = new URLSearchParams({ s: query, type: 'movie', apikey: token }); | ||
const res = await fetch(`https://www.omdbapi.com/?${params}`, { | ||
method: 'GET' | ||
}); | ||
|
||
return await res.json(); | ||
}; | ||
|
||
export const singleMovie = async (movieId: string, token: string): Promise<OmdbMovie> => { | ||
const params = new URLSearchParams({ i: movieId, apikey: token }); | ||
const res = await fetch(`https://www.omdbapi.com/?${params}`, { | ||
method: 'GET' | ||
}); | ||
|
||
return await res.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as OMDb from '$lib/server/omdb'; | ||
|
||
import type { RequestHandler } from './$types'; | ||
|
||
export const GET = (async ({ url }) => { | ||
const id = String(url.searchParams.get('id')); | ||
|
||
if (!id) { | ||
return new Response('No id', { status: 400 }); | ||
} | ||
|
||
const token = await OMDb.getToken(); | ||
const result = await OMDb.singleMovie(id, token); | ||
|
||
return new Response(JSON.stringify(result), { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
}) satisfies RequestHandler; |
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,37 @@ | ||
import { getToken, search } from '$lib/server/spotify'; | ||
import * as Spotify from '$lib/server/spotify'; | ||
import * as OMDb from '$lib/server/omdb'; | ||
|
||
import type { RequestHandler } from './$types'; | ||
|
||
export const GET = (async ({ url }) => { | ||
const query = String(url.searchParams.get('q')); | ||
const type = String(url.searchParams.get('type')); | ||
|
||
if (!query) { | ||
return new Response('No query', { status: 400 }); | ||
} else if (!type) { | ||
return new Response('No type', { status: 400 }); | ||
} | ||
|
||
if (type === 'albums') { | ||
const token = await Spotify.getToken(); | ||
const results = await Spotify.search(query, token); | ||
|
||
return new Response(JSON.stringify(results.albums.items), { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
} else if (type === 'movies') { | ||
const token = await OMDb.getToken(); | ||
const results = await OMDb.search(query, token); | ||
|
||
const token = await getToken(); | ||
const results = await search(query, token); | ||
return new Response(JSON.stringify(results.Search), { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
} | ||
|
||
return new Response(JSON.stringify(results.albums.items), { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
return new Response('Invalid type', { status: 400 }); | ||
}) satisfies RequestHandler; |
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.