From 71a444547673946a140db5bd0ed819932e392ccd Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Sun, 3 Nov 2019 00:28:21 +0800 Subject: Design the entity model primarily. --- Timeline/Entities/DatabaseContext.cs | 2 ++ Timeline/Entities/TimelineEntity.cs | 46 +++++++++++++++++++++++++++++++ Timeline/Entities/TimelineMemberEntity.cs | 27 ++++++++++++++++++ Timeline/Entities/TimelinePostEntity.cs | 34 +++++++++++++++++++++++ Timeline/Entities/User.cs | 10 ++++++- Timeline/Entities/UserAvatar.cs | 2 +- 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 Timeline/Entities/TimelineEntity.cs create mode 100644 Timeline/Entities/TimelineMemberEntity.cs create mode 100644 Timeline/Entities/TimelinePostEntity.cs (limited to 'Timeline/Entities') diff --git a/Timeline/Entities/DatabaseContext.cs b/Timeline/Entities/DatabaseContext.cs index 6c005b30..19df32c6 100644 --- a/Timeline/Entities/DatabaseContext.cs +++ b/Timeline/Entities/DatabaseContext.cs @@ -20,5 +20,7 @@ namespace Timeline.Entities public DbSet Users { get; set; } = default!; public DbSet UserAvatars { get; set; } = default!; public DbSet UserDetails { get; set; } = default!; + public DbSet Timelines { get; set; } = default!; + public DbSet TimelinePosts { get; set; } = default!; } } diff --git a/Timeline/Entities/TimelineEntity.cs b/Timeline/Entities/TimelineEntity.cs new file mode 100644 index 00000000..f4c7045d --- /dev/null +++ b/Timeline/Entities/TimelineEntity.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Timeline.Entities +{ + public enum TimelineVisibility + { + Public, + Private + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is entity object.")] + [Table("timelines")] + public class TimelineEntity + { + [Column("id"), Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public long Id { get; set; } + + /// + /// If null, then this timeline is a personal timeline. + /// + [Column("name")] + public string? Name { get; set; } + + [Column("description")] + public string? Description { get; set; } + + [Column("owner")] + public long OwnerId { get; set; } + + [ForeignKey(nameof(OwnerId))] + public User Owner { get; set; } = default!; + + [Column("visibility")] + public TimelineVisibility Visibility { get; set; } + + [Column("create_time")] + public DateTime CreateTime { get; set; } + + public List Members { get; set; } = default!; + + public List Posts { get; set; } = default!; + } +} diff --git a/Timeline/Entities/TimelineMemberEntity.cs b/Timeline/Entities/TimelineMemberEntity.cs new file mode 100644 index 00000000..4631dc89 --- /dev/null +++ b/Timeline/Entities/TimelineMemberEntity.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; + +namespace Timeline.Entities +{ + public class TimelineMemberEntity + { + [Column("id"), Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public long Id { get; set; } + + [Column("user")] + public long UserId { get; set; } + + [ForeignKey(nameof(UserId))] + public User User { get; set; } = default!; + + [Column("timeline")] + public long TimelineId { get; set; } + + [ForeignKey(nameof(TimelineId))] + public TimelineEntity Timeline { get; set; } = default!; + } +} diff --git a/Timeline/Entities/TimelinePostEntity.cs b/Timeline/Entities/TimelinePostEntity.cs new file mode 100644 index 00000000..efef3ab5 --- /dev/null +++ b/Timeline/Entities/TimelinePostEntity.cs @@ -0,0 +1,34 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Timeline.Entities +{ + [Table("timeline_posts")] + public class TimelinePostEntity + { + [Column("id"), Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public long Id { get; set; } + + [Column("timeline")] + public long TimelineId { get; set; } + + [ForeignKey(nameof(TimelineId))] + public TimelineEntity Timeline { get; set; } = default!; + + [Column("author")] + public long AuthorId { get; set; } + + [ForeignKey(nameof(AuthorId))] + public User Author { get; set; } = default!; + + [Column("content")] + public string? Content { get; set; } + + [Column("time")] + public DateTime Time { get; set; } + + [Column("last_updated")] + public DateTime LastUpdated { get; set; } + } +} diff --git a/Timeline/Entities/User.cs b/Timeline/Entities/User.cs index 02352b03..e725a69a 100644 --- a/Timeline/Entities/User.cs +++ b/Timeline/Entities/User.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace Timeline.Entities @@ -9,6 +10,7 @@ namespace Timeline.Entities public const string User = "user"; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is an entity class.")] [Table("users")] public class User { @@ -30,5 +32,11 @@ namespace Timeline.Entities public UserAvatar? Avatar { get; set; } public UserDetail? Detail { get; set; } + + public List Timelines { get; set; } = default!; + + public List TimelinePosts { get; set; } = default!; + + public List TimelinesJoined { get; set; } = default!; } } diff --git a/Timeline/Entities/UserAvatar.cs b/Timeline/Entities/UserAvatar.cs index a5b18b94..114246f3 100644 --- a/Timeline/Entities/UserAvatar.cs +++ b/Timeline/Entities/UserAvatar.cs @@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Timeline.Entities { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "This is data base entity.")] [Table("user_avatars")] public class UserAvatar { @@ -11,7 +12,6 @@ namespace Timeline.Entities public long Id { get; set; } [Column("data")] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "This is data base entity.")] public byte[]? Data { get; set; } [Column("type")] -- cgit v1.2.3