feat: can search now

This commit is contained in:
lzh
2023-12-08 16:45:25 +08:00
parent 1e599c9bd8
commit ad44f8a996
3 changed files with 7 additions and 14 deletions
-7
View File
@@ -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()
+6 -6
View File
@@ -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;
}
}
});
});
@@ -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;