Skip to content

Commit b8484f2

Browse files
committed
Rename UserName to AccountName and add Language property to Profile
1 parent a004de8 commit b8484f2

File tree

10 files changed

+26
-16
lines changed

10 files changed

+26
-16
lines changed

OpenBioCardServer/Controllers/Classic/ClassicAdminController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public async Task<IActionResult> CreateUser([FromBody] ClassicCreateUserRequest
197197
var profile = new ProfileEntity
198198
{
199199
AccountId = newAccount.Id,
200-
UserName = request.NewUsername,
200+
AccountName = request.NewUsername,
201201
AvatarType = AssetType.Text,
202202
AvatarText = "👤"
203203
};

OpenBioCardServer/Controllers/Classic/ClassicAuthController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public async Task<IActionResult> SignUp([FromBody] ClassicSignUpRequest request)
8686
var profile = new ProfileEntity
8787
{
8888
AccountId = account.Id,
89-
UserName = request.Username,
89+
AccountName = request.Username,
9090
AvatarType = AssetType.Text,
9191
AvatarText = "👤"
9292
};

OpenBioCardServer/Data/AppDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6464
modelBuilder.Entity<ProfileEntity>(entity =>
6565
{
6666
// Unique index on Username (redundant with Account but useful)
67-
entity.HasIndex(e => e.UserName).IsUnique();
67+
entity.HasIndex(e => e.AccountName).IsUnique();
6868

6969
// One-to-Many relationships with all child entities
7070
entity.HasMany(e => e.Contacts)

OpenBioCardServer/Models/Entities/ProfileEntity.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ public class ProfileEntity
1616

1717
[Required]
1818
[MaxLength(64)]
19-
public string UserName { get; set; } = string.Empty;
19+
public string AccountName { get; set; } = string.Empty;
20+
21+
/// <summary>
22+
/// 语言代码 (ISO 639-1).
23+
/// null = 默认/主 Profile
24+
/// "en", "ja" = 特定语言变体
25+
/// </summary>
26+
[MaxLength(16)]
27+
public string? Language { get; set; }
2028

2129
// Avatar (required Asset) - 扁平化存储
2230
public AssetType AvatarType { get; set; } = AssetType.Text;

OpenBioCardServer/Models/Profile.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ namespace OpenBioCardServer.Models;
44

55
public class Profile
66
{
7-
public string UserName { get; set; } = string.Empty;
7+
public string AccountName { get; set; } = string.Empty;
8+
9+
public string? Language { get; set; }
810

911
public AccountRole Role { get; set; } = AccountRole.User;
1012
public AccountType Type { get; set; } = AccountType.Personal;

OpenBioCardServer/Services/AuthService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public async Task CreateDefaultProfileAsync(Guid accountId, string username)
126126
var profile = new ProfileEntity
127127
{
128128
AccountId = accountId,
129-
UserName = username,
129+
AccountName = username,
130130
AvatarType = AssetType.Text,
131131
AvatarText = "👤"
132132
};

OpenBioCardServer/Services/ClassicProfileService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ClassicProfileService(
4444
.Include(p => p.WorkExperiences)
4545
.Include(p => p.SchoolExperiences)
4646
.Include(p => p.Gallery)
47-
.FirstOrDefaultAsync(p => p.UserName == username, token);
47+
.FirstOrDefaultAsync(p => p.AccountName == username, token);
4848
return profile == null ? null : ClassicMapper.ToClassicProfile(profile);
4949
});
5050
}
@@ -102,7 +102,7 @@ public async Task<bool> UpdateProfileAsync(string username, ClassicProfile reque
102102
{
103103
var profile = await _context.Profiles
104104
.AsTracking()
105-
.FirstOrDefaultAsync(p => p.UserName == username);
105+
.FirstOrDefaultAsync(p => p.AccountName == username);
106106

107107
if (profile == null)
108108
{
@@ -187,7 +187,7 @@ public async Task<bool> PatchProfileAsync(string username, ClassicProfilePatch p
187187
{
188188
var profile = await _context.Profiles
189189
.AsTracking()
190-
.FirstOrDefaultAsync(p => p.UserName == username);
190+
.FirstOrDefaultAsync(p => p.AccountName == username);
191191

192192
if (profile == null)
193193
{

OpenBioCardServer/Services/ProfileService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ProfileService(
4444
.Include(p => p.WorkExperiences)
4545
.Include(p => p.SchoolExperiences)
4646
.Include(p => p.Gallery)
47-
.FirstOrDefaultAsync(p => p.UserName == username, token);
47+
.FirstOrDefaultAsync(p => p.AccountName == username, token);
4848

4949
return profile == null ? null : DataMapper.ToProfileDto(profile);
5050
});
@@ -79,7 +79,7 @@ public async Task<bool> UpdateProfileAsync(string username, ProfileDto request)
7979
try
8080
{
8181
var profile = await _context.Profiles
82-
.FirstOrDefaultAsync(p => p.UserName == username);
82+
.FirstOrDefaultAsync(p => p.AccountName == username);
8383

8484
if (profile == null)
8585
{

OpenBioCardServer/Utilities/Mappers/ClassicMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static ClassicProfile ToClassicProfile(ProfileEntity profile)
1313
{
1414
return new ClassicProfile
1515
{
16-
Username = profile.UserName,
16+
Username = profile.AccountName,
1717
Name = profile.Nickname ?? string.Empty,
1818
Pronouns = profile.Pronouns ?? string.Empty,
1919
Avatar = AssetToString(profile.AvatarType, profile.AvatarText, profile.AvatarData),
@@ -177,7 +177,7 @@ private static ClassicSocialLink ToClassicSocialLink(SocialLinkItemEntity s)
177177

178178
public static void UpdateProfileFromClassic(ProfileEntity profile, ClassicProfile classic)
179179
{
180-
profile.UserName = classic.Username;
180+
profile.AccountName = classic.Username;
181181
profile.Nickname = classic.Name;
182182
profile.Pronouns = classic.Pronouns;
183183

@@ -366,7 +366,7 @@ public static void UpdateProfileFromPatch(ProfileEntity profile, ClassicProfileP
366366
// 仅当字段不为 Null 时更新
367367
// 注意:如果前端传空字符串 "",这里会更新为空字符串,符合预期(清空字段)
368368

369-
if (patch.Username != null) profile.UserName = patch.Username;
369+
if (patch.Username != null) profile.AccountName = patch.Username;
370370
if (patch.Name != null) profile.Nickname = patch.Name;
371371
if (patch.Pronouns != null) profile.Pronouns = patch.Pronouns;
372372

OpenBioCardServer/Utilities/Mappers/DataMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static ProfileDto ToProfileDto(ProfileEntity profile)
1313
{
1414
var dto = new ProfileDto
1515
{
16-
Username = profile.UserName,
16+
Username = profile.AccountName,
1717
Avatar = ToAssetDto(profile.AvatarType, profile.AvatarText, profile.AvatarData),
1818
NickName = profile.Nickname,
1919
Pronouns = profile.Pronouns,
@@ -127,7 +127,7 @@ public static SocialLinkItemDto ToSocialLinkItemDto(SocialLinkItemEntity entity)
127127

128128
public static void UpdateProfileEntity(ProfileEntity entity, ProfileDto dto)
129129
{
130-
entity.UserName = dto.Username;
130+
entity.AccountName = dto.Username;
131131
entity.Nickname = dto.NickName;
132132
entity.Pronouns = dto.Pronouns;
133133
entity.Biography = dto.Description;

0 commit comments

Comments
 (0)