-
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.
* feat(backend): add route to create a room, and methods to add it in the database * feat(frontend) : added a part of the frontend of the creating a room page * fix(backend) : fixing CORS problem * fix(backend) : fixing code smell for parameters checking in RoomPost, and reformat code with prettier * feat(frontend) : end of the frontend before review * feat(frontend) : Adjustement on CSS and frontend in general * chore : Adding an endpoint for streaming services and using it in frontend * chore : Giving directly the streaming service id to the createRoom methods of room.ts instead of the service name * fix(frontend) : changed backend url to make them dynamic * chore: deleting assets files of spotify and souncloud logo. Also renaming components file with maj * fix: Using cookies to create supabase clients and retrieve id * chore: Adding a method to create supabase client * refactor: fixed rooms routing * chore(deps): updated package-lock.json * refactor(backend): changed endpoint of streaming services * style(ui): improved style of CustomTextInput * refactor(frontend): improved ServicesList component * chore: added .env.local.example file * chore: improved typing in RoomPOST route * chore(types): changed any to actual type --------- Co-authored-by: MAXOUXAX <[email protected]>
- Loading branch information
1 parent
479b7be
commit 492b585
Showing
16 changed files
with
1,683 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
SUPABASE_URL= | ||
SUPABASE_ANON_KEY= | ||
SERVICE_ROLE= | ||
SERVICE_ROLE= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { FastifyRequest } from "fastify"; | ||
import { supabase } from "./server"; | ||
import { createClient } from "@supabase/supabase-js"; | ||
|
||
export async function getUserFromRequest(req: any) { | ||
if (!process.env.SUPABASE_URL) { | ||
throw new Error("Missing SUPABASE_URL environment variable"); | ||
} | ||
|
||
const accesToken = req.cookies.accessToken; | ||
const supabaseUrl = process.env.SUPABASE_URL; | ||
const supabase = createClient(supabaseUrl, accesToken); | ||
|
||
return await supabase.auth.getUser(); | ||
} | ||
|
||
export async function createRoom( | ||
name: string, | ||
code: string, | ||
voteSkipping: boolean, | ||
voteSkippingNeeded: number, | ||
maxMusicPerUser: number, | ||
maxMusicPerUserDuration: number, | ||
serviceId: string, | ||
req: FastifyRequest, | ||
) { | ||
let configurationId: string | null = null; | ||
let hostUserProfileId: string | null = null; | ||
|
||
getUserFromRequest(req).then((user) => { | ||
if (user) { | ||
if (user.data.user) hostUserProfileId = user.data.user.id; | ||
else return { code: 500, message: "User not found" }; | ||
} else { | ||
return { code: 500, message: "User not found" }; | ||
} | ||
}); | ||
|
||
// TODO : review | ||
/* | ||
const userProfileRes = await supabase | ||
.from("user_profile") | ||
.select("user_profile_id"); | ||
if (userProfileRes.error) { | ||
return { code: code, message: userProfileRes.error }; | ||
} else { | ||
hostUserProfileId = userProfileRes.data[0].user_profile_id; | ||
console.log("Host user profile id retrieved"); | ||
}*/ | ||
|
||
const roomConfigRes = await supabase | ||
.from("active_room_configurations") | ||
.insert([ | ||
{ | ||
vote_skipping: voteSkipping, | ||
vote_skipping_needed_percentage: voteSkippingNeeded, | ||
max_music_count_in_queue_per_participant: maxMusicPerUser, | ||
max_music_duration: maxMusicPerUserDuration, | ||
}, | ||
]) | ||
.select("id"); | ||
|
||
if (roomConfigRes.error) { | ||
return { code: roomConfigRes.status, message: roomConfigRes.error }; | ||
} else { | ||
configurationId = roomConfigRes.data[0].id; | ||
console.log("Room configurations created"); | ||
} | ||
|
||
const roomRes = await supabase | ||
.from("active_rooms") | ||
.insert([ | ||
{ | ||
name: name, | ||
code: code, | ||
configuration_id: configurationId, | ||
host_user_profile_id: hostUserProfileId, | ||
service_id: serviceId, | ||
}, | ||
]) | ||
.select("id"); | ||
|
||
if (roomRes.error) { | ||
return { code: roomRes.status, message: roomRes.error }; | ||
} else { | ||
return { code: roomRes.status, message: "Room created" }; | ||
} | ||
} | ||
|
||
export function endRoom(roomId: string) { | ||
let createdAt: Date | null = null; | ||
let configurationId: string | null = null; | ||
let hostUserProfileId: string | null = null; | ||
|
||
supabase | ||
.from("active_rooms") | ||
.delete() | ||
.eq("id", roomId) | ||
.select("*") | ||
.then((res) => { | ||
if (res.error) { | ||
return res.error; | ||
} else { | ||
createdAt = res.data[0].created_at; | ||
configurationId = res.data[0].configuration_id; | ||
hostUserProfileId = res.data[0].host_user_profile_id; | ||
console.log("Room ended"); | ||
} | ||
}); | ||
|
||
supabase | ||
.from("rooms") | ||
.insert([ | ||
{ | ||
created_at: createdAt, | ||
configuration_id: configurationId, | ||
host_user_profile_id: hostUserProfileId, | ||
}, | ||
]) | ||
.then((res) => { | ||
if (res.error) { | ||
return res.error; | ||
} else { | ||
console.log("Room added to rooms"); | ||
} | ||
}); | ||
} |
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,53 @@ | ||
import { FastifyReply, FastifyRequest } from "fastify"; | ||
import { createRoom } from "../room"; | ||
import * as repl from "repl"; | ||
|
||
interface BodyParams { | ||
name: string; | ||
code: string; | ||
service: string; | ||
voteSkipping: boolean; | ||
voteSkippingNeeded: number; | ||
maxMusicPerUser: number; | ||
maxMusicPerUserDuration: number; | ||
} | ||
|
||
function extractFromRequest(req: FastifyRequest): BodyParams { | ||
const bodyParams = req.body as BodyParams; | ||
const name = bodyParams.name; | ||
const code = bodyParams.code; | ||
const voteSkipping = bodyParams.voteSkipping; | ||
const voteSkippingNeeded = bodyParams.voteSkippingNeeded; | ||
const maxMusicPerUser = bodyParams.maxMusicPerUser; | ||
const maxMusicPerUserDuration = bodyParams.maxMusicPerUserDuration; | ||
const serviceId = bodyParams.service; | ||
return { | ||
name, | ||
code, | ||
voteSkipping, | ||
voteSkippingNeeded, | ||
maxMusicPerUser, | ||
maxMusicPerUserDuration, | ||
service: serviceId, | ||
}; | ||
} | ||
|
||
export default async function RoomPOST( | ||
req: FastifyRequest, | ||
reply: FastifyReply | ||
) { | ||
const roomOptions = extractFromRequest(req); | ||
|
||
const creationResult = await createRoom( | ||
roomOptions.name, | ||
roomOptions.code, | ||
roomOptions.voteSkipping, | ||
roomOptions.voteSkippingNeeded, | ||
roomOptions.maxMusicPerUser, | ||
roomOptions.maxMusicPerUserDuration, | ||
roomOptions.service, | ||
req | ||
); | ||
|
||
reply.send(creationResult); | ||
} |
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,18 @@ | ||
import { FastifyReply, FastifyRequest } from "fastify"; | ||
import { supabase } from "../server"; | ||
|
||
export default function StreamingServicesGET( | ||
req: FastifyRequest, | ||
reply: FastifyReply | ||
) { | ||
supabase | ||
.from("streaming_services") | ||
.select("*") | ||
.then((res) => { | ||
if (res.error) { | ||
reply.code(500).send({ error: res.error }); | ||
} else { | ||
reply.send(res.data); | ||
} | ||
}); | ||
} |
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,5 @@ | ||
import { Slot } from "expo-router"; | ||
|
||
export default function RoomsTabLayout() { | ||
return <Slot />; | ||
} |
Oops, something went wrong.