Skip to content

Commit

Permalink
Added /waifu route
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrea committed Jan 4, 2024
1 parent 891d39b commit f94df44
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
103 changes: 103 additions & 0 deletions src/routes/v4/images/waifu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Router } from 'express';
import getRandomWaifu from '../../../controllers/v4/images/waifu.js';
import createRateLimiter from '../../../middlewares/rateLimit.js';
import authorize from '../../../middlewares/authorize.js';
import incrementData from '../../../middlewares/database/add.js';
import updateData from '../../../middlewares/database/update.js';
import deleteData from '../../../middlewares/database/delete.js';

const router = Router();

router
.route('/')
/**
* @api {get} v4/waifu Get a Random Waifu
* @apiDescription Retrieve a random Waifu.
* @apiName getRandomWaifu
* @apiGroup images
* @apiPermission user
*
* @apiHeader {String} Authorization User's access token.
*
* @apiSuccess {Object[]} users List of users.
*
* @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data.
* @apiError (Forbidden 403) Forbidden Only users can access the data.
* @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window.
* @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit.
*
* @function createRateLimit
* @description Creates a rate limiter middleware to control the frequency of requests.
* @returns {function} Express middleware function that handles rate limiting.
*
*/
.get(authorize(config.roles.USER), createRateLimiter(), getRandomWaifu)
/**
* @api {post} v4/waifu Increment Waifu Data
* @apiDescription Increment data related to Waifus (only accessible by database moderators).
* @apiName IncrementWaifuData
* @apiGroup images
* @apiPermission database_moderator
*
* @apiHeader {String} Authorization Database Moderator's access token.
*
* @apiSuccess {Object} result Result of the data incrementation.
*
* @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data.
* @apiError (Forbidden 403) Forbidden Only users can access the data.
* @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window.
* @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit.
*
* @function createRateLimit
* @description Creates a rate limiter middleware to control the frequency of requests.
* @returns {function} Express middleware function that handles rate limiting.
*
*/
.post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Waifu'));

router
.route('/:id')
/**
* @api {patch} v4/waifu/:id Update Waifu Data
* @apiDescription Update data related to Waifus with a specific ID (only accessible by database moderators).
* @apiName UpdateWaifuData
* @apiGroup Waifu
* @apiPermission database_moderator
*
* @apiHeader {String} Authorization database moderator access token.
*
* @apiSuccess {Object} result Result of the data update.
*
* @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data.
* @apiError (Forbidden 403) Forbidden Only users can access the data.
* @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window.
* @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit.
*
* @function createRateLimit
* @description Creates a rate limiter middleware to control the frequency of requests.
* @returns {function} Express middleware function that handles rate limiting.
*/
.patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Waifu'))
/**
* @api {delete} v4/waifu/:id Delete Waifu Data
* @apiDescription Delete data related to Waifu with a specific ID (only accessible by admins).
* @apiName DeleteWaifuData
* @apiGroup Waifu
* @apiPermission admin
*
* @apiHeader {String} Authorization Admin's access token.
*
* @apiSuccess {Object} result Result of the data deletion.
*
* @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data.
* @apiError (Forbidden 403) Forbidden Only users can access the data.
* @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window.
* @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit.
*
* @function createRateLimit
* @description Creates a rate limiter middleware to control the frequency of requests.
* @returns {function} Express middleware function that handles rate limiting.
*/
.delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Waifu'));
// Export the router
export default router;
15 changes: 15 additions & 0 deletions src/routes/v4/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import owoifyRoutes from './textUtilities/owoify.js';
import passwordRoutes from './textUtilities/password.js';
import uvuifyRoutes from './textUtilities/uvuify.js';
import uwuifyRoutes from './textUtilities/uwuify.js';
import waifuRoutes from './images/waifu.js';

/**
* Express Router for handling API routes.
Expand Down Expand Up @@ -98,6 +99,20 @@ router.use('/uvuify', uvuifyRoutes);
*/
router.use('/uwuify', uwuifyRoutes);

/**
* @api {use} v4/waifu Use Waifu Routes
* @apiDescription Mount the waifu-related routes for handling images.
* @apiName UseWaifuRoutes
* @apiGroup Routes
*
* @apiSuccess {Object} routes Uwuify-related routes mounted on the parent router.
*
* @function createUwuifyRoutes
* @description Creates and returns a set of routes for handling images related to waifu.
* @returns {Object} Waifu-related routes.
*/
router.use('/waifu', waifuRoutes);

/**
* Exporting the router for use in other parts of the application.
* @exports {Router} router - Express Router instance with mounted routes.
Expand Down

0 comments on commit f94df44

Please sign in to comment.