Skip to content

Commit da851ce

Browse files
authored
Merge pull request #19 from guilhermeg2k/develop
Release 0.7.0-beta (Rukia)
2 parents 9f12b1c + 046ab08 commit da851ce

34 files changed

Lines changed: 479 additions & 297 deletions

.env.local.example

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ NEXT_PUBLIC_ANILIST_AUTH_URL=
99

1010
NEXT_PUBLIC_DISCORD_AUTH_URL=
1111

12-
TWITTER_CONSUMER_KEY=
13-
TWITTER_CONSUMER_SECRET=
14-
TWITTER_CALLBACK_URL=
15-
1612
NEXT_PUBLIC_MAL_CLIENT_ID=
1713
NEXT_PUBLIC_MAL_REDIRECT_URL=
1814
MAL_CLIENT_SECRET=

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ NEXT_PUBLIC_ANILIST_AUTH_URL: Anilist auth url, you can get it [here](https://an
2222

2323
NEXT_PUBLIC_DISCORD_AUTH_URL: Discord auth url, you can get it [here](https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-authorization-url-example)
2424

25-
TWITTER_CONSUMER_KEY: Twitter consumer key, you can get it [here](https://developer.twitter.com/en/portal/dashboard)
26-
27-
TWITTER_CONSUMER_SECRET: Twitter consumer secret, you can get it [here](https://developer.twitter.com/en/portal/dashboard)
28-
29-
TWITTER_CALLBACK_URL: Twitter callback url, you can get it [here](https://developer.twitter.com/en/portal/dashboard)
30-
3125
NEXT_PUBLIC_MAL_CLIENT_ID: My Anime List client id, you can get it [here](https://myanimelist.net/apiconfig)
3226

3327
NEXT_PUBLIC_MAL_REDIRECT_URL: My Anime List redirect url, you can get it [here](https://myanimelist.net/apiconfig)

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "anipool",
3-
"version": "0.6.0",
4-
"versionName": "Himeno",
3+
"version": "0.7.0",
4+
"versionName": "Rukia",
55
"private": true,
66
"scripts": {
77
"dev": "next dev",
@@ -17,14 +17,15 @@
1717
"@vercel/analytics": "^0.1.6",
1818
"aws-sdk": "^2.1193.0",
1919
"axios": "^0.27.2",
20+
"date-fns": "^2.30.0",
2021
"dayjs": "^1.11.7",
2122
"express-rate-limit": "^6.7.0",
2223
"graphql": "^16.5.0",
2324
"graphql-request": "^4.3.0",
2425
"jose": "^4.8.3",
26+
"jotai": "^2.3.1",
2527
"js-cookie": "^3.0.1",
2628
"next": "^12.3.4",
27-
"oauth-1.0a": "^2.2.6",
2829
"react": "^18.2.0",
2930
"react-dom": "^18.2.0",
3031
"react-toastify": "^9.0.8",
@@ -53,4 +54,4 @@
5354
"tailwindcss": "^3.0.24",
5455
"typescript": "4.7.2"
5556
}
56-
}
57+
}

pnpm-lock.yaml

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

src/backend/controller/authController.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ import authService from '@backend/service/auth/authService';
33
import anilistProvider from '@backend/service/auth/providers/anilistProvider';
44
import discordProvider from '@backend/service/auth/providers/discordProvider';
55
import myAnimelistProvider from '@backend/service/auth/providers/myAnimeListProvider';
6-
import twitterProvider from '@backend/service/auth/providers/twitterProvider';
7-
import twitterService from '@services/twitterService';
86
import { NextApiRequest, NextApiResponse } from 'next';
97
import { ZodError } from 'zod';
108
import {
119
signByDiscordBodySchema,
1210
signByMyAnimeListBodySchema,
1311
signInBodySchema,
1412
signInByAnilistBodySchema,
15-
signInByTwitterBodySchema,
1613
} from './validators/authControllerValidators';
1714

1815
const providerControllers = {
@@ -28,12 +25,6 @@ const providerControllers = {
2825
validator: signByDiscordBodySchema,
2926
},
3027

31-
[OAuthProvider.Twitter]: {
32-
signIn: (credencials: ProviderCredencials) =>
33-
authService.signIn(twitterProvider, credencials as Twitter.Credencials),
34-
validator: signInByTwitterBodySchema,
35-
},
36-
3728
[OAuthProvider.MyAnimeList]: {
3829
signIn: (credencials: ProviderCredencials) =>
3930
authService.signIn(
@@ -62,17 +53,6 @@ const signIn = async (req: NextApiRequest, res: NextApiResponse) => {
6253
}
6354
};
6455

65-
const getTwitterAuthUrl = async (_: NextApiRequest, res: NextApiResponse) => {
66-
try {
67-
const twitterAuthUrl = await twitterService.getAuthUrl();
68-
return res.status(200).send({
69-
twitterAuthUrl,
70-
});
71-
} catch (error) {
72-
return handleError(error, res);
73-
}
74-
};
75-
7656
const handleError = (error: unknown, res: NextApiResponse) => {
7757
if (error instanceof ZodError) {
7858
return res.status(400).send('Bad request');
@@ -82,7 +62,6 @@ const handleError = (error: unknown, res: NextApiResponse) => {
8262

8363
const authController = {
8464
signIn,
85-
getTwitterAuthUrl,
8665
};
8766

8867
export default authController;

src/backend/controller/pollController.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NextApiRequest, NextApiResponse } from 'next';
44
import { ZodError } from 'zod';
55
import {
66
createPollBodySchema,
7+
deleteByIdQueryParamsSchema,
78
getQueryParamsSchema,
89
getResultQueryParamsSchema,
910
listByUserIdQueryParamsSchema,
@@ -32,7 +33,14 @@ const listByUserId = async (req: NextApiRequest, res: NextApiResponse) => {
3233
const getResult = async (req: NextApiRequest, res: NextApiResponse) => {
3334
try {
3435
const { pollId } = getResultQueryParamsSchema.parse(req.query);
35-
const pollResults = await pollService.getResult(String(pollId));
36+
const { userToken } = req.cookies;
37+
const user = userToken && (await getTokenPayload(String(userToken)));
38+
39+
const pollResults = await pollService.getResult(
40+
String(pollId),
41+
user && user.id
42+
);
43+
3644
return res.status(200).send(pollResults);
3745
} catch (error) {
3846
return handleError(error, res);
@@ -41,8 +49,9 @@ const getResult = async (req: NextApiRequest, res: NextApiResponse) => {
4149

4250
const createPoll = async (req: NextApiRequest, res: NextApiResponse) => {
4351
try {
44-
const { title, endDate, options, multiOptions } =
52+
const { title, endDate, options, multiOptions, resultsVisibility } =
4553
createPollBodySchema.parse(req.body);
54+
4655
const { userToken } = req.cookies;
4756
const { id: userId } = await getTokenPayload(String(userToken));
4857

@@ -52,6 +61,7 @@ const createPoll = async (req: NextApiRequest, res: NextApiResponse) => {
5261
endDate: endDate.toISOString(),
5362
options,
5463
multiOptions,
64+
resultsVisibility,
5565
});
5666

5767
return res.status(200).send(pollId);
@@ -60,6 +70,18 @@ const createPoll = async (req: NextApiRequest, res: NextApiResponse) => {
6070
}
6171
};
6272

73+
const deleteById = async (req: NextApiRequest, res: NextApiResponse) => {
74+
try {
75+
const { pollId } = deleteByIdQueryParamsSchema.parse(req.query);
76+
const { userToken } = req.cookies;
77+
const { id: userId } = await getTokenPayload(String(userToken));
78+
await pollService.deleteById(pollId, userId);
79+
return res.status(200).send('DELETED');
80+
} catch (error) {
81+
return handleError(error, res);
82+
}
83+
};
84+
6385
const handleError = (error: unknown, res: NextApiResponse) => {
6486
if (error instanceof ZodError) {
6587
return res.status(400).send('Bad request');
@@ -72,6 +94,7 @@ const pollController = {
7294
listByUserId,
7395
getResult,
7496
createPoll,
75-
};
97+
deleteById,
98+
} as const;
7699

77100
export default pollController;

src/backend/controller/validators/authControllerValidators.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ export const signInByAnilistBodySchema = z.object({
1313
}),
1414
});
1515

16-
export const signInByTwitterBodySchema = z.object({
17-
provider: z.literal(OAuthProvider.Twitter),
18-
credencials: z.object({
19-
OAuthToken: z.string(),
20-
OAuthVerifier: z.string(),
21-
}),
22-
});
23-
2416
export const signByDiscordBodySchema = z.object({
2517
provider: z.literal(OAuthProvider.Discord),
2618
credencials: z.object({

src/backend/controller/validators/pollControllerValidators.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export const getResultQueryParamsSchema = z.object({
1212
pollId: z.string().uuid(),
1313
});
1414

15+
export const deleteByIdQueryParamsSchema = z.object({
16+
pollId: z.string().uuid(),
17+
});
18+
1519
export const createPollBodySchema = z.object({
1620
title: z.string(),
1721
endDate: z.preprocess((endDate) => {
@@ -26,4 +30,5 @@ export const createPollBodySchema = z.object({
2630
})
2731
),
2832
multiOptions: z.boolean(),
33+
resultsVisibility: z.enum(['ALWAYS_VISIBLE', 'AFTER_END']),
2934
});

src/backend/enums.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export enum OAuthProvider {
22
MyAnimeList = 'MAL',
33
Anilist = 'ANILIST',
4-
Twitter = 'TWITTER',
54
Discord = 'DISCORD',
65
}

src/backend/repository/pollRepository.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,21 @@ const createAndReturnId = async (poll: Poll) => {
4444
return id;
4545
};
4646

47+
const deleteById = async (pollId: string) => {
48+
const params = {
49+
TableName: POLL_TABLE_NAME,
50+
Key: {
51+
id: pollId,
52+
},
53+
};
54+
await dynamoDb.delete(params).promise();
55+
};
56+
4757
const pollRepository = {
4858
get,
49-
createAndReturnId,
5059
listByUserId,
51-
};
60+
createAndReturnId,
61+
deleteById,
62+
} as const;
5263

5364
export default pollRepository;

0 commit comments

Comments
 (0)