summaryrefslogtreecommitdiffstats
path: root/api/WhatApi/Database/Tables/User.cs
blob: bfcdb50f1deb01d888a360fe776a1394b7f52567 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace WhatApi.Database.Tables;

public class User : BaseAuditableEntity
{
    public Guid Id { get; set; }
    public required string Name { get; set; }
    public required string Email { get; set; }
    public required string PasswordHash { get; set; }
    public DateTimeOffset? LastSeen { get; set; }
    public IEnumerable<Place> Places { get; set; } = null!;

    public void SetLastSeen() {
        LastSeen = DateTimeOffset.UtcNow;
    }
}

public class UserConfiguration : IEntityTypeConfiguration<User>
{
    public void Configure(EntityTypeBuilder<User> builder) {
        builder.HasKey(x => x.Id);
        builder.Property(x => x.Name).HasMaxLength(50);
        builder.Property(x => x.Email).HasMaxLength(100);
        builder.Property(x => x.PasswordHash).HasMaxLength(100);
        builder.HasMany(x => x.Places);
        builder.ToTable("user");
    }
}