Skip to content

Commit 3ec650a

Browse files
committed
refactor: update song retrieval endpoints to use query parameters for recent and featured songs
1 parent e99b8da commit 3ec650a

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

apps/frontend/src/app/(content)/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import { HomePageComponent } from '@web/modules/browse/components/HomePageCompon
88
async function fetchRecentSongs() {
99
try {
1010
const response = await axiosInstance.get<SongPreviewDtoType[]>(
11-
'/song-browser/recent',
11+
'/song',
1212
{
1313
params: {
14+
q : 'recent',
1415
page : 1, // TODO: fiz constants
1516
limit: 16, // TODO: change 'limit' parameter to 'skip' and load 12 songs initially, then load 8 more songs on each pagination
1617
sort : 'recent',
@@ -28,7 +29,7 @@ async function fetchRecentSongs() {
2829
async function fetchFeaturedSongs(): Promise<FeaturedSongsDtoType> {
2930
try {
3031
const response = await axiosInstance.get<FeaturedSongsDtoType>(
31-
'/song-browser/featured',
32+
'/song?q=featured',
3233
);
3334

3435
return response.data;

apps/frontend/src/modules/browse/components/client/context/RecentSongs.context.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
'use client';
22

33
import { SongPreviewDtoType } from '@nbw/database';
4-
import {
5-
createContext,
6-
useCallback,
7-
useContext,
8-
useEffect,
9-
useState,
10-
} from 'react';
4+
import { createContext, useCallback, useContext, useEffect, useState,} from 'react';
115

126
import axiosInstance from '@web/lib/axios';
137

@@ -44,7 +38,7 @@ export function RecentSongsProvider({
4438
const [hasMore, setHasMore] = useState(true);
4539
const [categories, setCategories] = useState<Record<string, number>>({});
4640
const [selectedCategory, setSelectedCategory] = useState<string>('');
47-
const [endpoint, setEndpoint] = useState<string>('/song-browser/recent');
41+
const [endpoint, setEndpoint] = useState<string>('/song?q=recent');
4842

4943
const adCount = 1;
5044
const pageSize = 12;
@@ -98,7 +92,7 @@ export function RecentSongsProvider({
9892
const fetchCategories = useCallback(async function () {
9993
try {
10094
const response = await axiosInstance.get<Record<string, number>>(
101-
'/song-browser/categories',
95+
'/songs?q=categories',
10296
);
10397

10498
return response.data;
@@ -120,8 +114,8 @@ export function RecentSongsProvider({
120114

121115
const newEndpoint =
122116
selectedCategory === ''
123-
? '/song-browser/recent'
124-
: `/song-browser/categories/${selectedCategory}`;
117+
? '/song?q=recent'
118+
: `/songs?q=categories&id=${selectedCategory}`;
125119

126120
setEndpoint(newEndpoint);
127121
}, [selectedCategory]);

apps/frontend/src/modules/shared/components/layout/RandomSongButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export const RandomSongButton = () => {
1818

1919
try {
2020
const response = await axios.get<SongPreviewDto[]>(
21-
'/song-browser/random',
21+
'/song',
2222
{
2323
params: {
24+
q : 'random',
2425
count: 1,
2526
},
2627
},

apps/frontend/src/modules/song/components/SongPage.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ import { formatTimeAgo } from '../../shared/util/format';
1212

1313
import { LicenseInfo } from './client/LicenseInfo';
1414
import { SongDetails } from './SongDetails';
15-
import {
16-
DownloadSongButton,
17-
OpenSongInNBSButton,
18-
ShareButton,
19-
UploaderBadge,
20-
VisibilityBadge,
21-
} from './SongPageButtons';
15+
import { DownloadSongButton, OpenSongInNBSButton, ShareButton, UploaderBadge, VisibilityBadge,} from './SongPageButtons';
2216

2317
export async function SongPage({ id }: { id: string }) {
2418
let song: SongViewDtoType;
@@ -47,9 +41,10 @@ export async function SongPage({ id }: { id: string }) {
4741

4842
try {
4943
const response = await axios.get<SongPreviewDtoType[]>(
50-
`/song-browser/random`,
44+
`/song`,
5145
{
5246
params: {
47+
q : 'random',
5348
count : 4,
5449
category: song.category,
5550
},

0 commit comments

Comments
 (0)