Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions app/features/profile/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,6 @@ import createAction from 'app/utils/createAction';

import { HandleSchema, FollowsActionSchema } from './schema';

export const addTodaySongAction = createAction(async ({ request, db, params }) => {
await requireUserOwnership(request, { userId: params.userId });
const formData = await request.formData();

const userId = Number(params.userId);
if (isNaN(userId)) {
return new Response(JSON.stringify('잘못된 사용자입니다.'), { status: 400 });
}

const title = (formData.get('title') as string | null)?.trim() ?? '';
const artist = (formData.get('artist') as string | null)?.trim() ?? '';
const album = (formData.get('album') as string | null)?.trim() || null;
const thumbnailUrl = (formData.get('thumbnailUrl') as string | null)?.trim() || null;
const spotifyId = (formData.get('spotifyId') as string | null)?.trim() || null;

if (!title || !artist) {
return new Response('제목과 아티스트는 필수입니다.', { status: 400 });
}

const existingSong =
(spotifyId ? await db.song.findFirst({ where: { spotifyId } }) : null) ??
(await db.song.findFirst({ where: { title, artist } }));

const song = existingSong
? await db.song.update({
where: { id: existingSong.id },
data: { album, thumbnailUrl, spotifyId },
})
: await db.song.create({
data: { title, artist, album, thumbnailUrl, spotifyId },
});

await db.user.update({
where: { id: userId },
data: { todayRecommendedSongId: song.id },
});

return redirect('../show');
});

export const editHandleAction = createAction(async ({ request, db, params }) => {
await requireUserOwnership(request, { userId: params.userId });

Expand Down
33 changes: 0 additions & 33 deletions app/features/profile/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,6 @@ export const profileRedirectLoader = createLoader(async ({ request }) => {
return redirect(`/profile/${user.id}/feed`);
});

export const addTodaySongLoader = createLoader(async ({ db, params, request }) => {
await requireUserOwnership(request, { userId: params.userId });

const userId = Number(params.userId);
if (isNaN(userId)) {
throw new Response('잘못된 사용자입니다.', { status: 400 });
}

const user = await db.user.findUnique({
where: { id: userId },
select: {
todayRecommendedSong: {
select: {
id: true,
title: true,
artist: true,
album: true,
thumbnailUrl: true,
spotifyId: true,
},
},
},
});

if (!user) {
throw new Response('유저가 존재하지 않습니다.', { status: 404 });
}

const songs = searchSongInputLoader({ request });

return { initialSong: user.todayRecommendedSong, songs };
});

export const editHandleLoader = createLoader(async ({ request, params }) => {
await requireUserOwnership(request, { userId: params.userId });

Expand Down
48 changes: 0 additions & 48 deletions app/features/profile/pages/addTodaySong.module.scss

This file was deleted.

60 changes: 0 additions & 60 deletions app/features/profile/pages/addTodaySong.tsx

This file was deleted.

74 changes: 74 additions & 0 deletions app/features/search/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { redirect } from '@remix-run/node';

import { getCurrentUser } from 'app/external/auth/jwt.server';
import createAction from 'app/utils/createAction';

export const searchAction = createAction(async ({ request, db }) => {
const formData = await request.formData();
const actionType = String(formData.get('_action') ?? '');

const currentUser = await getCurrentUser(request);
if (!currentUser) {
return redirect('/login/error');
}
const userId = currentUser.id;
if (Number.isNaN(userId)) {
return new Response('잘못된 사용자입니다.', { status: 400 });
}

const songId = formData.get('songId');
const title = (formData.get('title') as string | null)?.trim() ?? '';
const artist = (formData.get('artist') as string | null)?.trim() ?? '';
const album = (formData.get('album') as string | null)?.trim() || null;
const thumbnailUrl = (formData.get('thumbnailUrl') as string | null)?.trim() || null;
const spotifyId = (formData.get('spotifyId') as string | null)?.trim() || null;

const maybeSongOrResponse = await (async () => {
if (songId) {
const s = await db.song.findUnique({ where: { id: Number(songId) } });
if (!s) return new Response('노래를 찾을 수 없습니다.', { status: 404 });
return s;
}

if (!title || !artist) {
return new Response('제목과 아티스트는 필수입니다.', { status: 400 });
}

const existingSong =
(spotifyId ? await db.song.findFirst({ where: { spotifyId } }) : null) ??
(await db.song.findFirst({ where: { title, artist } }));

if (existingSong) {
const updated = await db.song.update({
where: { id: existingSong.id },
data: { album, thumbnailUrl, spotifyId },
});
return updated;
}

const created = await db.song.create({
data: { title, artist, album, thumbnailUrl, spotifyId },
});
return created;
})();

if (maybeSongOrResponse instanceof Response) {
return maybeSongOrResponse;
}

const song = maybeSongOrResponse;

if (actionType === 'addToday') {
await db.user.update({
where: { id: userId },
data: { todayRecommendedSongId: song.id },
});
return redirect(`/profile/${userId}/show`);
}

if (actionType === 'createMemo') {
return redirect(`/music/${song.id}/user/${userId}/create`);
}

return new Response('unknown action', { status: 400 });
});
73 changes: 0 additions & 73 deletions app/features/search/components/SearchSongInput.tsx

This file was deleted.

Loading