From ad44f8a9964a18ab2f262b429ff90bcdde87aa5e Mon Sep 17 00:00:00 2001 From: lzh <52725224+Yourdaylight@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:45:25 +0800 Subject: [PATCH] feat: can search now --- backend/views/games.py | 7 ------- front/api/src/functions/register.js | 12 ++++++------ front/src/app/pages/layout/list/list.component.ts | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/backend/views/games.py b/backend/views/games.py index 7c4ede0..e05f15c 100644 --- a/backend/views/games.py +++ b/backend/views/games.py @@ -69,13 +69,6 @@ def add_game(): for field in string_fields: if not isinstance(game_data.get(field), str): return jsonify({"code": 500, "msg": f"Field:[{field}] should be a string"}), 400 - - # 验证列表类型的字段 - # list_fields = ["Popular Tags", "Game Features", "Supported Languages"] - # for field in list_fields: - # if not isinstance(game_data.get(field), list): - # return jsonify({"code": 500, "msg": f"Field: [{field}] should be a list"}), 400 - # 添加时间戳 game_data["date_added"] = datetime.datetime.now().strftime("%Y-%m-%d") game_data["update_time"] = time.time() diff --git a/front/api/src/functions/register.js b/front/api/src/functions/register.js index 683d087..6fdc52c 100644 --- a/front/api/src/functions/register.js +++ b/front/api/src/functions/register.js @@ -1,7 +1,8 @@ const { app } = require('@azure/functions'); const { MongoClient } = require('mongodb'); - +// import jwt +const jwt = require('jsonwebtoken'); var connectionString = "mongodb://games:oQ5bO7YMfpu99oZMpKs0fjjypybyIMwBHJh7TmK8FYj1J41StnByDp1vxZ0huSXxlYbNLiRtNdvZACDb9cByMQ%3D%3D@games.mongo.cosmos.azure.com:10255/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@games@"; const client = new MongoClient(connectionString); @@ -12,7 +13,7 @@ app.http('register', { try { await client.connect(); const db = client.db("games"); - const { username, password } = request.body; + const { username, password } = await request.json(); const existingUser = await db.collection("user").findOne({ username }); if (!existingUser) { @@ -49,13 +50,13 @@ app.http('login', { authLevel: 'anonymous', handler: async (request, context) => { try { - const { username, password } = request.body; + const { username, password } = await request.json(); await client.connect(); const db = client.db("games"); const user = await db.collection("user").findOne({ username, password }); if (user) { - const token = jwt.sign({ username }, process.env["JWT_SECRET"], { expiresIn: '1h' }); + const token = jwt.sign({ username }, "123456" ,{ expiresIn: '1h' }); context.res = { status: 200, // HTTP 状态码 body: JSON.stringify({ code: 200, msg: "SUCCESS", data: { token } }), @@ -81,5 +82,4 @@ app.http('login', { return context.res; } } -}); - +}); \ No newline at end of file diff --git a/front/src/app/pages/layout/list/list.component.ts b/front/src/app/pages/layout/list/list.component.ts index e5f345f..66b29ac 100644 --- a/front/src/app/pages/layout/list/list.component.ts +++ b/front/src/app/pages/layout/list/list.component.ts @@ -164,7 +164,7 @@ export class ListComponent implements OnInit { ...this.searchQueryForm.value, }; - this.apiService.post('/game/getGames', params).subscribe( + this.apiService.post('/games', params).subscribe( (res: any) => { this.isLoading = false; const { code, data, total } = res;