Working on Standartisation.... #TODO
This commit is contained in:
1 parent
da4d67ea47
commit
bdc864cf94
8 files changed
+104
-36
No files matched your search
@@ -1,6 +1,11 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongBookById, updateSongBook, deleteSongBook } from "@/lib/db/songbook";
|
import { getSongBookById, updateSongBook, deleteSongBook } from "@/lib/db/songbook";
|
||||||
// import { parseInt } from "@/lib/helper/checkvar";
|
|
||||||
|
interface RouteParams {
|
||||||
|
params: Promise<{
|
||||||
|
songBookId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
@@ -28,12 +33,12 @@ import { getSongBookById, updateSongBook, deleteSongBook } from "@/lib/db/songbo
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
export async function GET(request: Request, { params }) {
|
export async function GET(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
|
|
||||||
|
|
||||||
const res = await getSongBookById(songBookId);
|
const res = await getSongBookById(parseInt(songBookId));
|
||||||
|
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
@@ -81,11 +86,11 @@ export async function GET(request: Request, { params }) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }) {
|
export async function PATCH(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const res = await updateSongBook(songBookId, data);
|
const res = await updateSongBook(parseInt(songBookId), data);
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -126,10 +131,10 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function DELETE(request: Request, { params }) {
|
export async function DELETE(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
const res = await deleteSongBook(songBookId);
|
const res = await deleteSongBook(parseInt(songBookId));
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { addSongToBook, updateSongInBook, removeSongFromBook } from "@/lib/db/songbooksongs";
|
import { addSongToBook, updateSongInBook, removeSongFromBook } from "@/lib/db/songbooksongs";
|
||||||
// import { parseInt } from "@/lib/helper/checkvar";
|
|
||||||
|
interface RouteParams {
|
||||||
|
params: Promise<{
|
||||||
|
songBookId: string;
|
||||||
|
songId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
@@ -45,13 +51,13 @@ import { addSongToBook, updateSongInBook, removeSongFromBook } from "@/lib/db/so
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function POST(request: Request, { params }) {
|
export async function POST(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId, songId } = await params;
|
const { songBookId, songId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
|
|
||||||
|
|
||||||
const res = await addSongToBook(songId, songBookId, data.number);
|
const res = await addSongToBook(parseInt(songId), parseInt(songBookId), String(data.number));
|
||||||
|
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
@@ -114,11 +120,11 @@ export async function POST(request: Request, { params }) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }) {
|
export async function PATCH(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId, songId } = await params;
|
const { songBookId, songId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const res = await updateSongInBook(songId, songBookId, data);
|
const res = await updateSongInBook(parseInt(songId), parseInt(songBookId), data);
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -165,11 +171,11 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function DELETE(request: Request, { params }) {
|
export async function DELETE(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId, songId } = await params;
|
const { songBookId, songId } = await params;
|
||||||
|
|
||||||
const res = await removeSongFromBook(songId, songBookId);
|
const res = await removeSongFromBook(parseInt(songId), parseInt(songBookId));
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongByNumber } from "@/lib/db/songbooksongs";
|
import { getSongByNumber } from "@/lib/db/songbooksongs";
|
||||||
|
|
||||||
|
interface RouteParams {
|
||||||
|
params: Promise<{
|
||||||
|
songBookId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
@@ -26,14 +31,14 @@ import { getSongByNumber } from "@/lib/db/songbooksongs";
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function GET(request: Request, { params }) {
|
export async function GET(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const number = searchParams.get("number") || searchParams.get("n");
|
const number = searchParams.get("number") || searchParams.get("n");
|
||||||
|
|
||||||
if(number){
|
if(number){
|
||||||
const res = await getSongByNumber(songBookId, number);
|
const res = await getSongByNumber(parseInt(songBookId), number);
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongById, updateSong, deleteSong } from "@/lib/db/song";
|
import { getSongById, updateSong, deleteSong } from "@/lib/db/song";
|
||||||
// import { parseInt } from "@/lib/helper/checkvar";
|
|
||||||
|
|
||||||
|
interface RouteParams {
|
||||||
|
params: Promise<{
|
||||||
|
songId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
@@ -27,10 +31,10 @@ import { getSongById, updateSong, deleteSong } from "@/lib/db/song";
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function GET(request: Request, { params }) {
|
export async function GET(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const res = await getSongById(songId);
|
const res = await getSongById(parseInt(songId));
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -77,11 +81,11 @@ export async function GET(request: Request, { params }) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }) {
|
export async function PATCH(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const res = await updateSong(songId, data);
|
const res = await updateSong(parseInt(songId), data);
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -122,10 +126,10 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function DELETE(request: Request, { params }) {
|
export async function DELETE(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const res = await deleteSong(songId);
|
const res = await deleteSong(parseInt(songId));
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// @wikiCategory: Stream
|
// @wikiCategory: Stream
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongById } from "@/lib/db/song";
|
|
||||||
import { getSongBookById } from "@/lib/db/songbook";
|
|
||||||
|
|
||||||
|
|
||||||
let currentSong = {
|
let currentSong = {
|
||||||
@@ -58,8 +56,9 @@ export async function POST(request: Request) {
|
|||||||
number
|
number
|
||||||
};
|
};
|
||||||
|
|
||||||
const payload = JSON.stringify(currentSong);
|
clients.forEach((controller) => {
|
||||||
clients.forEach((send) => send(payload));
|
controller.enqueue(`data: ${JSON.stringify(currentSong)}\n\n`);
|
||||||
|
});
|
||||||
|
|
||||||
return NextResponse.json({ success: true , currentSong }, { status: 200 });
|
return NextResponse.json({ success: true , currentSong }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
export interface Song {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SongBook {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
language?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SongDetailed {
|
||||||
|
song: {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
songBooks?:{songNumber: number; book:SongBook}[]
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type APIResponse<T> =
|
||||||
|
| { success: true; status: number; data: T }
|
||||||
|
| { success: false; status: number; error: string };
|
||||||
|
|
||||||
|
export type GetSongsResponse = APIResponse<Song[]>;
|
||||||
|
export type GetSongDetailedResponse =
|
||||||
|
| {
|
||||||
|
success: true;
|
||||||
|
status: number;
|
||||||
|
song: SongDetailed
|
||||||
|
}
|
||||||
|
| { success: false; status: number; error: string };
|
||||||
|
|
||||||
|
export type GetSongsDelailedResponse =
|
||||||
|
| {
|
||||||
|
success: true;
|
||||||
|
status: number;
|
||||||
|
songs: SongDetailed[]
|
||||||
|
}
|
||||||
|
| { success: false; status: number; error: string };
|
||||||
|
|
||||||
|
export type CreateSongsResponse = APIResponse<Song>;
|
||||||
+15
-8
@@ -1,7 +1,14 @@
|
|||||||
import { prisma } from "@/lib/db/prisma";
|
import { prisma } from "@/lib/db/prisma";
|
||||||
import { parseInt } from "@/lib/helper/checkvar";
|
import { parseInt } from "@/lib/helper/checkvar";
|
||||||
|
import type * as API from "./response";
|
||||||
// For Error checking use this import: import { Prisma } from "@prisma/client";
|
// For Error checking use this import: import { Prisma } from "@prisma/client";
|
||||||
|
|
||||||
|
interface Response {
|
||||||
|
success: boolean;
|
||||||
|
status: number;
|
||||||
|
songs?: [];
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetSongs
|
* GetSongs
|
||||||
@@ -9,7 +16,7 @@ import { parseInt } from "@/lib/helper/checkvar";
|
|||||||
*
|
*
|
||||||
* @returns {"success": boolean, "status": number, "songs": [{"id":number, "title": string},...]}
|
* @returns {"success": boolean, "status": number, "songs": [{"id":number, "title": string},...]}
|
||||||
*/
|
*/
|
||||||
export async function getSongs() {
|
export async function getSongs(): Promise<API.GetSongsResponse> {
|
||||||
try{
|
try{
|
||||||
const songs = await prisma.song.findMany({
|
const songs = await prisma.song.findMany({
|
||||||
select: {
|
select: {
|
||||||
@@ -35,7 +42,7 @@ export async function getSongs() {
|
|||||||
* @param id - ID indicatin the song
|
* @param id - ID indicatin the song
|
||||||
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
||||||
*/
|
*/
|
||||||
export async function getSongById(rawId: number) {
|
export async function getSongById(rawId: number): Promise<API.GetSongDetailedResponse> {
|
||||||
try{
|
try{
|
||||||
const id = parseInt(rawId);
|
const id = parseInt(rawId);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -78,13 +85,13 @@ export async function getSongById(rawId: number) {
|
|||||||
*
|
*
|
||||||
* @param query - The search term for the song title.
|
* @param query - The search term for the song title.
|
||||||
* @param limit - Max number of songs returned for performance (default: 20).
|
* @param limit - Max number of songs returned for performance (default: 20).
|
||||||
* @returns @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
||||||
*/
|
*/
|
||||||
export async function searchSongsByTitle(query: string, limit: number = 20) {
|
export async function searchSongsByTitle(query: string, limit: number = 20): Promise<API.GetSongsDelailedResponse> {
|
||||||
try {
|
try {
|
||||||
const cleanQuery = query.trim();
|
const cleanQuery = query.trim();
|
||||||
if (!cleanQuery) {
|
if (!cleanQuery) {
|
||||||
return { success: true, songBooks: [] };
|
return { success: true, status: 200, songs: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const songs = await prisma.song.findMany({
|
const songs = await prisma.song.findMany({
|
||||||
@@ -124,7 +131,7 @@ export async function searchSongsByTitle(query: string, limit: number = 20) {
|
|||||||
* @param data - object with title
|
* @param data - object with title
|
||||||
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string}}
|
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string}}
|
||||||
*/
|
*/
|
||||||
export async function createSong(data: { title: string }) {
|
export async function createSong(data: { title: string }): Promise<API.CreateSongsResponse> {
|
||||||
try{
|
try{
|
||||||
if(!data.title){
|
if(!data.title){
|
||||||
return { success: false, status: 400, error: "Field 'title' is required" };
|
return { success: false, status: 400, error: "Field 'title' is required" };
|
||||||
@@ -164,7 +171,7 @@ export async function createSong(data: { title: string }) {
|
|||||||
export async function updateSong(
|
export async function updateSong(
|
||||||
rawId: number,
|
rawId: number,
|
||||||
data: { title?: string }
|
data: { title?: string }
|
||||||
) {
|
): Promise<API.CreateSongsResponse> {
|
||||||
try {
|
try {
|
||||||
const id = parseInt(rawId);
|
const id = parseInt(rawId);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -213,7 +220,7 @@ export async function updateSong(
|
|||||||
* @param id - ID indicatin the song
|
* @param id - ID indicatin the song
|
||||||
* @returns {"success": boolean, "status": number, "song": {"id": number, "title": string}}
|
* @returns {"success": boolean, "status": number, "song": {"id": number, "title": string}}
|
||||||
*/
|
*/
|
||||||
export async function deleteSong(rawId: number) {
|
export async function deleteSong(rawId: number): Promise<API.CreateSongsResponse> {
|
||||||
try {
|
try {
|
||||||
const id = parseInt(rawId);
|
const id = parseInt(rawId);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
export function parseInt(rawInteger){
|
export function parseInt(rawInteger: number){
|
||||||
const integer = Number.parseInt(rawInteger);
|
const integer = Number.parseInt(rawInteger);
|
||||||
|
|
||||||
if (Number.isNaN(integer) || !Number.isInteger(integer)) {
|
if (Number.isNaN(integer) || !Number.isInteger(integer)) {
|
||||||
|
|||||||
Reference in new issue
Block a user