Skip to content

Commit

Permalink
Feat(Movies): Add CRUD API endpoints
Browse files Browse the repository at this point in the history
Adds CRUD API endpoints for movies
* Creates isValidKey util
* Creates camelCaseToSnakeCase util
* Creates GuildRequest util type
  • Loading branch information
mikeyaworski committed Jul 23, 2024
1 parent 04862b0 commit 104afdd
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/__test__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getSecondsFromClockString,
getSecondsFromUrlTimestamp,
getUniqueId,
camelCaseToSnakeCase,
isUuid,
notUuidValidator,
} from '../utils';
Expand Down Expand Up @@ -306,6 +307,22 @@ describe('utils', () => {
});
});

describe('camelCaseToSnakeCase', () => {
test('fooBar', () => {
expect(camelCaseToSnakeCase('fooBar')).toBe('foo_bar');
});
test('foo_bar', () => {
expect(camelCaseToSnakeCase('foo_bar')).toBe('foo_bar');
});
test('fooBarFooBar', () => {
expect(camelCaseToSnakeCase('fooBarFooBar')).toBe('foo_bar_foo_bar');
});
test('IMDb', () => {
// This is not meant to be supported, so this test verifies that we don't support it.
expect(camelCaseToSnakeCase('IMDb')).toBe('_i_m_db');
});
});

describe('isUuid', () => {
test('ac548368-df12-4cf7-b7e5-d078adf92cf7', () => {
expect(isUuid('ac548368-df12-4cf7-b7e5-d078adf92cf7')).toBe(true);
Expand Down
6 changes: 4 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import guildsRouter from 'src/api/routes/guilds';
import dmsRouter from 'src/api/routes/dms';
import chessRouter from 'src/api/routes/chess';
import playerRouter from 'src/api/routes/player';
import webhooksRouter from 'src/api/routes/webhooks';
import chatGptRouter from 'src/api/routes/chatgpt';
import moviesRouter from 'src/api/routes/movies';
import webhooksRouter from 'src/api/routes/webhooks';

import { WAKE_INTERVAL } from 'src/constants';
import { log, error } from 'src/logging';
Expand Down Expand Up @@ -64,8 +65,9 @@ export function initApi(): void {
app.use('/dms', dmsRouter);
app.use('/chess', chessRouter);
app.use('/player', playerRouter);
app.use('/webhooks', webhooksRouter);
app.use('/chatgpt', chatGptRouter);
app.use('/movies', moviesRouter);
app.use('/webhooks', webhooksRouter);
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
httpServer.listen(port, () => {
log('Listening on port', port);
Expand Down
4 changes: 4 additions & 0 deletions src/api/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export type AuthRequest<T = Request> = T & {
user: User,
}

export type GuildRequest<T = Request> = T & {
guild: Guild,
}

// Storing promises in a global variable lets us avoid rate limiting issues if multiple
// endpoints are hit simultaneously and there is a cache miss. This ensures the Discord API
// requests will be made only once since all request handlers will await the same promise
Expand Down
Loading

0 comments on commit 104afdd

Please sign in to comment.