diff --git a/client/src/api/endpoints/resources.ts b/client/src/api/endpoints/resources.ts index e748207..585bd15 100644 --- a/client/src/api/endpoints/resources.ts +++ b/client/src/api/endpoints/resources.ts @@ -22,6 +22,7 @@ import { Tag, TagBaseWithRefs, TagWithRefs, + Track, TrackBaseWithRefs, TrackWithDetails, TrackWithRefs @@ -47,7 +48,7 @@ import { // Get track details (GET). export const GetTrackEndpoint = '/track/:id'; -export type GetTrackResponse = TrackWithDetails; +export type GetTrackResponse = Track; // Get artist details (GET). export const GetArtistEndpoint = '/artist/:id'; diff --git a/client/src/api/types/resources.ts b/client/src/api/types/resources.ts index bb37ac6..ff5d023 100644 --- a/client/src/api/types/resources.ts +++ b/client/src/api/types/resources.ts @@ -35,6 +35,8 @@ export interface TrackWithRefs extends TrackBaseWithRefs { export interface Track extends TrackBase { name: string, album: AlbumWithId | null, + artists: ArtistWithId[], + tags: TagWithId[], } export interface TrackWithRefsWithId extends TrackWithRefs { id: number, @@ -131,6 +133,7 @@ export interface AlbumWithRefs extends AlbumBaseWithRefs { } export interface Album extends AlbumBase { name: string, + artists: ArtistWithId[], } export interface AlbumWithRefsWithId extends AlbumWithRefs { id: number, @@ -170,7 +173,7 @@ export interface TagWithRefs extends TagBaseWithRefs { name: string, parentId: number | null, } -export interface Tag extends TagBase { +export interface Tag extends TagBaseWithDetails { name: string, } export interface TagWithRefsWithId extends TagWithRefs { diff --git a/client/src/components/windows/track/TrackWindow.tsx b/client/src/components/windows/track/TrackWindow.tsx index e911b80..ddb330b 100644 --- a/client/src/components/windows/track/TrackWindow.tsx +++ b/client/src/components/windows/track/TrackWindow.tsx @@ -14,12 +14,11 @@ import { useParams } from 'react-router'; import EditTrackDialog from './EditTrackDialog'; import EditIcon from '@material-ui/icons/Edit'; import { modifyTrack } from '../../../lib/saveChanges'; - -export type TrackMetadata = serverApi.TrackWithDetails; +import { getTrack } from '../../../lib/backend/tracks'; export interface TrackWindowState extends WindowState { id: number, - metadata: TrackMetadata | null, + metadata: serverApi.Track | null, } export enum TrackWindowStateActions { @@ -38,17 +37,6 @@ export function TrackWindowReducer(state: TrackWindowState, action: any) { } } -export async function getTrackMetadata(id: number) { - let response: any = await queryTracks( - { - a: QueryLeafBy.TrackId, - b: id, - leafOp: QueryLeafOp.Equals, - }, 0, 1, serverApi.QueryResponseType.Details - ); - return response[0]; -} - export default function TrackWindow(props: {}) { const { id } = useParams<{ id: string }>(); const [state, dispatch] = useReducer(TrackWindowReducer, { @@ -69,8 +57,8 @@ export function TrackWindowControlled(props: { useEffect(() => { if (metadata === null) { - getTrackMetadata(trackId) - .then((m: TrackMetadata) => { + getTrack(trackId) + .then((m: serverApi.Track) => { dispatch({ type: TrackWindowStateActions.SetMetadata, value: m diff --git a/server/db/Track.ts b/server/db/Track.ts index 3da46ae..9761e28 100644 --- a/server/db/Track.ts +++ b/server/db/Track.ts @@ -1,5 +1,5 @@ import Knex from "knex"; -import { TrackBaseWithRefs, TrackWithDetails, TrackWithRefs } from "../../client/src/api/api"; +import { Track, TrackBaseWithRefs, TrackWithDetails, TrackWithRefs } from "../../client/src/api/api"; import * as api from '../../client/src/api/api'; import asJson from "../lib/asJson"; import { DBError, DBErrorKind } from "../endpoints/types"; @@ -8,7 +8,7 @@ var _ = require('lodash') // Returns an track with details, or null if not found. export async function getTrack(id: number, userId: number, knex: Knex): - Promise { + Promise { // Start transfers for tracks, tags and artists. // Also request the track itself. const tagsPromise: Promise = diff --git a/server/endpoints/Track.ts b/server/endpoints/Track.ts index a2aa7bb..5e89bf1 100644 --- a/server/endpoints/Track.ts +++ b/server/endpoints/Track.ts @@ -3,6 +3,7 @@ import { EndpointError, EndpointHandler, handleErrorsInEndpoint } from './types' import Knex from 'knex'; import asJson from '../lib/asJson'; import { createTrack, deleteTrack, getTrack, modifyTrack } from '../db/Track'; +import { Track } from '../../client/src/api/api'; export const PostTrack: EndpointHandler = async (req: any, res: any, knex: Knex) => { if (!api.checkPostTrackRequest(req.body)) { @@ -34,7 +35,7 @@ export const GetTrack: EndpointHandler = async (req: any, res: any, knex: Knex) let id = parseInt(req.params.id); try { - let track = await getTrack(id, userId, knex); + let track: Track = await getTrack(id, userId, knex); await res.status(200).send(track); } catch (e) { handleErrorsInEndpoint(e)