first commit
This commit is contained in:
commit
7bf0cb4f05
27 files changed
+5490
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getSongbooks, addSongbook } from "@/lib/db/managing";
|
||||
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const songbooks = await getSongbooks();
|
||||
return NextResponse.json(songbooks);
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false, message: error}, { status: 500})
|
||||
}
|
||||
}
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { name, language } = await request.json();
|
||||
|
||||
if (!name ) {
|
||||
return NextResponse.json({ success: false, message: "Fields incomplete (name)"}, { status: 400 })
|
||||
}
|
||||
|
||||
const newBook = await addSongbook(String(name), String(language))
|
||||
|
||||
return NextResponse.json(newBook, { status: 201 })
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { getSongs, addSongToSongbook } from "@/lib/db/managing";
|
||||
|
||||
export async function GET() {
|
||||
const songs = await getSongs();
|
||||
if (songs) {
|
||||
return NextResponse.json(songs);
|
||||
} else {
|
||||
return NextResponse.json({ success: false}, { status: 500})
|
||||
}
|
||||
}
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { title, songbookId, number } = await request.json();
|
||||
|
||||
if (!title || !songbookId || !number) {
|
||||
return NextResponse.json({ success: false, message: "Fields incomplete"}, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await addSongToSongbook(title, Number(songbookId), String(number));
|
||||
if (result.success) {
|
||||
return NextResponse.json({ success: true });
|
||||
} else {
|
||||
return NextResponse.json({ success: false }, { status: 500 });
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getSong } from "@/lib/db/managing";
|
||||
|
||||
let currentSong = {
|
||||
songID: "",
|
||||
songbook: "",
|
||||
number: "",
|
||||
title: ""
|
||||
};
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(currentSong)
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const data = await request.json();
|
||||
const songID = data.songID;
|
||||
const songbookID = data.songbookID;
|
||||
|
||||
if (!songID || !songbookID) {
|
||||
return NextResponse.json({ success: false, error: "Fields incomplete!" }, { status: 400 });
|
||||
}
|
||||
|
||||
const song = await getSong(Number(songbookID), String(songID));
|
||||
|
||||
if (song) {
|
||||
currentSong = {
|
||||
songID: String(songID),
|
||||
songbook: song.songbook_name,
|
||||
number: song.number,
|
||||
title: song.song_title,
|
||||
};
|
||||
} else {
|
||||
currentSong = {
|
||||
songID: "",
|
||||
songbook: "",
|
||||
number: "",
|
||||
title: "",
|
||||
};
|
||||
}
|
||||
console.log(currentSong);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false, error: "Server-Fehler" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user