Skip to content

Commit

Permalink
feat(routes): Add in 2014 routes and move controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
bagelbits committed Dec 28, 2024
1 parent 06aaef0 commit 78a3ffc
Show file tree
Hide file tree
Showing 93 changed files with 272 additions and 186 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
db:
# image: ghcr.io/5e-bits/5e-database:latest
build: ../5e-database
image: ghcr.io/5e-bits/5e-database:latest
# build: ../5e-database
ports:
- '27017:27017'

Expand Down
4 changes: 4 additions & 0 deletions src/controllers/api/2014/abilityScoreController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import AbilityScore from '../../../models/2014/abilityScore/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(AbilityScore);
4 changes: 4 additions & 0 deletions src/controllers/api/2014/alignmentController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Alignment from '../../../models/2014/alignment/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(Alignment);
4 changes: 4 additions & 0 deletions src/controllers/api/2014/backgroundController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Background from '../../../models/2014/background/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(Background);
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Request, Response, NextFunction } from 'express';

import { ResourceList, escapeRegExp } from '../../util/index.js';

import Class from '../../models/2014/class/index.js';
import Feature from '../../models/2014/feature/index.js';
import Level from '../../models/2014/level/index.js';
import Proficiency from '../../models/2014/proficiency/index.js';
import SimpleController from '../simpleController.js';
import Spell from '../../models/2014/spell/index.js';
import Subclass from '../../models/2014/subclass/index.js';
import { ResourceList, escapeRegExp } from '../../../util/index.js';

import Class from '../../../models/2014/class/index.js';
import Feature from '../../../models/2014/feature/index.js';
import Level from '../../../models/2014/level/index.js';
import Proficiency from '../../../models/2014/proficiency/index.js';
import SimpleController from '../../simpleController.js';
import Spell from '../../../models/2014/spell/index.js';
import Subclass from '../../../models/2014/subclass/index.js';

const simpleController = new SimpleController(Class);
interface ShowLevelsForClassQuery {
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/api/2014/conditionController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Condition from '../../../models/2014/condition/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(Condition);
4 changes: 4 additions & 0 deletions src/controllers/api/2014/damageTypeController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import DamageType from '../../../models/2014/damageType/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(DamageType);
4 changes: 4 additions & 0 deletions src/controllers/api/2014/equipmentCategoryController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import EquipmentCategory from '../../../models/2014/equipmentCategory/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(EquipmentCategory);
4 changes: 4 additions & 0 deletions src/controllers/api/2014/equipmentController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Equipment from '../../../models/2014/equipment/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(Equipment);
4 changes: 4 additions & 0 deletions src/controllers/api/2014/featController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Feat from '../../../models/2014/feat/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(Feat);
4 changes: 4 additions & 0 deletions src/controllers/api/2014/featureController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Feature from '../../../models/2014/feature/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(Feature);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextFunction, Request, Response } from 'express';

import { GetObjectCommand } from '@aws-sdk/client-s3';
import { awsS3Client } from '../../util/index.js';
import { awsS3Client } from '../../../util/index.js';

const show = async (req: Request, res: Response, next: NextFunction) => {
try {
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/api/2014/languageController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Language from '../../../models/2014/language/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(Language);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express';

import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';
import MagicItem from '../../models/2014/magicItem/index.js';
import { ResourceList, escapeRegExp, redisClient } from '../../../util/index.js';
import MagicItem from '../../../models/2014/magicItem/index.js';

interface IndexQuery {
name?: { $regex: RegExp };
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/api/2014/magicSchoolController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import MagicSchool from '../../../models/2014/magicSchool/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(MagicSchool);
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Request, Response, NextFunction } from 'express';

import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';
import { ResourceList, escapeRegExp, redisClient } from '../../../util/index.js';

import Monster from '../../models/2014/monster/index.js';
import Monster from '../../../models/2014/monster/index.js';

interface IndexQuery {
name?: { $regex: RegExp };
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/api/2014/proficiencyController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Proficiency from '../../../models/2014/proficiency/index.js';
import SimpleController from '../../simpleController.js';

export default new SimpleController(Proficiency);
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Request, Response, NextFunction } from 'express';

import Proficiency from '../../models/2014/proficiency/index.js';
import Race from '../../models/2014/race/index.js';
import { ResourceList } from '../../util/data.js';
import SimpleController from '../simpleController.js';
import Subrace from '../../models/2014/subrace/index.js';
import Trait from '../../models/2014/trait/index.js';
import Proficiency from '../../../models/2014/proficiency/index.js';
import Race from '../../../models/2014/race/index.js';
import { ResourceList } from '../../../util/data.js';
import SimpleController from '../../simpleController.js';
import Subrace from '../../../models/2014/subrace/index.js';
import Trait from '../../../models/2014/trait/index.js';

const simpleController = new SimpleController(Race);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express';
import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';
import { ResourceList, escapeRegExp, redisClient } from '../../../util/index.js';

import Rule from '../../models/2014/rule/index.js';
import Rule from '../../../models/2014/rule/index.js';

interface IndexQuery {
name?: { $regex: RegExp };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express';
import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';
import { ResourceList, escapeRegExp, redisClient } from '../../../util/index.js';

import RuleSection from '../../models/2014/ruleSection/index.js';
import RuleSection from '../../../models/2014/ruleSection/index.js';
interface IndexQuery {
name?: { $regex: RegExp };
desc?: { $regex: RegExp };
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/api/2014/skillController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import SimpleController from '../../simpleController.js';
import Skill from '../../../models/2014/skill/index.js';

export default new SimpleController(Skill);
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Request, Response, NextFunction } from 'express';
import { ResourceList, escapeRegExp, redisClient } from '../../util/index.js';
import { ResourceList, escapeRegExp, redisClient } from '../../../util/index.js';

interface IndexQuery {
name?: { $regex: RegExp };
level?: { $in: string[] };
'school.name'?: { $in: RegExp[] };
}

import Spell from '../../models/2014/spell/index.js';
import Spell from '../../../models/2014/spell/index.js';

export const index = async (req: Request, res: Response, next: NextFunction) => {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response, NextFunction } from 'express';
import Feature from '../../models/2014/feature/index.js';
import Level from '../../models/2014/level/index.js';
import { ResourceList } from '../../util/data.js';
import SimpleController from '../simpleController.js';
import Subclass from '../../models/2014/subclass/index.js';
import Feature from '../../../models/2014/feature/index.js';
import Level from '../../../models/2014/level/index.js';
import { ResourceList } from '../../../util/data.js';
import SimpleController from '../../simpleController.js';
import Subclass from '../../../models/2014/subclass/index.js';

const simpleController = new SimpleController(Subclass);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response, NextFunction } from 'express';
import Proficiency from '../../models/2014/proficiency/index.js';
import { ResourceList } from '../../util/data.js';
import SimpleController from '../simpleController.js';
import Subrace from '../../models/2014/subrace/index.js';
import Trait from '../../models/2014/trait/index.js';
import Proficiency from '../../../models/2014/proficiency/index.js';
import { ResourceList } from '../../../util/data.js';
import SimpleController from '../../simpleController.js';
import Subrace from '../../../models/2014/subrace/index.js';
import Trait from '../../../models/2014/trait/index.js';

const simpleController = new SimpleController(Subrace);

Expand Down
4 changes: 4 additions & 0 deletions src/controllers/api/2014/traitController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import SimpleController from '../../simpleController.js';
import Trait from '../../../models/2014/trait/index.js';

export default new SimpleController(Trait);
4 changes: 4 additions & 0 deletions src/controllers/api/2014/weaponPropertyController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import SimpleController from '../../simpleController.js';
import WeaponProperty from '../../../models/2014/weaponProperty/index.js';

export default new SimpleController(WeaponProperty);
4 changes: 0 additions & 4 deletions src/controllers/api/abilityScoreController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/alignmentController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/backgroundController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/conditionController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/damageTypeController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/equipmentCategoryController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/equipmentController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/featController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/featureController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/languageController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/magicSchoolController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/proficiencyController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/skillController.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/controllers/api/traitController.ts

This file was deleted.

22 changes: 22 additions & 0 deletions src/controllers/api/v2014Controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Request, Response, NextFunction } from 'express';
import Collection from '../../models/2014/collection/index.js';

export const index = async (req: Request, res: Response, next: NextFunction) => {
try {
const data = await Collection.find({})
.select({ index: 1, _id: 0 })
.sort({ index: 'asc' })
.exec();

const apiIndex: Record<string, string> = {};
data.forEach((item) => {
if (item.index === 'levels') return;

apiIndex[item.index] = `/api/2014/${item.index}`;
});

return res.status(200).json(apiIndex);
} catch (err) {
next(err);
}
};
4 changes: 0 additions & 4 deletions src/controllers/api/weaponPropertyController.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/controllers/apiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const index = async (req: Request, res: Response, next: NextFunction) =>
.sort({ index: 'asc' })
.exec();

const apiIndex: Record<string, string> = {};
const apiIndex: Record<string, string> = { '2014': '/api/2014' };
data.forEach((item) => {
if (item.index === 'levels') return;

Expand Down
4 changes: 3 additions & 1 deletion src/routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ import {
SubracesHandler,
TraitsHandler,
WeaponPropertiesHandler,
} from './api/index.js';
} from './api/2014/index.js';
import V2014Handler from './api/2014.js';

import express from 'express';
import { index } from '../controllers/apiController.js';

const router = express.Router();

router.get('/', index);
router.use('/2014', V2014Handler);

router.use('/ability-scores', AbilityScoresHandler);
router.use('/alignments', AlignmentsHandler);
Expand Down
Loading

0 comments on commit 78a3ffc

Please sign in to comment.