AnlaAnla 18 часов назад
Родитель
Сommit
0d51bda1b5
2 измененных файлов с 4 добавлено и 5 удалено
  1. 3 4
      app/api/users.py
  2. 1 1
      app/core/database_loader.py

+ 3 - 4
app/api/users.py

@@ -16,7 +16,7 @@ db_dependency = Depends(get_db_connection)
 
 
 class BindCardRequest(BaseModel):
-    user_id: int = Field(..., ge=0)
+    user_id: str = Field(..., min_length=1)
     bind_card_id: List[int] = Field(default_factory=list)
     unbind_card_id: List[int] = Field(default_factory=list)
 
@@ -53,9 +53,8 @@ def get_current_user(x_user_base64: Optional[str] = Header(None, alias="X-USER-B
     if not isinstance(role_code_list, list):
         raise _auth_exception("X-USER-BASE64 的 roleCodeList 格式错误")
 
-    try:
-        user_id = int(user_id)
-    except (TypeError, ValueError):
+    user_id = str(user_id).strip()
+    if not user_id:
         raise _auth_exception("X-USER-BASE64 的用户 id 格式错误")
 
     return {

+ 1 - 1
app/core/database_loader.py

@@ -45,7 +45,7 @@ def init_database():
         user_card_table = (
             f"CREATE TABLE IF NOT EXISTS `{settings.DB_USER_CARD_TABLE_NAME}` ("
             "  `id` INT AUTO_INCREMENT PRIMARY KEY,"
-            "  `user_id` BIGINT NOT NULL,"
+            "  `user_id` VARCHAR(128) NOT NULL,"
             "  `card_id` INT NOT NULL,"
             "  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,"
             f"  FOREIGN KEY (`card_id`) REFERENCES `{settings.DB_CARD_TABLE_NAME}`(`id`) ON DELETE CASCADE,"