3c892d02ed
Jenkins Production Deployment
Reviewed-on: #13 Co-authored-by: Patrick Müller <mail@pmueller.me> Co-committed-by: Patrick Müller <mail@pmueller.me>
102 lines
3.1 KiB
TypeScript
102 lines
3.1 KiB
TypeScript
/**
|
|
* Required External Modules and Interfaces
|
|
*/
|
|
import express, {Request, Response} from 'express';
|
|
import * as SongsAdminService from './songs.admin.service.js';
|
|
import {sendServerError} from '../feedback.errors.js';
|
|
|
|
/**
|
|
* Router Definition
|
|
*/
|
|
export const songsAdminRouter = express.Router();
|
|
|
|
/**
|
|
* @swagger
|
|
* /feedback/admin/songs/{songId}:
|
|
* put:
|
|
* summary: Edit a song's title/composer
|
|
* tags: [feedback-admin]
|
|
* security:
|
|
* - AdminSessionCookie: []
|
|
* parameters:
|
|
* - in: path
|
|
* name: songId
|
|
* required: true
|
|
* schema:
|
|
* type: integer
|
|
* requestBody:
|
|
* required: true
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* required: [title]
|
|
* properties:
|
|
* title:
|
|
* type: string
|
|
* composer:
|
|
* type: string
|
|
* responses:
|
|
* 200:
|
|
* description: Updated
|
|
* 400:
|
|
* description: Missing title
|
|
* 404:
|
|
* description: Unknown song
|
|
* 401:
|
|
* description: Unauthorized
|
|
* 403:
|
|
* description: Signed in without the permission for this app, or account disabled
|
|
* delete:
|
|
* summary: Remove a song
|
|
* description: Past answers keep their song_title_snapshot even after the song is removed.
|
|
* tags: [feedback-admin]
|
|
* security:
|
|
* - AdminSessionCookie: []
|
|
* parameters:
|
|
* - in: path
|
|
* name: songId
|
|
* required: true
|
|
* schema:
|
|
* type: integer
|
|
* responses:
|
|
* 204:
|
|
* description: Removed
|
|
* 404:
|
|
* description: Unknown song
|
|
* 401:
|
|
* description: Unauthorized
|
|
* 403:
|
|
* description: Signed in without the permission for this app, or account disabled
|
|
*/
|
|
songsAdminRouter.put('/:songId', async (req: Request, res: Response) => {
|
|
try {
|
|
const {title, composer} = req.body || {};
|
|
if (!title) {
|
|
res.status(400).send({status: 'BAD_REQUEST', message: 'title is required'});
|
|
return;
|
|
}
|
|
const updated = await SongsAdminService.updateSong(Number(req.params.songId), title, composer || null);
|
|
if (!updated) {
|
|
res.status(404).send({status: 'NOT_FOUND'});
|
|
return;
|
|
}
|
|
res.status(200).send({status: 'OK'});
|
|
} catch (e: any) {
|
|
sendServerError(res, e);
|
|
}
|
|
});
|
|
|
|
songsAdminRouter.delete('/:songId', async (req: Request, res: Response) => {
|
|
try {
|
|
const deleted = await SongsAdminService.deleteSong(Number(req.params.songId));
|
|
if (!deleted) {
|
|
res.status(404).send({status: 'NOT_FOUND'});
|
|
return;
|
|
}
|
|
res.status(204).send();
|
|
} catch (e: any) {
|
|
sendServerError(res, e);
|
|
}
|
|
});
|