Skip to content

Commit 3ce8dfa

Browse files
committed
refactor(validation): drop types.ts barrels; add uploadMeta and use DTO names
Remove common/types.ts and song/types.ts (PageQueryDTOType and *DtoType aliases). Add song/uploadMeta.ts for VisibilityType, CategoryType, LicenseType, TimespanType. Export SongsFolder from SongPage.dto.ts next to SongPageDto. Point SongPreview/SongView/UploadSongDto at uploadMeta; update package index exports. Rename frontend imports from *DtoType to the real DTO types (via @nbw/database).
1 parent b691a99 commit 3ce8dfa

26 files changed

Lines changed: 80 additions & 110 deletions

File tree

apps/frontend/src/app/(content)/song/[id]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Metadata } from 'next';
22
import { cookies } from 'next/headers';
33

4-
import type { SongViewDtoType } from '@nbw/database';
4+
import type { SongViewDto } from '@nbw/database';
55
import axios from '@web/lib/axios';
66
import { SongPage } from '@web/modules/song/components/SongPage';
77

@@ -28,7 +28,7 @@ export async function generateMetadata({
2828
}
2929

3030
try {
31-
const response = await axios.get<SongViewDtoType>(`/song/${id}`, {
31+
const response = await axios.get<SongViewDto>(`/song/${id}`, {
3232
headers,
3333
});
3434

apps/frontend/src/modules/browse/components/SongCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
55
import Link from 'next/link';
66
import Skeleton from 'react-loading-skeleton';
77

8-
import type { SongPreviewDtoType } from '@nbw/database';
8+
import type { SongPreviewDto } from '@nbw/database';
99
import { formatDuration, formatTimeAgo } from '@web/modules/shared/util/format';
1010

1111
import SongThumbnail from '../../shared/components/layout/SongThumbnail';
1212

13-
const SongDataDisplay = ({ song }: { song: SongPreviewDtoType | null }) => {
13+
const SongDataDisplay = ({ song }: { song: SongPreviewDto | null }) => {
1414
return (
1515
<div className='flex flex-col gap-2 pb-2 h-full'>
1616
{/* Song image */}
@@ -66,7 +66,7 @@ const SongDataDisplay = ({ song }: { song: SongPreviewDtoType | null }) => {
6666
);
6767
};
6868

69-
const SongCard = ({ song }: { song: SongPreviewDtoType | null }) => {
69+
const SongCard = ({ song }: { song: SongPreviewDto | null }) => {
7070
return !song ? (
7171
<SongDataDisplay song={song} />
7272
) : (

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

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

3-
import type { FeaturedSongsDtoType, SongPreviewDtoType } from '@nbw/database';
3+
import type { FeaturedSongsDto, SongPreviewDto } from '@nbw/database';
44

55
import {
66
FeaturedSongsProvider,
@@ -30,8 +30,8 @@ export function HomePageProvider({
3030
initialFeaturedSongs,
3131
}: {
3232
children: React.ReactNode;
33-
initialRecentSongs: SongPreviewDtoType[];
34-
initialFeaturedSongs: FeaturedSongsDtoType;
33+
initialRecentSongs: SongPreviewDto[];
34+
initialFeaturedSongs: FeaturedSongsDto;
3535
}) {
3636
return (
3737
<RecentSongsProvider initialRecentSongs={initialRecentSongs}>

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import { useEffect } from 'react';
44
import { create } from 'zustand';
55

6-
import type { PageDto, SongPreviewDtoType } from '@nbw/database';
6+
import type { PageDto, SongPreviewDto } from '@nbw/database';
77
import axiosInstance from '@web/lib/axios';
88

99
interface RecentSongsState {
10-
recentSongs: (SongPreviewDtoType | null | undefined)[];
10+
recentSongs: (SongPreviewDto | null | undefined)[];
1111
recentError: string;
1212
isLoading: boolean;
1313
hasMore: boolean;
@@ -17,7 +17,7 @@ interface RecentSongsState {
1717
}
1818

1919
interface RecentSongsActions {
20-
initialize: (initialRecentSongs: SongPreviewDtoType[]) => void;
20+
initialize: (initialRecentSongs: SongPreviewDto[]) => void;
2121
setSelectedCategory: (category: string) => void;
2222
increasePageRecent: () => Promise<void>;
2323
fetchRecentSongs: () => Promise<void>;
@@ -31,9 +31,9 @@ const pageSize = 12;
3131
const fetchCount = pageSize - adCount;
3232

3333
function injectAdSlots(
34-
songs: SongPreviewDtoType[],
35-
): Array<SongPreviewDtoType | undefined> {
36-
const songsWithAds: Array<SongPreviewDtoType | undefined> = [...songs];
34+
songs: SongPreviewDto[],
35+
): Array<SongPreviewDto | undefined> {
36+
const songsWithAds: Array<SongPreviewDto | undefined> = [...songs];
3737

3838
for (let i = 0; i < adCount; i++) {
3939
const adPosition = Math.floor(Math.random() * (songsWithAds.length + 1));
@@ -90,7 +90,7 @@ export const useRecentSongsStore = create<RecentSongsStore>((set, get) => ({
9090
params.category = selectedCategory;
9191
}
9292

93-
const response = await axiosInstance.get<PageDto<SongPreviewDtoType>>(
93+
const response = await axiosInstance.get<PageDto<SongPreviewDto>>(
9494
'/song',
9595
{ params },
9696
);
@@ -177,7 +177,7 @@ export const useRecentSongsProvider = () => {
177177
// Provider component for initialization (now just a wrapper)
178178
type RecentSongsProviderProps = {
179179
children: React.ReactNode;
180-
initialRecentSongs: SongPreviewDtoType[];
180+
initialRecentSongs: SongPreviewDto[];
181181
};
182182

183183
export function RecentSongsProvider({

apps/frontend/src/modules/my-songs/components/MySongsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MY_SONGS } from '@nbw/config';
2-
import type { SongPageDtoType, SongsFolder } from '@nbw/database';
2+
import type { SongPageDto, SongsFolder } from '@nbw/database';
33
import axiosInstance from '@web/lib/axios';
44

55
import { getTokenServer } from '../../auth/features/auth.utils';
@@ -11,7 +11,7 @@ async function fetchSongsPage(
1111
page: number,
1212
pageSize: number,
1313
token: string,
14-
): Promise<SongPageDtoType> {
14+
): Promise<SongPageDto> {
1515
const response = await axiosInstance
1616
.get('/my-songs', {
1717
headers: {

apps/frontend/src/modules/my-songs/components/client/MySongsTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Link from 'next/link';
99
import Skeleton from 'react-loading-skeleton';
1010

1111
import { MY_SONGS } from '@nbw/config';
12-
import type { SongPageDtoType, SongPreviewDtoType } from '@nbw/database';
12+
import type { SongPageDto, SongPreviewDto } from '@nbw/database';
1313
import { ErrorBox } from '@web/modules/shared/components/client/ErrorBox';
1414

1515
import {
@@ -45,14 +45,14 @@ const SongRows = ({
4545
page,
4646
pageSize,
4747
}: {
48-
page: SongPageDtoType | null;
48+
page: SongPageDto | null;
4949
pageSize: number;
5050
}) => {
5151
const maxPage = MY_SONGS.PAGE_SIZE;
5252

5353
const content = !page
5454
? Array(pageSize).fill(null)
55-
: (page.content as SongPreviewDtoType[]);
55+
: (page.content as SongPreviewDto[]);
5656

5757
return (
5858
<>

apps/frontend/src/modules/my-songs/components/client/SongRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
88
import Link from 'next/link';
99
import Skeleton from 'react-loading-skeleton';
1010

11-
import type { SongPreviewDtoType } from '@nbw/database';
11+
import type { SongPreviewDto } from '@nbw/database';
1212
import SongThumbnail from '@web/modules/shared/components/layout/SongThumbnail';
1313
import { formatDuration } from '@web/modules/shared/util/format';
1414

@@ -20,7 +20,7 @@ import {
2020

2121
import { useMySongsProvider } from './context/MySongs.context';
2222

23-
export const SongRow = ({ song }: { song?: SongPreviewDtoType | null }) => {
23+
export const SongRow = ({ song }: { song?: SongPreviewDto | null }) => {
2424
const { setIsDeleteDialogOpen, setSongToDelete } = useMySongsProvider();
2525

2626
const onDeleteClicked = () => {

apps/frontend/src/modules/my-songs/components/client/context/MySongs.context.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,21 @@ import { toast } from 'react-hot-toast';
55
import { create } from 'zustand';
66

77
import { MY_SONGS } from '@nbw/config';
8-
import type {
9-
SongPageDtoType,
10-
SongPreviewDtoType,
11-
SongsFolder,
12-
} from '@nbw/database';
8+
import type { SongPageDto, SongPreviewDto, SongsFolder } from '@nbw/database';
139
import axiosInstance from '@web/lib/axios';
1410
import { getTokenLocal } from '@web/lib/axios/token.utils';
1511

1612
interface MySongsState {
1713
loadedSongs: SongsFolder;
18-
page: SongPageDtoType | null;
14+
page: SongPageDto | null;
1915
totalSongs: number;
2016
totalPages: number;
2117
currentPage: number;
2218
pageSize: number;
2319
isLoading: boolean;
2420
error: string | null;
2521
isDeleteDialogOpen: boolean;
26-
songToDelete: SongPreviewDtoType | null;
22+
songToDelete: SongPreviewDto | null;
2723
}
2824

2925
interface MySongsActions {
@@ -39,7 +35,7 @@ interface MySongsActions {
3935
nextpage: () => void;
4036
prevpage: () => void;
4137
setIsDeleteDialogOpen: (isOpen: boolean) => void;
42-
setSongToDelete: (song: SongPreviewDtoType) => void;
38+
setSongToDelete: (song: SongPreviewDto) => void;
4339
deleteSong: () => Promise<void>;
4440
}
4541

@@ -95,7 +91,7 @@ export const useMySongsStore = create<MySongsStore>((set, get) => ({
9591
},
9692
});
9793

98-
const data = response.data as SongPageDtoType;
94+
const data = response.data as SongPageDto;
9995

10096
// TODO: total, page and pageSize are stored in every page, when it should be stored in the folder (what matters is 'content')
10197
set((state) => ({

apps/frontend/src/modules/song-edit/components/client/EditSongPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UploadSongDtoType } from '@nbw/database';
1+
import type { UploadSongDto } from '@nbw/database';
22
import axiosInstance from '@web/lib/axios';
33
import {
44
getTokenServer,
@@ -13,7 +13,7 @@ import {
1313

1414
import { SongEditForm } from './SongEditForm';
1515

16-
async function fetchSong({ id }: { id: string }): Promise<UploadSongDtoType> {
16+
async function fetchSong({ id }: { id: string }): Promise<UploadSongDto> {
1717
// get token from cookies
1818
const token = await getTokenServer();
1919
// if token is not null, redirect to home page
@@ -31,7 +31,7 @@ async function fetchSong({ id }: { id: string }): Promise<UploadSongDtoType> {
3131

3232
const data = await response.data;
3333

34-
return data as UploadSongDtoType;
34+
return data as UploadSongDto;
3535
} catch (error: unknown) {
3636
throw new Error('Failed to fetch song data');
3737
}

apps/frontend/src/modules/song-edit/components/client/SongEditForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import { useEffect } from 'react';
44

5-
import type { UploadSongDtoType } from '@nbw/database';
5+
import type { UploadSongDto } from '@nbw/database';
66
import { useSongProvider } from '@web/modules/song/components/client/context/Song.context';
77
import { SongForm } from '@web/modules/song/components/client/SongForm';
88

99
import { useEditSongProviderType } from './context/EditSong.context';
1010

1111
type SongEditFormProps = {
12-
songData: UploadSongDtoType;
12+
songData: UploadSongDto;
1313
songId: string;
1414
username: string;
1515
};

0 commit comments

Comments
 (0)