Skip to content

Commit a5fe564

Browse files
pizza6inchdada878
authored andcommitted
feat: implement player and fragment APIs with token validation; remove obsolete routes and add new data types
1 parent b8a7e4d commit a5fe564

File tree

13 files changed

+774
-847
lines changed

13 files changed

+774
-847
lines changed

src/app/api/fragment/booth/route.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { forbidden, success } from "@/utils/response";
2+
import { NextRequest } from "next/server";
3+
import { SharedFragmentData } from "@/types";
4+
5+
// 指南針計畫分享的板塊資料
6+
export const GET = async (request: NextRequest) => {
7+
const data = await request.json();
8+
const { token } = data;
9+
// 先確認是否存在使用者
10+
const result = await fetch(`https://sitcon.opass.app/status?token=${token}`);
11+
if (result.status === 400) return forbidden("並非本次與會者");
12+
13+
// 用token向資料庫拿取該player被指南針計畫分享的板塊資料,不包含Qrcode & 自己的板塊
14+
// prisma query here
15+
// return SharedFragmentData
16+
};

src/app/api/fragment/require/route.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/app/api/fragment/route.ts

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,16 @@
1+
import { forbidden, success } from "@/utils/response";
12
import { NextRequest } from "next/server";
3+
import { FragmentData } from "@/types";
24

5+
// 全部的板塊資料
36
export const GET = async (request: NextRequest) => {
4-
// TODO: get data
5-
/*
6-
{
7-
{
8-
type: "0",
9-
quantity: 1,
10-
},
11-
{
12-
type: "1",
13-
quantity: 2,
14-
},
15-
{
16-
type: "2",
17-
quantity: 3,
18-
},
19-
{
20-
type: "3",
21-
quantity: 4,
22-
},
23-
{
24-
type: "4",
25-
quantity: 1,
26-
},
27-
{
28-
type: "5",
29-
quantity: 1,
30-
},
31-
{
32-
type: "6",
33-
quantity: 1,
34-
},
35-
{
36-
type: "7",
37-
quantity: 0,
38-
},
39-
}
40-
*/
7+
const data = await request.json();
8+
const { token } = data;
9+
// 先確認是否存在使用者
10+
const result = await fetch(`https://sitcon.opass.app/status?token=${token}`);
11+
if (result.status === 400) return forbidden("並非本次與會者");
12+
13+
// 用token向資料庫拿取該player關聯的所有板塊,包含指南針 & QrCode共享
14+
// prisma query here
15+
// return FragmentData
4116
};

src/app/api/fragment/self/route.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { forbidden, success } from "@/utils/response";
2+
import { NextRequest } from "next/server";
3+
import { FragmentData } from "@/types";
4+
5+
// 玩家自己的板塊資料
6+
export const GET = async (request: NextRequest) => {
7+
const data = await request.json();
8+
const { token } = data;
9+
// 先確認是否存在使用者
10+
const result = await fetch(`https://sitcon.opass.app/status?token=${token}`);
11+
if (result.status === 400) return forbidden("並非本次與會者");
12+
13+
// 用token向資料庫拿取該player自己的板塊資料,不包含指南針 & 被分享的板塊,僅由成就&攤位解鎖獲取
14+
// prisma query here
15+
// return FragmentData
16+
};
Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,16 @@
1-
// TODO: get
2-
/*
3-
{
4-
[
5-
{
6-
playerAvatar:"https:456789",
7-
blocks: [
8-
{
9-
type: "0",
10-
quantity: 2,
11-
},
12-
{
13-
type: "4",
14-
quantity: 1,
15-
},
16-
]
17-
},
18-
{
19-
playerAvatar:"https:456789",
20-
blocks: [
21-
{
22-
type: "0",
23-
quantity: 1,
24-
},
25-
{
26-
type: "4",
27-
quantity: 1,
28-
},
29-
{
30-
type: "7",
31-
quantity: 1,
32-
},
33-
]
34-
}
35-
]
36-
}
37-
*/
1+
import { forbidden, success } from "@/utils/response";
2+
import { NextRequest } from "next/server";
3+
import { SharedFragmentData } from "@/types";
4+
5+
// Qrcode分享的板塊資料
6+
export const GET = async (request: NextRequest) => {
7+
const data = await request.json();
8+
const { token } = data;
9+
// 先確認是否存在使用者
10+
const result = await fetch(`https://sitcon.opass.app/status?token=${token}`);
11+
if (result.status === 400) return forbidden("並非本次與會者");
12+
13+
// 用token向資料庫拿取該player被分享的板塊資料,不包含指南針 & 自己的板塊
14+
// prisma query here
15+
// return SharedFragmentData
16+
};
Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
1-
// todo: get / post
2-
3-
/*
4-
TODO: get-req
5-
{
6-
playerId:123
7-
}
8-
TODO: get-res
9-
{
10-
{
11-
[
12-
{
13-
id:1,
14-
name:"456",
15-
description:"lorem lorem lorem lorem",
16-
target:5,
17-
progress:2,
18-
prizeBlockType:"2" //隨機生成? 待討論
19-
},
20-
...
21-
{
22-
id:9,
23-
name:"789",
24-
description:"lorem lorem lorem lorem",
25-
target:5,
26-
progress:5,
27-
prizeBlockType:"2" //隨機生成? 待討論
28-
}
29-
]
30-
}
31-
}
32-
*/
1+
import { forbidden, success } from "@/utils/response";
2+
import { NextRequest } from "next/server";
3+
import { AchievementData } from "@/types";
4+
5+
export const GET = async (request: NextRequest) => {
6+
const data = await request.json();
7+
const { token } = data;
8+
9+
// 先確認是否存在使用者
10+
const result = await fetch(`https://sitcon.opass.app/status?token=${token}`);
11+
if (result.status === 400) return forbidden("並非本次與會者");
12+
13+
// 用token向資料庫拿取該player的所有成就解鎖狀態
14+
// prisma query here
15+
16+
// return AchievementData
17+
};
18+
19+
// 錯誤情況 1: 並非本次與會者invalid token
20+
// 錯誤情況 2: 抓取資料問題
21+
22+
export const POST = async (request: NextRequest) => {
23+
const data = await request.json();
24+
const { token, achievementId } = data;
25+
26+
// 先確認是否存在使用者
27+
const result = await fetch(`https://sitcon.opass.app/status?token=${token}`);
28+
if (result.status === 400) return forbidden("並非本次與會者");
29+
30+
// 用token向prisma拿取對應 achievementId 的成就資料
31+
// achievement.progress += 1
32+
// 判斷progress是否等於target
33+
// 是的話解鎖成就,隨機生成prizeBlockType指定到achievement.prizeBlockType
34+
// 寫入prisma database
35+
// return success 給成就工作者
36+
};
37+
38+
// 錯誤情況 1: 並非本次與會者invalid token
39+
// 錯誤情況 2: 無效的成就編號
40+
// 錯誤情況 3: 抓取資料問題

src/app/api/player/booth/route.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { forbidden, success } from "@/utils/response";
2+
import { NextRequest } from "next/server";
3+
import { BoothData } from "@/types";
4+
5+
export const GET = async (request: NextRequest) => {
6+
const data = await request.json();
7+
const { token } = data;
8+
9+
// 先確認是否存在使用者
10+
const result = await fetch(`https://sitcon.opass.app/status?token=${token}`);
11+
if (result.status === 400) return forbidden("並非本次與會者");
12+
13+
// 用token向資料庫拿取該player關聯的所有攤位解鎖狀態
14+
// prisma query here
15+
16+
// return BoothData
17+
};
18+
// 錯誤情況 1: 並非本次與會者invalid token
19+
// 錯誤情況 2: 抓取資料問題
20+
21+
export const POST = async (request: NextRequest) => {
22+
const data = await request.json();
23+
const { token, boothId } = data;
24+
25+
// 先確認是否存在使用者
26+
const result = await fetch(`https://sitcon.opass.app/status?token=${token}`);
27+
if (result.status === 400) return forbidden("並非本次與會者");
28+
29+
// 用token向prisma拿取對應 boothId 的成就資料
30+
// boothId.isFinished = true
31+
// 隨機生成prizeBlockType指定到achievement.prizeBlockType
32+
// 寫入prisma database
33+
// return success 給攤位工作者
34+
};
35+
// 錯誤情況 1: 並非本次與會者invalid token
36+
// 錯誤情況 2: 無效的攤位編號
37+
// 錯誤情況 3: 抓取資料問題

src/app/api/player/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ export const POST = async (request: NextRequest) => {
3535
if (!player) return internalServerError();
3636
return success({ message: "User regist complete" });
3737
};
38+
39+
// {
40+
// status: 200,
41+
// message: "User regist complete"
42+
// }

0 commit comments

Comments
 (0)