Skip to content
Snippets Groups Projects
Verified Commit 85dc5efd authored by Miniontoby's avatar Miniontoby :writing_hand_tone1:
Browse files

Added URL field to song

parent d6549b5d
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,7 @@ model Song {
name String @unique
artist String?
lyrics String?
url String?
playlists Playlist[]
sheets MusicSheet[]
}
......
......@@ -68,7 +68,13 @@
"label": "Enter Password to change Password"
},
"role": {
"label": "Select Role"
"label": "Select Role",
"options": {
"Owner": "Owner",
"Admin": "Admin",
"Leader": "Leader",
"User": "User"
}
}
},
"team": {
......@@ -104,6 +110,10 @@
"placeholder": "Enter Song Artist",
"label": "Song Artist"
},
"url": {
"placeholder": "Enter Song URL",
"label": "Song URL"
},
"lyrics": {
"placeholder": "Enter Song Lyrics",
"label": "Song Lyrics"
......
......@@ -11,6 +11,7 @@ export async function getAll() {
id: true,
name: true,
artist: true,
url: true,
lyrics: true,
sheets: true,
}
......@@ -31,6 +32,7 @@ export async function getAllByTeam(teamId: number) {
id: true,
name: true,
artist: true,
url: true,
lyrics: true,
sheets: true,
}
......@@ -52,6 +54,7 @@ export async function findById(id: number) {
id: true,
name: true,
artist: true,
url: true,
lyrics: true,
sheets: true,
}
......@@ -73,6 +76,7 @@ export async function findByName(name: string) {
id: true,
name: true,
artist: true,
url: true,
lyrics: true,
sheets: true,
}
......@@ -84,14 +88,16 @@ export async function findByName(name: string) {
*
* @param name The name/title of the song (Required)
* @param artist The artist of the song (Optional)
* @param url A URL to the song (Optional)
* @param lyrics The lyrics of the song (Optional)
* @returns { object } created song
*/
export async function create(name: string, artist: string|undefined = undefined, lyrics: string|undefined = undefined) {
export async function create(name: string, artist: string|undefined = undefined, url: string|undefined = undefined, lyrics: string|undefined = undefined) {
return await db.song.create({
data: {
name,
artist,
url,
lyrics,
}
})
......@@ -103,10 +109,11 @@ export async function create(name: string, artist: string|undefined = undefined,
* @param id
* @param name The name/title of the song (Required)
* @param artist The artist of the song (Optional)
* @param url A URL to the song (Optional)
* @param lyrics The lyrics of the song (Optional)
* @returns { object } edited song
*/
export async function edit(id: number, name: string, artist: string|undefined = undefined, lyrics: string|undefined = undefined) {
export async function edit(id: number, name: string, artist: string|undefined = undefined, url: string|undefined = undefined, lyrics: string|undefined = undefined) {
return await db.song.update({
where: {
id,
......@@ -114,6 +121,7 @@ export async function edit(id: number, name: string, artist: string|undefined =
data: {
name,
artist,
url,
lyrics,
}
})
......
......@@ -21,17 +21,18 @@ export const actions = {
const formData = parseAndCheckFormData(data, [
{ name: 'name', required: true, type: 'string' },
{ name: 'artist', required: false, type: 'string' },
{ name: 'url', required: false, type: 'string' },
{ name: 'lyrics', required: true, type: 'string' },
]);
if (!formData.success) return formData.data;
const { name, artist, lyrics } = formData.data;
const { name, artist, url, lyrics } = formData.data;
const song = await Song.findById(Number(params.id));
if (song.name !== name && await Song.findByName(name))
return fail(400, { unique: true });
const songNew = await Song.edit(song.id, name, artist ?? '', lyrics);
const songNew = await Song.edit(song.id, name, artist, url, lyrics);
return { success: true, song: songNew };
}
}
......@@ -20,7 +20,8 @@
/** @type {string} */ $: name = form?.name ?? song?.name;
/** @type {string} */ $: artist = form?.artist ?? song?.artist ?? '';
/** @type {string} */ $: lyrics = form?.lyrics ?? song?.lyrics;
/** @type {string} */ $: url = form?.url ?? song?.url ?? '';
/** @type {string} */ $: lyrics = form?.lyrics ?? song?.lyrics ?? '';
let working = false;
......@@ -62,7 +63,7 @@
<form class="space-y-4 md:space-y-6" action="?/edit" method="POST" use:enhance={() => { if (!working) { working = true; return async ({ result }) => { working = false; await applyAction(result); if (result.type === 'redirect') { goto(result.location); } }; } }}>
<TextField
id="name"
id="name"
type="text"
placeholder={$_('fields.song.name.placeholder')}
label={true}
......@@ -72,7 +73,7 @@
disabled={working}
/>
<TextField
id="artist"
id="artist"
type="text"
placeholder={$_('fields.song.artist.placeholder')}
label={true}
......@@ -81,7 +82,16 @@
disabled={working}
/>
<TextField
id="lyrics"
id="url"
type="text"
placeholder={$_('fields.song.url.placeholder')}
label={true}
labelText={$_('fields.song.url.label')}
bind:value={url}
disabled={working}
/>
<TextField
id="lyrics"
type="textarea"
placeholder={$_('fields.song.lyrics.placeholder')}
label={true}
......
......@@ -8,15 +8,17 @@ export const actions = {
const data = await request.formData();
const formData = parseAndCheckFormData(data, [
{ name: 'name', required: true, type: 'string' },
{ name: 'artist', required: false, type: 'string' },
{ name: 'url', required: false, type: 'string' },
{ name: 'lyrics', required: false, type: 'string' },
]);
if (!formData.success) return formData.data;
const { name, lyrics } = formData.data;
const { name, artist, url, lyrics } = formData.data;
if (await Song.findByName(name))
return fail(400, { unique: true });
const song = await Song.create(name, lyrics);
const song = await Song.create(name, artist, url, lyrics);
return { success: true, song };
}
}
......@@ -16,6 +16,7 @@
/** @type {string} */ $: name = form?.name ?? '';
/** @type {string} */ $: artist = form?.artist ?? '';
/** @type {string} */ $: url = form?.url ?? '';
/** @type {string} */ $: lyrics = form?.lyrics ?? '';
let working = false;
......@@ -76,6 +77,15 @@
bind:value={artist}
disabled={working}
/>
<TextField
id="url"
type="text"
placeholder={$_('fields.song.url.placeholder')}
label={true}
labelText={$_('fields.song.url.label')}
bind:value={url}
disabled={working}
/>
<TextField
id="lyrics"
type="textarea"
......
......@@ -26,6 +26,9 @@
{#if song.artist}
<p><strong>{$_('fields.song.artist.label')}:</strong> {song.artist}</p>
{/if}
{#if song.url}
<p><strong>{$_('fields.song.url.label')}:</strong> <a href={song.url}>{song.url}</a></p>
{/if}
<br><hr /><br>
<p><a href={resolveRoute('/musicsheets/[song]', { song: String(song.id) })}>Go to MusicSheets</a></p>
<br><hr /><br>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment