Skip to content

Commit 2e0a5ca

Browse files
razznbluek-wilmeth
andauthored
v1.1.6 - Graffiti Soul Integration (#42)
* add in soul configs * add tests * remove comment * version --------- Co-authored-by: Kaipo Wilmeth <kwilmeth@fanthreesixty.com>
1 parent e1196c2 commit 2e0a5ca

18 files changed

Lines changed: 508 additions & 14 deletions

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
testEnvironment: "node",
3+
transform: {},
4+
};

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jetsetradio-api",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"description": "A Data Provider relating to the JSR/JSRF universe",
55
"type": "module",
66
"main": "src/app.js",

src/controllers/artistController.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Constants from "../constants/dbConstants.js";
33
import {Actions} from "../config/dbActions.js";
44
import {performDBAction} from "../config/db.js";
55
import LOGGER from "../utils/logger.js";
6+
import {fetchRandom} from "./utilController.js";
67

78
const Artist = "Artist";
89
const Song = "Song";
@@ -21,6 +22,15 @@ export const getArtists = async (req, res) => {
2122
}
2223
};
2324

25+
export const getRandomArtist = async (req, res) => {
26+
try {
27+
res.send(await fetchRandom(req, Artist, "N/A"));
28+
} catch (err) {
29+
LOGGER.error(`Could not fetch random Artist`, err);
30+
res.status(500).json({error: "Failed to fetch random Artist"});
31+
}
32+
};
33+
2434
export const getArtistById = async (req, res) => {
2535
try {
2636
const artist = await performDBAction(
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import Constants from "../constants/dbConstants.js";
2+
import {Actions} from "../config/dbActions.js";
3+
import {performDBAction} from "../config/db.js";
4+
import {sortObjects} from "../utils/utility.js";
5+
import LOGGER from "../utils/logger.js";
6+
import {fetchRandom} from "./utilController.js";
7+
8+
const GraffitiSoul = "GraffitiSoul";
9+
const {JSR_DB, JSRF_DB} = Constants;
10+
11+
export const getAllGraffitiSouls = async (req, res) => {
12+
try {
13+
const sortByValue = req?.query?.sortBy ? req?.query?.sortBy : undefined;
14+
const sortOrder = req?.query?.orderBy ? req?.query?.orderBy : "asc";
15+
const jsrSouls = await fetchJSRSouls(req);
16+
const jsrfSouls = await fetchJSRFSouls(req);
17+
if (sortByValue) {
18+
const Souls = [...jsrSouls, ...jsrfSouls];
19+
return res.send(Souls.sort(sortObjects(sortByValue, sortOrder)));
20+
}
21+
res.send([...jsrSouls, ...jsrfSouls]);
22+
} catch (err) {
23+
LOGGER.error(`Could not fetch ALL GraffitiSouls`, err);
24+
res
25+
.status(500)
26+
.json({message: "Failed to fetch ALL GraffitiSouls", err: err});
27+
}
28+
};
29+
30+
export const getRandomGraffitiSoul = async (req, res) => {
31+
try {
32+
res.send(await fetchRandom(req, GraffitiSoul));
33+
} catch (err) {
34+
LOGGER.error(`Could not fetch random GraffitiSoul`, err);
35+
res.status(500).json({error: "Failed to fetch random GraffitiSoul"});
36+
}
37+
};
38+
39+
export const getJSRGraffitiSouls = async (req, res) => {
40+
try {
41+
res.send(await fetchJSRSouls(req));
42+
} catch (err) {
43+
LOGGER.error(`Could not fetch JSR GraffitiSouls`, err);
44+
res
45+
.status(500)
46+
.json({message: "Failed to fetch JSR GraffitiSouls", err: err});
47+
}
48+
};
49+
50+
export const getJSRFGraffitiSouls = async (req, res) => {
51+
try {
52+
res.send(await fetchJSRFSouls(req));
53+
} catch (err) {
54+
LOGGER.error(`Could not fetch JSRF GraffitiSouls`, err);
55+
res
56+
.status(500)
57+
.json({message: "Failed to fetch JSRF GraffitiSouls", err: err});
58+
}
59+
};
60+
61+
export const getJSRGraffitiSoulById = async (req, res) => {
62+
try {
63+
const soulId = req?.params?.id;
64+
res.send(
65+
await performDBAction(Actions.fetchById, JSR_DB, GraffitiSoul, soulId)
66+
);
67+
} catch (err) {
68+
LOGGER.error(`Could not fetch JSR GraffitiSoul With ID: ${soulId}`, err);
69+
res
70+
.status(500)
71+
.json({message: "Failed to fetch JSR GraffitiSoul By ID", err: err});
72+
}
73+
};
74+
75+
export const getJSRFGraffitiSoulById = async (req, res) => {
76+
try {
77+
const soulId = req?.params?.id;
78+
res.send(
79+
await performDBAction(Actions.fetchById, JSRF_DB, GraffitiSoul, soulId)
80+
);
81+
} catch (err) {
82+
LOGGER.error(`Could not fetch JSRF GraffitiSoul With ID: ${soulId}`, err);
83+
res
84+
.status(500)
85+
.json({message: "Failed to fetch JSRF GraffitiSoul By ID", err: err});
86+
}
87+
};
88+
89+
export const fetchJSRSouls = async (req) => {
90+
if (req?.query) {
91+
return await performDBAction(
92+
Actions.fetchWithQuery,
93+
JSR_DB,
94+
GraffitiSoul,
95+
null,
96+
req?.query
97+
);
98+
}
99+
return await performDBAction(Actions.fetchAll, JSR_DB, GraffitiSoul, null);
100+
};
101+
102+
export const fetchJSRFSouls = async (req) => {
103+
if (req?.query) {
104+
return await performDBAction(
105+
Actions.fetchWithQuery,
106+
JSRF_DB,
107+
GraffitiSoul,
108+
null,
109+
req?.query
110+
);
111+
}
112+
return await performDBAction(Actions.fetchAll, JSRF_DB, GraffitiSoul, null);
113+
};

src/controllers/utilController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import {Actions} from "../config/dbActions.js";
33
import Constants from "../constants/dbConstants.js";
44
import LOGGER from "../utils/logger.js";
55

6-
const {JSR_DB, JSRF_DB, BRC_DB, gameMap} = Constants;
6+
const {JSR_DB, JSRF_DB, BRC_DB, gameMap, CORE_DB} = Constants;
77

88
/* Helper Functions to support all other Controllers */
99
export const fetchRandom = async (req, resource, game) => {
1010
try {
11-
const games =
11+
const games = game === 'N/A' ? [CORE_DB] :
1212
resource === "Audio" ? [JSR_DB, JSRF_DB] : [JSR_DB, JSRF_DB, BRC_DB];
1313
const selectedGame = req?.query?.game;
1414
const count = Number(req?.query?.count);
1515
const safeCount = Number.isFinite(count) && count > 0 ? count : 1;
1616

1717
/* if a game is provided */
18-
if (game || selectedGame) {
18+
if ((game && game !== 'N/A') || selectedGame) {
1919
const dbName = game || gameMap[selectedGame];
2020
return await performDBAction(
2121
Actions.fetchRandom,

src/managers/MiddlewareManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const cacheMiddleware = (req, res, next) => {
164164
}
165165
res.sendResponse = res.send;
166166
res.send = (body) => {
167-
cache.put(cacheKey, body, 3600000); // 1 hour cache time, restart the service to bypass
167+
cache.put(cacheKey, body, 3600000); // 1 hour cache time, restart the service to bypass or run /cache/clear
168168
res.sendResponse(body);
169169
};
170170
LOGGER.info(`Cache missed for url ${req.url}`);

src/public/docs.html

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ <h2>Resources</h2>
4141
<li>Locations</li>
4242
<li>Levels</li>
4343
<li>Graffiti Tags</li>
44+
<li>Graffiti Souls</li>
4445
<li>Songs</li>
4546
<li>Artists</li>
4647
<li>Collectibles</li>
4748
</ul>
4849
<p>The following Resources will be added in a future release of JSRAPI.</p>
4950
<p>If you would like to contribute in adding any of these resources, see the Contributing Docs.</p>
5051
<ul>
51-
<li>Graffiti Souls</li>
5252
<li>Street Challenges</li>
5353
<li>Jet Challenges</li>
5454
<li>Gangs</li>
@@ -154,6 +154,29 @@ <h2>Graffiti-Tags</h2>
154154
<pre id="graffiti-tag-response" class="expandable code-snippet" style="display: none;"></pre>
155155
</div>
156156

157+
<div class="main-container">
158+
<h2>Graffiti-Souls</h2>
159+
<p>A Graffiti Soul is a resource describing a Graffiti Soul from a specific Game.</p>
160+
<p>Endpoints:</p>
161+
<ul>
162+
<li><code class="code-snippet">/graffiti-souls</code> ==> Returns all Graffiti-Souls</li>
163+
<li><code class="code-snippet">/graffiti-souls/random</code> ==> Returns a Random Location From any Game</li>
164+
<li><code class="code-snippet">/graffiti-souls/random?game=jsr</code> ==> Returns a Random JSR Graffiti-Souls</li>
165+
<li><code class="code-snippet">/graffiti-souls/random?game=jsrf</code> ==> Returns a Random JSRF Graffiti-Souls</li>
166+
<li><code class="code-snippet">/graffiti-souls/random?count=10</code> ==> Returns 10 random Graffiti-Souls</li>
167+
<li><code class="code-snippet">/graffiti-souls/jsr</code> ==> Returns all Jet Set Radio Graffiti-Souls</li>
168+
<li><code class="code-snippet">/graffiti-souls/jsr/:id</code> ==> Returns a single JSR Graffiti-Soul by ID</li>
169+
<li><code class="code-snippet">/graffiti-souls/jsrf</code> ==> Returns all Jet Set Radio Future Graffiti-Souls</li>
170+
<li><code class="code-snippet">/graffiti-souls/jsrf/:id</code> ==> Returns a single JSRF Graffiti-Soul by ID</li>
171+
<li><code class="code-snippet">/graffiti-souls/jsrf?size=M</code> ==> Returns all JSRF M Graffiti-Souls</li>
172+
<li><code class="code-snippet">/graffiti-souls?locationName=Hikage Street</code> ==> Returns All Graffiti-Souls in a specific location</li>
173+
</ul>
174+
<p>Example Request:</p>
175+
<code class="code-snippet">https://jetsetradio-api.onrender.com/v1/api/graffiti-souls?sortBy=size&orderBy=desc</code>
176+
<p>Example Response: <button class="expandable-button">Expand</button> </p>
177+
<pre id="graffiti-soul-response" class="expandable code-snippet" style="display: none;"></pre>
178+
</div>
179+
157180
<div class="main-container">
158181
<h2>Collectibles</h2>
159182
<p>A Collectible is a resource describing a location or place from a specific Game. The only supported game currently is Bomb Rush Cyberfunk.</p>
@@ -260,7 +283,7 @@ <h2>Sorting</h2>
260283

261284
<div class="main-container">
262285
<h2>Limiting</h2>
263-
<p>All API routes support the <code class="code-snippet">limit</code> parameter. You can use this to return a limited number of results instead of the entire response.</p>
286+
<p>All API routes(with the exception of /random) support the <code class="code-snippet">limit</code> parameter. You can use this to return a limited number of results instead of the entire response.</p>
264287
<p>Example:</p>
265288
<code class="code-snippet">https://jetsetradio-api.onrender.com/v1/api/locations/jsrf?limit=5</code>
266289
</div>

src/public/js/apiTable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export function createApiTable() {
5656
endpoint: "/v1/api/graffitiTags?size=L",
5757
description: "Returns all Large Graffiti Tags from any game",
5858
},
59+
{
60+
endpoint:
61+
"/v1/api/graffiti-souls/jsrf?locationId=64c95601b33c6b029d936802",
62+
description:
63+
"Returns all Graffiti-Souls from The Skyscraper District Location",
64+
},
5965
{
6066
endpoint: "/v1/api/collectibles?type=Outfit",
6167
description: "Returns all Outfit collectibles from Bomb Rush Cyberfunk",

src/public/js/docs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import characterResource from "./examples/characterExample.js";
33
import locationResource from "./examples/locationExample.js";
44
import levelResource from "./examples/levelExample.js";
55
import graffitiTagResource from "./examples/graffitiTagExample.js";
6+
import graffitiSoulResource from "./examples/graffitiSoulExample.js";
67
import songResource from "./examples/songExample.js";
78
import artistResource from "./examples/artistExample.js";
89
import collectibleResource from "./examples/collectibleExample.js";
@@ -14,6 +15,7 @@ const resources = [
1415
{selector: "#location-response", data: locationResource},
1516
{selector: "#level-response", data: levelResource},
1617
{selector: "#graffiti-tag-response", data: graffitiTagResource},
18+
{selector: "#graffiti-soul-response", data: graffitiSoulResource},
1719
{selector: "#song-response", data: songResource},
1820
{selector: "#artist-response", data: artistResource},
1921
{selector: "#collectible-response", data: collectibleResource},

0 commit comments

Comments
 (0)