Skip to content

Commit

Permalink
feat(admin): 지원자 수 google spreadsheet 연동 후 cron 적용하여 1시간마다 데이터 가져오기 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
saseungmin committed Aug 20, 2024
1 parent 2164841 commit c14a8e9
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 10 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion apps/admin/@types/environment.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
namespace NodeJS {
interface ProcessEnv extends NodeJS.ProcessEnv {
AUTH_SECRET: string;
AUTH_GOOGLE_ID: string;
AUTH_GOOGLE_SECRET: string;
ALLOWED_EMAIL_ADDRESSES: string;
DND_ACADEMY_V2_BLOB_READ_WRITE_TOKEN: string;
AUTH_SECRET: string;
GOOGLE_CLIENT_EMAIL: string;
GOOGLE_PRIVATE_KEY: string;
CRON_SECRET: string;
}
}
2 changes: 2 additions & 0 deletions apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"@vercel/blob": "0.23.4",
"clsx": "2.1.1",
"framer-motion": "11.2.10",
"google-auth-library": "9.13.0",
"google-spreadsheet": "4.1.2",
"next": "14.2.4",
"next-auth": "5.0.0-beta.19",
"react": "18.3.1",
Expand Down
53 changes: 53 additions & 0 deletions apps/admin/src/app/api/cron/current-applicant-count/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { NextRequest, NextResponse } from 'next/server';

import { put } from '@vercel/blob';
import { JWT } from 'google-auth-library';
import { GoogleSpreadsheet } from 'google-spreadsheet';

export const dynamic = 'force-dynamic';

export const runtime = 'nodejs';

export async function GET(request: NextRequest) {
const authHeader = request.headers.get('authorization');
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return new Response('Unauthorized', {
status: 401,
});
}

const serviceAccountAuth = new JWT({
email: process.env.GOOGLE_CLIENT_EMAIL,
key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'),
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});

const developerApplicantDoc = new GoogleSpreadsheet('1LLxVCTkqtTZoMftrEkYOlwVdyEwoEKwCg7WvXwfW2Rk', serviceAccountAuth);
const designerApplicantDoc = new GoogleSpreadsheet('1BToiD3gjzT-SKWeKnQMRuFvGXmYv44oEigSIJy_w1Jc', serviceAccountAuth);

await developerApplicantDoc.loadInfo();
await designerApplicantDoc.loadInfo();

const developerApplicantRows = await developerApplicantDoc.sheetsByIndex[0].getRows();
const designerApplicantRows = await designerApplicantDoc.sheetsByIndex[0].getRows();

const currentApplicantCountForm = {
developer: developerApplicantRows.length,
designer: designerApplicantRows.length,
};

const jsonString = JSON.stringify(currentApplicantCountForm);

const requestBlob = new Blob([jsonString], { type: 'application/json' });

await put('current_applicant_count.json', requestBlob, {
access: 'public',
token: process.env.DND_ACADEMY_V2_BLOB_READ_WRITE_TOKEN,
addRandomSuffix: false,
cacheControlMaxAge: 3600,
});

return NextResponse.json(currentApplicantCountForm, {
status: 200,
});
}
6 changes: 6 additions & 0 deletions apps/admin/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"crons": [{
"path": "/api/cron/current-applicant-count",
"schedule": "0 * * * *"
}]
}
4 changes: 0 additions & 4 deletions packages/ui/src/hooks/useIsMounted.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { useEffect, useState } from 'react';

/**
* PageTitle component
* @module @dnd-academy/ui/client
*/
function useIsMounted() {
const [mounted, setMounted] = useState(false);

Expand Down
138 changes: 133 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5807,6 +5807,8 @@ __metadata:
eslint-plugin-testing-library: "npm:6.2.0"
eslint-plugin-unused-imports: "npm:3.2.0"
framer-motion: "npm:11.2.10"
google-auth-library: "npm:9.13.0"
google-spreadsheet: "npm:4.1.2"
identity-obj-proxy: "npm:3.0.0"
jest: "npm:29.7.0"
jest-environment-jsdom: "npm:29.7.0"
Expand Down Expand Up @@ -6354,6 +6356,17 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.4.0":
version: 1.7.4
resolution: "axios@npm:1.7.4"
dependencies:
follow-redirects: "npm:^1.15.6"
form-data: "npm:^4.0.0"
proxy-from-env: "npm:^1.1.0"
checksum: 10/7a1429be1e3d0c2e1b96d4bba4d113efbfabc7c724bed107beb535c782c7bea447ff634886b0c7c43395a264d085450d009eb1154b5f38a8bae49d469fdcbc61
languageName: node
linkType: hard

"axobject-query@npm:^3.2.1":
version: 3.2.4
resolution: "axobject-query@npm:3.2.4"
Expand Down Expand Up @@ -6509,7 +6522,7 @@ __metadata:
languageName: node
linkType: hard

"base64-js@npm:^1.3.1":
"base64-js@npm:^1.3.0, base64-js@npm:^1.3.1":
version: 1.5.1
resolution: "base64-js@npm:1.5.1"
checksum: 10/669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005
Expand Down Expand Up @@ -6539,6 +6552,13 @@ __metadata:
languageName: node
linkType: hard

"bignumber.js@npm:^9.0.0":
version: 9.1.2
resolution: "bignumber.js@npm:9.1.2"
checksum: 10/d89b8800a987225d2c00dcbf8a69dc08e92aa0880157c851c287b307d31ceb2fc2acb0c62c3e3a3d42b6c5fcae9b004035f13eb4386e56d529d7edac18d5c9d8
languageName: node
linkType: hard

"binary-extensions@npm:^2.0.0":
version: 2.3.0
resolution: "binary-extensions@npm:2.3.0"
Expand Down Expand Up @@ -6758,6 +6778,13 @@ __metadata:
languageName: node
linkType: hard

"buffer-equal-constant-time@npm:1.0.1":
version: 1.0.1
resolution: "buffer-equal-constant-time@npm:1.0.1"
checksum: 10/80bb945f5d782a56f374b292770901065bad21420e34936ecbe949e57724b4a13874f735850dd1cc61f078773c4fb5493a41391e7bda40d1fa388d6bd80daaab
languageName: node
linkType: hard

"buffer-from@npm:^1.0.0":
version: 1.1.2
resolution: "buffer-from@npm:1.1.2"
Expand Down Expand Up @@ -8594,6 +8621,15 @@ __metadata:
languageName: node
linkType: hard

"ecdsa-sig-formatter@npm:1.0.11, ecdsa-sig-formatter@npm:^1.0.11":
version: 1.0.11
resolution: "ecdsa-sig-formatter@npm:1.0.11"
dependencies:
safe-buffer: "npm:^5.0.1"
checksum: 10/878e1aab8a42773320bc04c6de420bee21aebd71810e40b1799880a8a1c4594bcd6adc3d4213a0fb8147d4c3f529d8f9a618d7f59ad5a9a41b142058aceda23f
languageName: node
linkType: hard

"ee-first@npm:1.1.1":
version: 1.1.1
resolution: "ee-first@npm:1.1.1"
Expand Down Expand Up @@ -9717,7 +9753,7 @@ __metadata:
languageName: node
linkType: hard

"extend@npm:~3.0.2":
"extend@npm:^3.0.2, extend@npm:~3.0.2":
version: 3.0.2
resolution: "extend@npm:3.0.2"
checksum: 10/59e89e2dc798ec0f54b36d82f32a27d5f6472c53974f61ca098db5d4648430b725387b53449a34df38fd0392045434426b012f302b3cc049a6500ccf82877e4e
Expand Down Expand Up @@ -10018,7 +10054,7 @@ __metadata:
languageName: node
linkType: hard

"follow-redirects@npm:^1.14.0":
"follow-redirects@npm:^1.14.0, follow-redirects@npm:^1.15.6":
version: 1.15.6
resolution: "follow-redirects@npm:1.15.6"
peerDependenciesMeta:
Expand Down Expand Up @@ -10279,6 +10315,29 @@ __metadata:
languageName: node
linkType: hard

"gaxios@npm:^6.0.0, gaxios@npm:^6.1.1":
version: 6.7.1
resolution: "gaxios@npm:6.7.1"
dependencies:
extend: "npm:^3.0.2"
https-proxy-agent: "npm:^7.0.1"
is-stream: "npm:^2.0.0"
node-fetch: "npm:^2.6.9"
uuid: "npm:^9.0.1"
checksum: 10/c85599162208884eadee91215ebbfa1faa412551df4044626cb561300e15193726e8f23d63b486533e066dadad130f58ed872a23acab455238d8d48b531a0695
languageName: node
linkType: hard

"gcp-metadata@npm:^6.1.0":
version: 6.1.0
resolution: "gcp-metadata@npm:6.1.0"
dependencies:
gaxios: "npm:^6.0.0"
json-bigint: "npm:^1.0.0"
checksum: 10/a0d12a9cb7499fdb9de0fff5406aa220310c1326b80056be8d9b747aae26414f99d14bd795c0ec52ef7d0473eef9d61bb657b8cd3d8186c8a84c4ddbff025fe9
languageName: node
linkType: hard

"gensync@npm:^1.0.0-beta.2":
version: 1.0.0-beta.2
resolution: "gensync@npm:1.0.0-beta.2"
Expand Down Expand Up @@ -10625,6 +10684,35 @@ __metadata:
languageName: node
linkType: hard

"google-auth-library@npm:9.13.0":
version: 9.13.0
resolution: "google-auth-library@npm:9.13.0"
dependencies:
base64-js: "npm:^1.3.0"
ecdsa-sig-formatter: "npm:^1.0.11"
gaxios: "npm:^6.1.1"
gcp-metadata: "npm:^6.1.0"
gtoken: "npm:^7.0.0"
jws: "npm:^4.0.0"
checksum: 10/132616d66833ac6b19d69360ac955e595c90261ad2f329c7b433615f4e21f7d831c6498dcd271ef92ea3e051c1bc26eed60a10b37d50de8936c36ae4459d8bc7
languageName: node
linkType: hard

"google-spreadsheet@npm:4.1.2":
version: 4.1.2
resolution: "google-spreadsheet@npm:4.1.2"
dependencies:
axios: "npm:^1.4.0"
lodash: "npm:^4.17.21"
peerDependencies:
google-auth-library: ^8.8.0 || ^9.0.0
peerDependenciesMeta:
google-auth-library:
optional: true
checksum: 10/7121b13050e622c1aec0595cda70210b3f354683a06dea6a7a73514bf0c8b34f38e30b5dd59e055687d7da0b466ae26d748a49fc75b612289f04c090ea62f207
languageName: node
linkType: hard

"gopd@npm:^1.0.1":
version: 1.0.1
resolution: "gopd@npm:1.0.1"
Expand Down Expand Up @@ -10658,6 +10746,16 @@ __metadata:
languageName: node
linkType: hard

"gtoken@npm:^7.0.0":
version: 7.1.0
resolution: "gtoken@npm:7.1.0"
dependencies:
gaxios: "npm:^6.0.0"
jws: "npm:^4.0.0"
checksum: 10/640392261e55c9242137a81a4af8feb053b57061762cedddcbb6a0d62c2314316161808ac2529eea67d06d69fdc56d82361af50f2d840a04a87ea29e124d7382
languageName: node
linkType: hard

"handlebars@npm:^4.4.3":
version: 4.7.8
resolution: "handlebars@npm:4.7.8"
Expand Down Expand Up @@ -12521,6 +12619,15 @@ __metadata:
languageName: node
linkType: hard

"json-bigint@npm:^1.0.0":
version: 1.0.0
resolution: "json-bigint@npm:1.0.0"
dependencies:
bignumber.js: "npm:^9.0.0"
checksum: 10/cd3973b88e5706f8f89d2a9c9431f206ef385bd5c584db1b258891a5e6642507c32316b82745239088c697f5ddfe967351e1731f5789ba7855aed56ad5f70e1f
languageName: node
linkType: hard

"json-buffer@npm:3.0.1":
version: 3.0.1
resolution: "json-buffer@npm:3.0.1"
Expand Down Expand Up @@ -12653,6 +12760,27 @@ __metadata:
languageName: node
linkType: hard

"jwa@npm:^2.0.0":
version: 2.0.0
resolution: "jwa@npm:2.0.0"
dependencies:
buffer-equal-constant-time: "npm:1.0.1"
ecdsa-sig-formatter: "npm:1.0.11"
safe-buffer: "npm:^5.0.1"
checksum: 10/ab983f6685d99d13ddfbffef9b1c66309a536362a8412d49ba6e687d834a1240ce39290f30ac7dbe241e0ab6c76fee7ff795776ce534e11d148158c9b7193498
languageName: node
linkType: hard

"jws@npm:^4.0.0":
version: 4.0.0
resolution: "jws@npm:4.0.0"
dependencies:
jwa: "npm:^2.0.0"
safe-buffer: "npm:^5.0.1"
checksum: 10/1d15f4cdea376c6bd6a81002bd2cb0bf3d51d83da8f0727947b5ba3e10cf366721b8c0d099bf8c1eb99eb036e2c55e5fd5efd378ccff75a2b4e0bd10002348b9
languageName: node
linkType: hard

"keyv@npm:^4.5.3":
version: 4.5.4
resolution: "keyv@npm:4.5.4"
Expand Down Expand Up @@ -13840,7 +13968,7 @@ __metadata:
languageName: node
linkType: hard

"node-fetch@npm:^2.6.7":
"node-fetch@npm:^2.6.7, node-fetch@npm:^2.6.9":
version: 2.7.0
resolution: "node-fetch@npm:2.7.0"
dependencies:
Expand Down Expand Up @@ -18475,7 +18603,7 @@ __metadata:
languageName: node
linkType: hard

"uuid@npm:^9.0.0":
"uuid@npm:^9.0.0, uuid@npm:^9.0.1":
version: 9.0.1
resolution: "uuid@npm:9.0.1"
bin:
Expand Down

0 comments on commit c14a8e9

Please sign in to comment.