Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Raymo111/cs348 into tracklist
Browse files Browse the repository at this point in the history
  • Loading branch information
elainehan3 committed Jul 12, 2023
2 parents 53a95d2 + eaceb03 commit 38096d6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions setup/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ CREATE TABLE IF NOT EXISTS track (
uploaded_on TIMESTAMP,
create_year INT,
audio_length INT,
num_of_times_played INT NOT NULL DEFAULT 0,
FOREIGN KEY (account_uuid) REFERENCES account(uuid)
);

Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions website/app/api/track/[trackId]/stream/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getDB } from "@/util/db";
import { NextResponse } from "next/server";

export async function GET(request: Request, { params }: { params: { trackId: string } }) {
Expand All @@ -8,5 +9,16 @@ export async function GET(request: Request, { params }: { params: { trackId: str
return NextResponse.json({ error: "invalid track id" }, { status: 400 });
}

const conn = await getDB();

try {
await conn.query(`UPDATE track SET num_of_times_played = num_of_times_played + 1 WHERE id = $1`, [trackId]);
} catch (e) {
await conn.end();
return NextResponse.json({ error: "unable to find track and update its played count" }, { status: 404 });
}

await conn.end();

return await fetch(`http://${process.env.FILESTORE_HOST}:${process.env.FILESTORE_PORT}/track/${trackId}`);
}
4 changes: 2 additions & 2 deletions website/app/collection/albums/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useEffect, useState } from "react";
import { apiGetCollectionAlbums, apiGetAlbumsSearch } from "@/components/apiclient";
import { apiGetCollectionAlbums, apiGetCollectionAlbumsSearch } from "@/components/apiclient";
import { useLoginStateContext } from "@/components/loginstateprovider";
import { useRouter } from "next/navigation";
import { APIAlbum } from "@/util/models/album";
Expand Down Expand Up @@ -56,7 +56,7 @@ export default function CollectionAlbumsPage() {
}

// Call API to search for tracks
apiGetAlbumsSearch(event.target.value).then((res) => {
apiGetCollectionAlbumsSearch(loginState.loggedInUserUuid, event.target.value).then((res) => {
setAlbums(res.data as APIAlbum[]);
});
}
Expand Down
4 changes: 2 additions & 2 deletions website/app/collection/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import { useEffect, useState } from "react";
import { apiGetCollectionTracks, apiGetCollectionSearch } from "@/components/apiclient";
import { apiGetCollectionTracks, apiGetCollectionTracksSearch } from "@/components/apiclient";
import { useAppStateContext } from "@/components/appstateprovider";
import { APITrack } from "@/util/models/track";
import {Grid, TextField, Typography, InputAdornment} from "@mui/material";
Expand Down Expand Up @@ -64,7 +64,7 @@ export default function CollectionPage() {
}

// Call API to search for tracks
apiGetCollectionSearch(loginState.loggedInUserUuid, event.target.value).then((res) => {
apiGetCollectionTracksSearch(loginState.loggedInUserUuid, event.target.value).then((res) => {
setTracks(res.data as APITrack[]);
});
}
Expand Down
8 changes: 4 additions & 4 deletions website/components/apiclient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export function apiGetAlbumTracks(albumId: string) {
});
}

export function apiGetAlbumsSearch(query: string) {
export function apiGetCollectionAlbumsSearch(accountUuid: string, query: string) {
return axios({
method: 'get',
url: `/api/album/search?q=${query}`
url: `/api/collection/${accountUuid}/albums/search?q=${query}`
});
}

Expand Down Expand Up @@ -84,10 +84,10 @@ export function apiGetCollectionTracks(accountUuid: string) {
});
}

export function apiGetCollectionSearch(accountUuid: string, query: string) {
export function apiGetCollectionTracksSearch(accountUuid: string, query: string) {
return axios({
method: 'get',
url: `/api/collection/${accountUuid}/search?q=${query}`
url: `/api/collection/${accountUuid}/tracks/search?q=${query}`
});
}

Expand Down

0 comments on commit 38096d6

Please sign in to comment.