feat: implement PATCH /user/settings/{option} and fix timezone range to UTC-12~+14
- Add SettingOption StrEnum (nickname/language/timezone) for path param validation - Add UserSettingUpdateRequest DTO with Pydantic constraints - Implement endpoint: extract value by option name, validate non-null for required fields - Fix timezone upper bound from 12 to 14 (UTC+14 exists, e.g. Line Islands) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,8 @@ from .user import (
|
||||
UserResponse,
|
||||
UserSettingResponse,
|
||||
UserThemeUpdateRequest,
|
||||
SettingOption,
|
||||
UserSettingUpdateRequest,
|
||||
WebAuthnInfo,
|
||||
UserTwoFactorResponse,
|
||||
# 管理员DTO
|
||||
|
||||
@@ -308,6 +308,32 @@ class UserThemeUpdateRequest(SQLModelBase):
|
||||
"""颜色配置"""
|
||||
|
||||
|
||||
class SettingOption(StrEnum):
|
||||
"""用户可自助修改的设置选项"""
|
||||
|
||||
NICKNAME = "nickname"
|
||||
"""昵称"""
|
||||
|
||||
LANGUAGE = "language"
|
||||
"""语言偏好"""
|
||||
|
||||
TIMEZONE = "timezone"
|
||||
"""时区"""
|
||||
|
||||
|
||||
class UserSettingUpdateRequest(SQLModelBase):
|
||||
"""用户设置更新请求 DTO,根据 option 路径参数仅使用对应字段"""
|
||||
|
||||
nickname: str | None = Field(default=None, max_length=50)
|
||||
"""昵称(传 null 可清除)"""
|
||||
|
||||
language: str | None = Field(default=None, max_length=5)
|
||||
"""语言偏好"""
|
||||
|
||||
timezone: int | None = Field(default=None, ge=-12, le=14)
|
||||
"""时区,UTC 偏移小时数"""
|
||||
|
||||
|
||||
class UserTwoFactorResponse(SQLModelBase):
|
||||
"""用户两步验证信息 DTO"""
|
||||
|
||||
@@ -474,7 +500,7 @@ class User(UserBase, UUIDTableBaseMixin):
|
||||
language: str = Field(default="zh-CN", max_length=5)
|
||||
"""语言偏好"""
|
||||
|
||||
timezone: int = Field(default=8, ge=-12, le=12)
|
||||
timezone: int = Field(default=8, ge=-12, le=14)
|
||||
"""时区,UTC 偏移小时数"""
|
||||
|
||||
# 外键
|
||||
|
||||
Reference in New Issue
Block a user